Python库可使用图表打开现有的.xlsx工作簿 [英] Python library to open existing .xlsx workbook with charts

查看:77
本文介绍了Python库可使用图表打开现有的.xlsx工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须读取某个.xlsx文件(file1.xlsx),从另一个.csv文件(file2.csv)中提取数据,并将处理后的数据与一些图表一起写入原始文件(file1.xlsx).该文件具有现有图表,我研究过openpyxl,xlswriter,xlsread和其他python库.

I have to read a certain .xlsx file (file1.xlsx), pull data from another .csv files (file2.csv) and write the processed data into the original file (file1.xlsx) along with some charts. The file has existing charts, I have looked into openpyxl, xlswriter, xlsread, and other python libraries.

似乎openpyxl是唯一允许您使用同一库读写文件的库.其他诸如xlswriter只写,或xlsread只读.

It seems openpyxl is the only library which allows you to read and write files back with the same library. Others like xlswriter only write, or xlsread only read.

但是,即使openpyxl也是受限制的,因为如果我读取已经具有图表的文件,则图表将丢失.

However, even openpyxl is limited, in that if I read a file which already has charts, the charts are lost.

我只能想到仅通过python执行此操作的唯一方法是使用openpyxl和pywin32的组合. 1.从file2.csv中提取数据,处理数据并打印到另一个.xlsx文件(或保存在内存中) 2.使用pywin32从内存或file3.xlsx复制数据并将其复制到file1.xlsx.

The only way I can think of doing this from python only, is using a combination of openpyxl and pywin32. 1. extract data from file2.csv, process data and printout to another .xlsx file (or hold in memory) 2. copy data from memory or from file3.xlsx and past into file1.xlsx using pywin32.

在开始学习pywin32之前,我想检查一下这是否可行.我在Linux环境中工作,因此本来希望在执行数据处理时留在该环境中,但是我不知道是否还有其他出路.

Before, I dive into pywin32, I wanted to check if this is a feasible strategy. I am working in a Linux environment, so would have preferred to stay in this environment while doing the data processing, but I dont know whether there is another way out.

有人阅读过带有图表的excel工作簿,并将数据写到具有openpyxl或其他库的excel工作簿中(无需丢失图表)吗?

Has anybody read an excel workbook with charts and written data out to the same excel workbook with openpyxl or other libraries (WITHOUT LOSING THE CHARTS)?

推荐答案

熊猫也许能够读取和写入Excel.它使用xlrd读取excel文件,并使用xlswriter将其写出.因此,它似乎可以将使用xlrd的Excel文件加载到内存中,然后将其传递给xlsxwriter,以保存该文件.

Panda's maybe able to read and write to Excel. It uses xlrd to read excel files and xlswriter to write it out. So it seems that it can load the Excel file usign xlrd, into memory and pass it out to xlsxwriter, to save the file.

https://pandas.pydata.org /pandas-docs/stable/io.html#io-excel-writer

这篇关于Python库可使用图表打开现有的.xlsx工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆