python读取excel表格太⼤怎么办_Python:使⽤Openpyxl读取
⼤型Exc。。。
尝试对load_workbook()类使⽤read_only = True属性,这会导致您获得的⼯作表为IterableWroksheet,这意味着您只能迭代它们,您不能直接使⽤列/⾏号来访问其中的单元格值.根据
documentation,这将提供接近恒定的存储器消耗.
此外,您不需要关闭⽂件,语句将为您处理.
⽰例 –
import openpyxl
import csv
python怎么读入excelimport time
ime())
importedfile = openpyxl.load_workbook(filename = "C:/Users/User/Desktop/Giant Workbook.xlsm", read_only = True,
keep_vba = False)
tabnames = _sheet_names()
substring = "Keyword"
for num in tabnames:
if num.find(substring) > -1:
_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 ws:
savefile.writerow([cell.value for cell in i])
ime())
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.