def add_table(self, rows, cols, left, top, width, height): """ Add table shape with the specified number of *rows* and *cols* at the specified position with the specified size. *width* is evenly distributed between the *cols* columns of the new table. Likewise, *height* is evenly distributed between the *rows* rows created. """ id = self.__next_shape_id name = "Table %d" % (id - 1) graphicFrame = CT_GraphicalObjectFrame.new_table(id, name, rows, cols, left, top, width, height) self.__spTree.append(graphicFrame) table = _Table(graphicFrame) self.__shapes.append(table) return table
def test_has_table_return_value(self): """CT_GraphicalObjectFrame.has_table property has correct value""" # setup ------------------------ id_, name = 9, "Table 8" left, top, width, height = 111, 222, 333, 444 tbl_uri = "http://schemas.openxmlformats.org/drawingml/2006/table" chart_uri = "http://schemas.openxmlformats.org/drawingml/2006/chart" graphicFrame = CT_GraphicalObjectFrame.new_graphicFrame(id_, name, left, top, width, height) graphicData = graphicFrame[qn("a:graphic")].graphicData # verify ----------------------- graphicData.set("uri", tbl_uri) assert_that(graphicFrame.has_table, is_(equal_to(True))) graphicData.set("uri", chart_uri) assert_that(graphicFrame.has_table, is_(equal_to(False)))
def add_table(self, rows, cols, left, top, width, height): """ Add table shape with the specified number of *rows* and *cols* at the specified position with the specified size. *width* is evenly distributed between the *cols* columns of the new table. Likewise, *height* is evenly distributed between the *rows* rows created. """ id = self.__next_shape_id name = 'Table %d' % (id - 1) graphicFrame = CT_GraphicalObjectFrame.new_table( id, name, rows, cols, left, top, width, height) self.__spTree.append(graphicFrame) table = _Table(graphicFrame) self.__shapes.append(table) return table
def test_new_table_generates_correct_xml(self): """CT_GraphicalObjectFrame.new_table() returns correct XML""" # setup ----------------------- id_, name = 9, 'Table 8' rows, cols = 2, 3 left, top, width, height = 111, 222, 334, 445 xml = ( '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n' '<p:graphicFrame xmlns:a="http://schemas.openxmlformats.org/drawi' 'ngml/2006/main" xmlns:p="http://schemas.openxmlformats.org/prese' 'ntationml/2006/main">\n <p:nvGraphicFramePr>\n <p:cNvP''r id' '="%d" name="%s"/>\n <p:cNvGraphicFramePr>\n <a:graphicFr' 'ameLocks noGrp="1"/>\n </p:cNvGraphicFramePr>\n <p:nvPr/>' '\n </p:nvGraphicFramePr>\n <p:xfrm>\n <a:off x="%d" y="%d"/' '>\n <a:ext cx="%d" cy="%d"/>\n </p:xfrm>\n <a:graphic>\n ' ' <a:graphicData uri="http://schemas.openxmlformats.org/drawingml' '/2006/table">\n <a:tbl>\n <a:tblPr firstRow="1" band' 'Row="1">\n <a:tableStyleId>{5C22544A-7EE6-4342-B048-85B' 'DC9FD1C3A}</a:tableStyleId>\n </a:tblPr>\n <a:tblG' 'rid>\n <a:gridCol w="111"/>\n <a:gridCol w="11' '1"/>\n <a:gridCol w="112"/>\n </a:tblGrid>\n ' ' <a:tr h="222">\n <a:tc>\n <a:txBody>\n ' ' <a:bodyPr/>\n <a:lstStyle/>\n ' ' <a:p/>\n </a:txBody>\n <a:tcPr/>\n ' ' </a:tc>\n <a:tc>\n <a:txBody>\n ' ' <a:bodyPr/>\n <a:lstStyle/>\n <' 'a:p/>\n </a:txBody>\n <a:tcPr/>\n ' ' </a:tc>\n <a:tc>\n <a:txBody>\n ' ' <a:bodyPr/>\n <a:lstStyle/>\n <a:p/>' '\n </a:txBody>\n <a:tcPr/>\n </a:' 'tc>\n </a:tr>\n <a:tr h="223">\n <a:tc>\n' ' <a:txBody>\n <a:bodyPr/>\n ' ' <a:lstStyle/>\n <a:p/>\n </a:txBody>\n ' ' <a:tcPr/>\n </a:tc>\n <a:tc>\n ' ' <a:txBody>\n <a:bodyPr/>\n <a:l' 'stStyle/>\n <a:p/>\n </a:txBody>\n ' ' <a:tcPr/>\n </a:tc>\n <a:tc>\n ' ' <a:txBody>\n <a:bodyPr/>\n <a:lstSty' 'le/>\n <a:p/>\n </a:txBody>\n ' ' <a:tcPr/>\n </a:tc>\n </a:tr>\n </a:tbl>\n' ' </a:graphicData>\n </a:graphic>\n</p:graphicFrame>\n' % (id_, name, left, top, width, height) ) # exercise -------------------- graphicFrame = CT_GraphicalObjectFrame.new_table( id_, name, rows, cols, left, top, width, height) # verify ---------------------- _assert_equal_line_by_line(self, xml, graphicFrame)
def test_new_table_generates_correct_xml(self): """CT_GraphicalObjectFrame.new_table() returns correct XML""" # setup ------------------------ id_, name = 9, "Table 8" rows, cols = 2, 3 left, top, width, height = 111, 222, 334, 445 xml = ( "<p:graphicFrame %s>\n <p:nvGraphicFramePr>\n <p:cNvP" 'r id="' '%d" name="%s"/>\n <p:cNvGraphicFramePr>\n <a:graphicFram' 'eLocks noGrp="1"/>\n </p:cNvGraphicFramePr>\n <p:nvPr/>\n ' ' </p:nvGraphicFramePr>\n <p:xfrm>\n <a:off x="%d" y="%d"/>\n' ' <a:ext cx="%d" cy="%d"/>\n </p:xfrm>\n <a:graphic>\n <a' ':graphicData uri="http://schemas.openxmlformats.org/drawingml/20' '06/table">\n <a:tbl>\n <a:tblPr firstRow="1" bandRow' '="1">\n <a:tableStyleId>{5C22544A-7EE6-4342-B048-85BDC9' "FD1C3A}</a:tableStyleId>\n </a:tblPr>\n <a:tblGrid" '>\n <a:gridCol w="111"/>\n <a:gridCol w="111"/' '>\n <a:gridCol w="112"/>\n </a:tblGrid>\n ' ' <a:tr h="222">\n <a:tc>\n <a:txBody>\n ' " <a:bodyPr/>\n <a:lstStyle/>\n " " <a:p/>\n </a:txBody>\n <a:tcPr/>\n " " </a:tc>\n <a:tc>\n <a:txBody>\n " " <a:bodyPr/>\n <a:lstStyle/>\n <a:p" "/>\n </a:txBody>\n <a:tcPr/>\n </" "a:tc>\n <a:tc>\n <a:txBody>\n <" "a:bodyPr/>\n <a:lstStyle/>\n <a:p/>\n " " </a:txBody>\n <a:tcPr/>\n </a:tc>" '\n </a:tr>\n <a:tr h="223">\n <a:tc>\n ' " <a:txBody>\n <a:bodyPr/>\n <a" ":lstStyle/>\n <a:p/>\n </a:txBody>\n " " <a:tcPr/>\n </a:tc>\n <a:tc>\n " " <a:txBody>\n <a:bodyPr/>\n <a:lstS" "tyle/>\n <a:p/>\n </a:txBody>\n " " <a:tcPr/>\n </a:tc>\n <a:tc>\n <" "a:txBody>\n <a:bodyPr/>\n <a:lstStyle/" ">\n <a:p/>\n </a:txBody>\n <a" ":tcPr/>\n </a:tc>\n </a:tr>\n </a:tbl>\n " " </a:graphicData>\n </a:graphic>\n</p:graphicFrame>\n" % (nsdecls("a", "p"), id_, name, left, top, width, height) ) # exercise --------------------- graphicFrame = CT_GraphicalObjectFrame.new_table(id_, name, rows, cols, left, top, width, height) # verify ----------------------- self.assertEqualLineByLine(xml, graphicFrame)
def test_new_graphicFrame_generates_correct_xml(self): """CT_GraphicalObjectFrame.new_graphicFrame() returns correct XML""" # setup ------------------------ id_, name = 9, "Table 8" left, top, width, height = 111, 222, 333, 444 xml = ( '<p:graphicFrame %s>\n <p:nvGraphicFramePr>\n <p:cNvPr id="%d' '" name="%s"/>\n <p:cNvGraphicFramePr>\n <a:graphicFrameL' 'ocks noGrp="1"/>\n </p:cNvGraphicFramePr>\n <p:nvPr/>\n <' '/p:nvGraphicFramePr>\n <p:xfrm>\n <a:off x="%d" y="%d"/>\n ' ' <a:ext cx="%d" cy="%d"/>\n </p:xfrm>\n <a:graphic>\n <a:g' "raphicData/>\n </a:graphic>\n</p:graphicFrame>\n" % (nsdecls("a", "p"), id_, name, left, top, width, height) ) # exercise --------------------- graphicFrame = CT_GraphicalObjectFrame.new_graphicFrame(id_, name, left, top, width, height) # verify ----------------------- self.assertEqualLineByLine(xml, graphicFrame)
def test_new_graphicFrame_generates_correct_xml(self): """CT_GraphicalObjectFrame.new_graphicFrame() returns correct XML""" # setup ----------------------- id_, name = 9, 'Table 8' left, top, width, height = 111, 222, 333, 444 xml = ( '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n' '<p:graphicFrame xmlns:a="http://schemas.openxmlformats.org/drawi' 'ngml/2006/main" xmlns:p="http://schemas.openxmlformats.org/prese' 'ntationml/2006/main">\n <p:nvGraphicFramePr>\n <p:cNvPr id="' '%d" name="%s"/>\n <p:cNvGraphicFramePr>\n <a:graphicFram' 'eLocks noGrp="1"/>\n </p:cNvGraphicFramePr>\n <p:nvPr/>\n ' ' </p:nvGraphicFramePr>\n <p:xfrm>\n <a:off x="%d" y="%d"/>\n' ' <a:ext cx="%d" cy="%d"/>\n </p:xfrm>\n <a:graphic>\n <a' ':graphicData/>\n </a:graphic>\n</p:graphicFrame>\n' % (id_, name, left, top, width, height) ) # exercise -------------------- graphicFrame = CT_GraphicalObjectFrame.new_graphicFrame( id_, name, left, top, width, height) # verify ---------------------- _assert_equal_line_by_line(self, xml, graphicFrame)
def add_chart(self, left, top, width, height,data,headings_xlsx): """ adding xlsx writer for excel file that is stored in /temp/ folder """ #name = 'temp/Worksheet.xlsx' workbook = xlsxwriter.Workbook('temp/Worksheet.xlsx') worksheet = workbook.add_worksheet() bold = workbook.add_format({'bold': 1}) # Add the worksheet data that the charts will refer to. for i,e in enumerate(headings_xlsx): if i ==0: worksheet.write_row('A1', headings_xlsx, bold) worksheet.write_column(string.uppercase[i]+'2',data[i]) else: worksheet.write_column(string.uppercase[i]+'2',data[i]) """ """ id = self.__next_shape_id chart, rel = self.__slide._add_chart(data,headings_xlsx,'temp/Worksheet.xlsx') rId = rel._rId name = 'Chart %d' % (id-1) graphicFrame = CT_GraphicalObjectFrame.new_chart( id,rId, name, left, top, width, height) self.__spTree.append(graphicFrame) return graphicFrame