2016-04-08 43 views
0

我想在windows,Python 2.7,xlwt 7.4上使用xlwt編寫一個.xls文件。我使用Excel 2013年使用xlwt創建的Excel警告打開文件:文件錯誤

我做了easyxf格式:

borders = "borders: top thin, bottom thin, left thin, right thin;" 
align = "align: wrap on, vert centre, horiz centre;" 
pattern = 'pattern: pattern solid, fore_colour ' + color_f(center) + ";" 
pct  = "num_format_str = 0%" 
pct_style = xlwt.easyxf(pattern + borders + align, pct) 

寫下了這些細胞:

ws.write (xlrow, 7, 1.0 * optempo/span, pct_style) 
ws.write (xlrow, 8, 1.0 - total/n_workdays, pct_style) 

當我打開的.xls,彈出提示「文件錯誤:某些數字格式可能已經丟失。「單元格被格式化爲整數或實數,而不是百分比。沒有其他問題。這些值在數學上是正確的。

任何想法發生了什麼?

謝謝!

回答

1

您在您的pct字符串中包含參數名稱num_format_str,這是錯誤的。

嘗試:

borders = "borders: top thin, bottom thin, left thin, right thin;" 
align = "align: wrap on, vert centre, horiz centre;" 
pattern = 'pattern: pattern solid, fore_colour ' + color_f(center) + ";" 
pct  = "0%" 
pct_style = xlwt.easyxf(pattern + borders + align, num_format_str = pct) 

See here進一步信息上xlwt.easyxf()

+0

完美!謝謝! – Gerry

相關問題