我正在将 ascii 文件中的数据读取到数组中,并将数据写入 excel 文件以进行进一步的后处理。总共有 337 列和 1100 行——这使得 xlsx 中有 370700 个单元格。
写入 excel 数据文件需要很长时间——在 16 GB 机器上大约需要 25-35 分钟。
有没有其他方法可以更有效地在 excel 文件中写入数据?
任何帮助都将不胜感激。
import numpy as np
import win32com.client as win32
import matplotlib.pyplot as plt
from win32com import client from time
clock, time start_time = clock()
itr = int(raw_input('Enter number of iteration = '))
f1 =open("Case_AT-6_WF_fl2.gid","r")
s2 = f1.read()
a = s2.split()
count=0 for col in open("Case_AT-6_WF_fl2.gid",'r'):
count = count+1 column = int(len(col.split()))
sm = int(itr * column)
digit = map(float,(a[(len(a)-sm):l
a[(column+7):(column*2+7)]
# preparing 2D matrix dig = np.array(digit) dig1 =(dig.reshape
### *******Plotting
## print name
for i in range(len(name)):
print i,"=",name[i]
plot = int(raw_input("\nEnter variable number for plot =" ))
# writing Excel file*******************************************
print('file printing option: 1 = Yes 2= No') q = int(raw_input(
printing option = "))
if q==1 :
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.Visible = False
wb = excel.Workbooks.Add()
ws=wb.Sheets(1)
ws.Name = "MyData"
ws.Activate
for kk in range(len(name)):
ws.Cells(2,kk+1).Value = name[kk]
ws.Cells(3,kk+1).Value = unit[kk]
m = 0
k =0
for j in range(itr):
for k in range(column):
ws.Cells(j+5,k+1).Value=dig1[j][k]
m = m+1
print '',m
print clock() - start_time, "seconds"
wb.SaveAs('C:\\Documents andSettings\\sd47086\\Desktop\\test\\MyWorkbook3.xlsx')
excel.Application.Quit()