【问题标题】:Excel warning opening file created with xlwt: file error使用 xlwt 创建的 Excel 警告打开文件:文件错误
【发布时间】:2016-04-08 12:25:44
【问题描述】:

我正在尝试在 Windows、Python 2.7、xlwt 7.4 上使用 xlwt 编写 .xls 文件。我正在使用 Excel 2013。

我做了一个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 时,会弹出一个提示“文件错误:某些数字格式可能已丢失”。单元格被格式化为整数或实数,而不是百分比。没有其他问题。这些值在数学上是正确的。

有什么想法吗?

谢谢!

【问题讨论】:

    标签: python excel xlwt


    【解决方案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()的信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-19
      • 1970-01-01
      • 2016-04-17
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多