简体   繁体   English

excel表中没有数据

[英]Data not present in excel sheet

I'm reading a existing excel file by using openpyxl package and trying to save that file it, and it got saved but after opening that excel file no data is present. 我正在使用openpyxl包读取现有的excel文件并尝试保存该文件,并保存但是在打开excel文件后没有数据存在。 I used the following code and my requirement is to open the file in use_iterators = True mode only 我使用了以下代码,我的要求是仅在use_iterators = True模式下打开文件

from openpyxl import load_workbook
wb = load_workbook(filename = 'large_file.xlsx', use_iterators = True)

ws = wb.get_sheet_by_name(name = 'big_data') 

for row in ws.iter_rows():

    for cell in row:

        print cell.internal_value

wb.save("large_file.xlsx")

can u guys show how to save the file and close the file after saving with out losing the data 你们可以展示如何保存文件并在保存后关闭文件而不丢失数据

Try loading with use_iterators = False , as use_iterators = True loads the data information differently, such that it may not contain all the information you wish to save. 尝试使用use_iterators = False加载,因为use_iterators = True以不同方式加载数据信息,因此它可能不包含您要保存的所有信息。

Openpyxl writes and entirely new excel file based on the information it has read in, so it's not like you make a small change and just update the file. Openpyxl根据它读入的信息编写了全新的excel文件,因此它不像你做一个小改动而只是更新文件。 (This also means if certain features aren't supported in openpyxl (such as VB macros), these won't exist in the file you've saved.) (这也意味着如果openpyxl中不支持某些功能(例如VB宏),这些功能将不会存在于您保存的文件中。)

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

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