简体   繁体   English

xlsx文件中的图形由openpyxl覆盖

[英]Graphs in xlsx File overwrite by openpyxl

We need to update xlsx sheet using python script which do some calcualtion and update one worksheet. 我们需要使用python脚本更新xlsx表,它会进行一些计算并更新一个工作表。 I choose openpyxl as it supoort writing/updating xlsx File. 我选择openpyxl,因为它支持编写/更新xlsx文件。 In the Excel sheet contain some graphs also but When I update excel sheet than graph does not work into excel and data update respectively. 在Excel工作表中也包含一些图表,但是当我更新excel工作表时,图表不能分别用于excel和数据更新。 I think we had some issue for updating graph with openpyxl.Can anyone provide me some input to fix this issue 我认为我们在使用openpyxl更新图表时遇到了一些问题。任何人都可以提供一些输入来解决这个问题

or In other word,In the Excel sheet I have 10 worksheet.In worksheet 1, it contain graphs. 或换句话说,在Excel工作表中我有10个工作表。在工作表1中,它包含图形。 I have updated worksheet number 5. Worksheet is updated successfully. 我已更新工作表编号5.工作表已成功更新。 But I have loose the graphs of worksheet 1. 但我已经松散了工作表1的图表。

#!/usr/bin/env python
from openpyxl import load_workbook
import openpyxl 
print "pylx"
ddr_sam45_flop =  "Flip_Flop.xlsx"
flop_workbook     = load_workbook(ddr_sam45_flop)
raw_flop_workbook = flop_workbook.get_sheet_by_name(name ='RAW')
raw_flop_workbook.cell(row = 1 , column = 1).value = 889999
flop_workbook.save(ddr_sam45_flop)
print "End"

(Please consider me new to openpyxl) (请考虑我是openpyxl的新手)

截至目前,Openpyxl不支持图表或图表

Any graphs that exist in the document before opening will be deleted after saving. 保存后,将删除打开前文档中存在的任何图形。 The only way around this ( i know of) is to create the chart in code. 围绕这个(我知道)的唯一方法是在代码中创建图表。

Here is the documentation on how to create a chart in openpyxl 以下是有关如何在openpyxl中创建图表的文档

The example is a little broken, compare to this instead. 这个例子有点破碎,相比之下。

    values = Reference(ws, (1, 1), (1, 95))
    series = Series(values, title="Sample" )
    chart = LineChart()
    chart.append(series)
    ws.add_chart(chart)  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM