def _write(self): """ create required structure and the serialise """ anchors = [] for idx, obj in enumerate(self.charts + self.images, 1): if isinstance(obj, ChartBase): rel = Relationship(type="chart", target='../charts/chart%s.xml' % obj._id) row, col = coordinate_to_tuple(obj.anchor) anchor = OneCellAnchor() anchor._from.row = row -1 anchor._from.col = col -1 anchor.ext.width = cm_to_EMU(obj.width) anchor.ext.height = cm_to_EMU(obj.height) anchor.graphicFrame = self._chart_frame(idx) elif isinstance(obj, Image): rel = Relationship(type="image", target='../media/image%s.png' % obj._id) anchor = obj.drawing.anchor anchor.pic = self._picture_frame(idx) anchors.append(anchor) self._rels.append(rel) self.oneCellAnchor = anchors tree = self.to_tree() tree.set('xmlns', SHEET_DRAWING_NS) return tree
def _write(self): """ create required structure and the serialise """ anchors = [] for idx, obj in enumerate(self.charts + self.images, 1): if isinstance(obj, ChartBase): rel = Relationship(type="chart", target="../charts/chart%s.xml" % obj._id) row, col = coordinate_to_tuple(obj.anchor) anchor = OneCellAnchor() anchor._from.row = row - 1 anchor._from.col = col - 1 anchor.ext.width = cm_to_EMU(obj.width) anchor.ext.height = cm_to_EMU(obj.height) anchor.graphicFrame = self._chart_frame(idx) elif isinstance(obj, Image): rel = Relationship(type="image", target="../media/image%s.png" % obj._id) anchor = obj.drawing.anchor anchor.pic = self._picture_frame(idx) anchors.append(anchor) self._rels.append(rel) self.oneCellAnchor = anchors tree = self.to_tree() tree.set("xmlns", SHEET_DRAWING_NS) return tree
def add_image(wb, ws, pos, key, img): if img is None: return w, h, margin, scale = eval(key[2]) img = trans(img, w, h, margin, scale == 0) img = PImage.fromarray(img) image_file = BytesIO() img.save(image_file, 'png') ref = BytesIO(image_file.getvalue()) image = Image(img) image.ref = ref image.height = EMU_to_pixels(cm_to_EMU(h)) image.width = EMU_to_pixels(cm_to_EMU(w)) wb[ws].add_image(image, wb[ws].cell(*pos).coordinate)
def _check_anchor(obj): """ Check whether an object has an existing Anchor object If not create a OneCellAnchor using the provided coordinate """ anchor = obj.anchor if not isinstance(anchor, _AnchorBase): row, col = coordinate_to_tuple(anchor) anchor = OneCellAnchor() anchor._from.row = row - 1 anchor._from.col = col - 1 if isinstance(obj, ChartBase): anchor.ext.width = cm_to_EMU(obj.width) anchor.ext.height = cm_to_EMU(obj.height) elif isinstance(obj, Image): anchor.ext.width = pixels_to_EMU(obj.width) anchor.ext.height = pixels_to_EMU(obj.height) return anchor
def _check_anchor(obj): """ Check whether an object has an existing Anchor object If not create a OneCellAnchor using the provided coordinate """ anchor = obj.anchor if not isinstance(anchor, _AnchorBase): row, col = coordinate_to_tuple(anchor) anchor = OneCellAnchor() anchor._from.row = row -1 anchor._from.col = col -1 if isinstance(obj, ChartBase): anchor.ext.width = cm_to_EMU(obj.width) anchor.ext.height = cm_to_EMU(obj.height) elif isinstance(obj, Image): anchor.ext.width = pixels_to_EMU(obj.width) anchor.ext.height = pixels_to_EMU(obj.height) return anchor
def new_sheet(self, name, tab_color=None): """Добавление листа""" if self.first: self.generate_styles() self.ws.title = name[:31] self.first = False else: self.ws = self.wb.create_sheet(name[:31]) self.ws.page_setup.orientation = self.sheet_orient self.ws.page_setup.paperSize = self.paper_size self.ws.page_margins.left = EMU_to_inch(cm_to_EMU(self.left_margin)) self.ws.page_margins.right = EMU_to_inch(cm_to_EMU(self.right_margin)) self.ws.page_margins.top = EMU_to_inch(cm_to_EMU(self.top_margin)) self.ws.page_margins.bottom = EMU_to_inch(cm_to_EMU( self.bottom_margin)) self.ws.print_options.horizontalCentered = self.center_horizontally self.ws.sheet_properties.tabColor = tab_color
def _write(self): """ create required structure and the serialise """ anchors = [] for idx, obj in enumerate(self.charts + self.images, 1): if isinstance(obj, ChartBase): rel = Relationship(type="chart", Target=obj.path) anchor = obj.anchor if not isinstance(anchor, _AnchorBase): row, col = coordinate_to_tuple(anchor) anchor = OneCellAnchor() anchor._from.row = row - 1 anchor._from.col = col - 1 anchor.ext.width = cm_to_EMU(obj.width) anchor.ext.height = cm_to_EMU(obj.height) anchor.graphicFrame = self._chart_frame(idx) elif isinstance(obj, Image): rel = Relationship(type="image", Target=obj.path) anchor = obj.drawing.anchor anchor.pic = self._picture_frame(idx) anchors.append(anchor) self._rels.append(rel) for a in anchors: if isinstance(a, OneCellAnchor): self.oneCellAnchor.append(a) elif isinstance(a, TwoCellAnchor): self.twoCellAnchor.append(a) else: self.absoluteAnchor.append(a) tree = self.to_tree() tree.set('xmlns', SHEET_DRAWING_NS) return tree
def _write(self): """ create required structure and the serialise """ anchors = [] for idx, obj in enumerate(self.charts + self.images, 1): if isinstance(obj, ChartBase): rel = Relationship(type="chart", Target=obj.path) anchor = obj.anchor if not isinstance(anchor, _AnchorBase): row, col = coordinate_to_tuple(anchor) anchor = OneCellAnchor() anchor._from.row = row -1 anchor._from.col = col -1 anchor.ext.width = cm_to_EMU(obj.width) anchor.ext.height = cm_to_EMU(obj.height) anchor.graphicFrame = self._chart_frame(idx) elif isinstance(obj, Image): rel = Relationship(type="image", Target=obj.path) anchor = obj.drawing.anchor anchor.pic = self._picture_frame(idx) anchors.append(anchor) self._rels.append(rel) for a in anchors: if isinstance(a, OneCellAnchor): self.oneCellAnchor.append(a) elif isinstance(a, TwoCellAnchor): self.twoCellAnchor.append(a) else: self.absoluteAnchor.append(a) tree = self.to_tree() tree.set('xmlns', SHEET_DRAWING_NS) return tree