def createBorders(): # 枠線の作成。 noneline = BorderLine2(LineStyle=BorderLineStyle.NONE) firstline = BorderLine2(LineStyle=BorderLineStyle.DASHED, LineWidth=62, Color=COLORS["violet"]) secondline = BorderLine2(LineStyle=BorderLineStyle.DASHED, LineWidth=62, Color=COLORS["magenta3"]) tableborder2 = TableBorder2(TopLine=firstline, LeftLine=firstline, RightLine=secondline, BottomLine=secondline, IsTopLineValid=True, IsBottomLineValid=True, IsLeftLineValid=True, IsRightLineValid=True) topbottomtableborder = TableBorder2(TopLine=firstline, LeftLine=firstline, RightLine=secondline, BottomLine=secondline, IsTopLineValid=True, IsBottomLineValid=True, IsLeftLineValid=False, IsRightLineValid=False) leftrighttableborder = TableBorder2(TopLine=firstline, LeftLine=firstline, RightLine=secondline, BottomLine=secondline, IsTopLineValid=False, IsBottomLineValid=False, IsLeftLineValid=True, IsRightLineValid=True) return noneline, tableborder2, topbottomtableborder, leftrighttableborder # 作成した枠線をまとめたタプル。
def configureBorders(doc, text, items): no_line = BorderLine2() no_line.Color = 0 no_line.InnerLineWidth = 0 no_line.LineDistance = 0 no_line.LineStyle = 0 no_line.LineWidth = 0 no_line.OuterLineWidth = 0 text_tables = doc.getTextTables() get_top_table = text_tables.getByIndex(0) table_top_border = get_top_table.TableBorder table_top_border.LeftLine = no_line table_top_border.RightLine = no_line table_top_border.TopLine = no_line table_top_border.BottomLine = no_line table_top_border.HorizontalLine = no_line table_top_border.VerticalLine = no_line get_top_table.TableBorder = table_top_border get_middle_table = text_tables.getByIndex(1) table_middle_border = get_middle_table.TableBorder table_middle_border.LeftLine = no_line table_middle_border.RightLine = no_line table_middle_border.TopLine = no_line table_middle_border.BottomLine = no_line table_middle_border.HorizontalLine = no_line table_middle_border.VerticalLine = no_line get_middle_table.TableBorder = table_middle_border get_main_table = text_tables.getByIndex(2) count = 0 col = ['A', 'B', 'C', 'D'] for i in items: count = count + 1 for i in col: table_main_cell = get_main_table.getCellByName(i + str(count + 2)) left_border_a_cell = table_main_cell.LeftBorder left_border_a_cell.OuterLineWidth = 0 left_border_a_cell.LineWidth = 0 table_main_cell.LeftBorder = left_border_a_cell cRange = get_main_table.getCellRangeByName("A" + str(count + 2) + ":D" + str(count + 2)) cRange.setPropertyValue("CharFontName", "Liberation Serif") cRange.setPropertyValue("CharHeight", 10.0) table_main_cell = get_main_table.getCellByName("D" + str(count + 2)) right_border_a_cell = table_main_cell.RightBorder right_border_a_cell.OuterLineWidth = 0 right_border_a_cell.LineWidth = 0 table_main_cell.RightBorder = right_border_a_cell table_main_border = get_main_table.TableBorder table_main_border.BottomLine = no_line get_main_table.TableBorder = table_main_border get_bottom_table = text_tables.getByIndex(3) table_bottom_border = get_bottom_table.TableBorder table_bottom_border.Distance = 1 table_bottom_border.HorizontalLine = no_line table_bottom_border.VerticalLine = no_line get_bottom_table.TableBorder = table_bottom_border return doc, text
def test_tableborder(self): xDoc = CheckTable._uno.openEmptyWriterDoc() # insert table xTable = xDoc.createInstance("com.sun.star.text.TextTable") xTable.initialize(3, 3) xText = xDoc.getText() xCursor = xText.createTextCursor() xText.insertTextContent(xCursor, xTable, False) border = xTable.getPropertyValue("TableBorder") self.__test_borderAsserts(border.TopLine, border.IsTopLineValid) self.__test_borderAsserts(border.BottomLine, border.IsBottomLineValid) self.__test_borderAsserts(border.LeftLine, border.IsLeftLineValid) self.__test_borderAsserts(border.RightLine, border.IsRightLineValid) self.__test_borderAsserts(border.HorizontalLine, border.IsHorizontalLineValid) self.__test_borderAsserts(border.VerticalLine, border.IsVerticalLineValid) self.__test_borderDistance(border) # set border border.TopLine = BorderLine(0, 11, 19, 19) border.BottomLine = BorderLine(0xFF, 00, 11, 00) border.HorizontalLine = BorderLine(0xFF00, 00, 90, 00) xTable.setPropertyValue("TableBorder", border) # read set border border = xTable.getPropertyValue("TableBorder") self.assertTrue(border.IsTopLineValid) self.assertEqual(11, border.TopLine.InnerLineWidth) self.assertEqual(19, border.TopLine.OuterLineWidth) self.assertEqual(19, border.TopLine.LineDistance) self.assertEqual(0, border.TopLine.Color) self.assertTrue(border.IsBottomLineValid) self.assertEqual(0, border.BottomLine.InnerLineWidth) self.assertEqual(11, border.BottomLine.OuterLineWidth) self.assertEqual(0, border.BottomLine.LineDistance) self.assertEqual(0xFF, border.BottomLine.Color) self.__test_borderAsserts(border.LeftLine, border.IsLeftLineValid) self.__test_borderAsserts(border.RightLine, border.IsRightLineValid) self.assertTrue(border.IsHorizontalLineValid) self.assertEqual(0, border.HorizontalLine.InnerLineWidth) self.assertEqual(90, border.HorizontalLine.OuterLineWidth) self.assertEqual(0, border.HorizontalLine.LineDistance) self.assertEqual(0xFF00, border.HorizontalLine.Color) self.__test_borderAsserts(border.VerticalLine, border.IsVerticalLineValid) self.__test_borderDistance(border) border2 = xTable.getPropertyValue("TableBorder2") self.assertTrue(border2.IsTopLineValid) self.assertEqual(11, border2.TopLine.InnerLineWidth) self.assertEqual(19, border2.TopLine.OuterLineWidth) self.assertEqual(19, border2.TopLine.LineDistance) self.assertEqual(0, border2.TopLine.Color) self.assertEqual(DOUBLE, border2.TopLine.LineStyle) self.assertEqual(49, border2.TopLine.LineWidth) self.assertTrue(border2.IsBottomLineValid) self.assertEqual(0, border2.BottomLine.InnerLineWidth) self.assertEqual(11, border2.BottomLine.OuterLineWidth) self.assertEqual(0, border2.BottomLine.LineDistance) self.assertEqual(0xFF, border2.BottomLine.Color) self.assertEqual(SOLID, border2.BottomLine.LineStyle) self.assertEqual(11, border2.BottomLine.LineWidth) self.__test_borderAssertsWithLineStyle(border2.LeftLine, border2.IsLeftLineValid) self.__test_borderAssertsWithLineStyle(border2.RightLine, border2.IsRightLineValid) self.assertTrue(border2.IsHorizontalLineValid) self.assertEqual(0, border2.HorizontalLine.InnerLineWidth) self.assertEqual(90, border2.HorizontalLine.OuterLineWidth) self.assertEqual(0, border2.HorizontalLine.LineDistance) self.assertEqual(0xFF00, border2.HorizontalLine.Color) self.assertEqual(SOLID, border2.HorizontalLine.LineStyle) self.assertEqual(90, border2.HorizontalLine.LineWidth) self.__test_borderAssertsWithLineStyle(border2.VerticalLine, border2.IsVerticalLineValid) self.__test_borderDistance(border2) # set border2 border2.RightLine = BorderLine2(0, 0, 0, 0, THICKTHIN_LARGEGAP, 120) border2.LeftLine = BorderLine2(0, 0, 0, 0, EMBOSSED, 90) border2.VerticalLine = BorderLine2(0xFF, 0, 90, 0, DOTTED, 0) border2.HorizontalLine = BorderLine2(0xFF00, 0, 0, 0, DASHED, 11) xTable.setPropertyValue("TableBorder2", border2) # read set border2 border2 = xTable.getPropertyValue("TableBorder2") self.assertTrue(border2.IsTopLineValid) self.assertEqual(11, border2.TopLine.InnerLineWidth) self.assertEqual(19, border2.TopLine.OuterLineWidth) self.assertEqual(19, border2.TopLine.LineDistance) self.assertEqual(0, border2.TopLine.Color) self.assertEqual(DOUBLE, border2.TopLine.LineStyle) self.assertEqual(49, border2.TopLine.LineWidth) self.assertTrue(border2.IsBottomLineValid) self.assertEqual(0, border2.BottomLine.InnerLineWidth) self.assertEqual(11, border2.BottomLine.OuterLineWidth) self.assertEqual(0, border2.BottomLine.LineDistance) self.assertEqual(0xFF, border2.BottomLine.Color) self.assertEqual(SOLID, border2.BottomLine.LineStyle) self.assertEqual(11, border2.BottomLine.LineWidth) self.assertTrue(border2.IsLeftLineValid) self.assertEqual(23, border2.LeftLine.InnerLineWidth) self.assertEqual(23, border2.LeftLine.OuterLineWidth) self.assertEqual(46, border2.LeftLine.LineDistance) self.assertEqual(0, border2.LeftLine.Color) self.assertEqual(EMBOSSED, border2.LeftLine.LineStyle) self.assertEqual(90, border2.LeftLine.LineWidth) self.assertTrue(border2.IsRightLineValid) self.assertEqual(53, border2.RightLine.InnerLineWidth) self.assertEqual(26, border2.RightLine.OuterLineWidth) self.assertEqual(41, border2.RightLine.LineDistance) self.assertEqual(0, border2.RightLine.Color) self.assertEqual(THICKTHIN_LARGEGAP, border2.RightLine.LineStyle) self.assertEqual(120, border2.RightLine.LineWidth) self.assertTrue(border2.IsHorizontalLineValid) self.assertEqual(0, border2.HorizontalLine.InnerLineWidth) self.assertEqual(11, border2.HorizontalLine.OuterLineWidth) self.assertEqual(0, border2.HorizontalLine.LineDistance) self.assertEqual(0xFF00, border2.HorizontalLine.Color) self.assertEqual(DASHED, border2.HorizontalLine.LineStyle) self.assertEqual(11, border2.HorizontalLine.LineWidth) self.assertTrue(border2.IsVerticalLineValid) self.assertEqual(0, border2.VerticalLine.InnerLineWidth) self.assertEqual(90, border2.VerticalLine.OuterLineWidth) self.assertEqual(0, border2.VerticalLine.LineDistance) self.assertEqual(0xFF, border2.VerticalLine.Color) self.assertEqual(DOTTED, border2.VerticalLine.LineStyle) self.assertEqual(90, border2.VerticalLine.LineWidth) self.__test_borderDistance(border2) # close document xDoc.dispose()
def configureBorders(doc, text, items): no_line = BorderLine2() no_line.Color = 0 no_line.InnerLineWidth = 0 no_line.LineDistance = 0 no_line.LineStyle = 0 no_line.LineWidth = 0 no_line.OuterLineWidth = 0 text_tables = doc.getTextTables() try: hospital_table = text_tables.getByName('hospital_table') hospital_table_border = hospital_table.TableBorder hospital_table_border.LeftLine = no_line hospital_table_border.VerticalLine = no_line hospital_table_border.HorizontalLine = no_line hospital_table_border.BottomLine = no_line hospital_table_border.TopLine = no_line hospital_table_border.RightLine = no_line hospital_table.TableBorder = hospital_table_border except Exception: pass get_top_table = text_tables.getByName('identity_table') table_top_border = get_top_table.TableBorder table_top_border.LeftLine = no_line table_top_border.RightLine = no_line table_top_border.TopLine = no_line table_top_border.BottomLine = no_line table_top_border.HorizontalLine = no_line table_top_border.VerticalLine = no_line get_top_table.TableBorder = table_top_border get_middle_table = text_tables.getByName('patient_table') table_middle_border = get_middle_table.TableBorder table_middle_border.LeftLine = no_line table_middle_border.RightLine = no_line table_middle_border.TopLine = no_line table_middle_border.BottomLine = no_line table_middle_border.HorizontalLine = no_line table_middle_border.VerticalLine = no_line get_middle_table.TableBorder = table_middle_border try: get_diagnosis_table = text_tables.getByName('diagnosis_table') otabseps = get_diagnosis_table.TableColumnSeparators relativeTableWidth = get_diagnosis_table.getPropertyValue( "TableColumnRelativeSum") otabseps[0].Position = 1675 otabseps[1].Position = 6670 otabseps[2].Position = 8330 get_diagnosis_table.TableColumnSeparators = otabseps get_diagnosis_table.setPropertyValue("TableColumnSeparators", otabseps) table_diagnosis_border = get_diagnosis_table.TableBorder table_diagnosis_border.LeftLine = no_line table_diagnosis_border.RightLine = no_line table_diagnosis_border.TopLine = no_line table_diagnosis_border.BottomLine = no_line table_diagnosis_border.VerticalLine = no_line table_diagnosis_border.HorizontalLine = no_line get_diagnosis_table.TableBorder = table_diagnosis_border except Exception: pass get_main_table = text_tables.getByName('treatment_table') count = 0 col = ['A', 'B', 'C', 'D', 'E'] for i in items: count = count + 1 for i in range(len(col)): table_main_cell = get_main_table.getCellByPosition(i, (count + 1)) left_border_a_cell = table_main_cell.LeftBorder left_border_a_cell.OuterLineWidth = 0 left_border_a_cell.LineWidth = 0 table_main_cell.LeftBorder = left_border_a_cell cRange = get_main_table.getCellRangeByName("A" + str(count + 2) + ":E" + str(count + 2)) cRange.setPropertyValue("CharFontName", "Liberation Serif") #cRange.setPropertyValue( "CharHeight", 10.0 ) table_main_cell = get_main_table.getCellByName("E" + str(count + 2)) right_border_a_cell = table_main_cell.RightBorder right_border_a_cell.OuterLineWidth = 0 right_border_a_cell.LineWidth = 0 table_main_cell.RightBorder = right_border_a_cell table_main_border = get_main_table.TableBorder table_main_border.BottomLine = no_line get_main_table.TableBorder = table_main_border get_bottom_table = text_tables.getByName('footer_table') table_bottom_border = get_bottom_table.TableBorder table_bottom_border.Distance = 50 table_bottom_border.HorizontalLine = no_line table_bottom_border.VerticalLine = no_line get_bottom_table.TableBorder = table_bottom_border return doc, text