python读取excel表格太大怎么办_Python:使用Openpyxl读取大型Excel工作表
嘗試對load_workbook()類使用read_only = True屬性,這會導(dǎo)致您獲得的工作表為IterableWroksheet,這意味著您只能迭代它們,您不能直接使用列/行號來訪問其中的單元格值.根據(jù)
documentation,這將提供接近恒定的存儲器消耗.
此外,您不需要關(guān)閉文件,語句將為您處理.
示例 –
import openpyxl
import csv
import time
print(time.ctime())
importedfile = openpyxl.load_workbook(filename = "C:/Users/User/Desktop/Giant Workbook.xlsm", read_only = True, keep_vba = False)
tabnames = importedfile.get_sheet_names()
substring = "Keyword"
for num in tabnames:
if num.find(substring) > -1:
sheet=importedfile.get_sheet_by_name(num)
name = "C:/Users/User/Desktop/Test/" + num + ".csv"
with open(name, 'w', newline='') as file:
savefile = csv.writer(file)
for i in sheet.rows:
savefile.writerow([cell.value for cell in i])
print(time.ctime())
Sometimes, you will need to open or write extremely large XLSX files, and the common routines in openpyxl won’t be able to handle that load. Fortunately, there are two modes that enable you to read and write unlimited amounts of data with (near) constant memory consumption.
總結(jié)
以上是生活随笔為你收集整理的python读取excel表格太大怎么办_Python:使用Openpyxl读取大型Excel工作表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端静态页面html珠宝首饰电商平台网站
- 下一篇: vue功能-键盘