xlsxwriter:在其中添加带有其他工作表的公式 [英] xlsxwriter: add formula with other sheet in it

查看:30
本文介绍了xlsxwriter:在其中添加带有其他工作表的公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 xlsxwriter python 插件创建一个 XLSX 文件.在这个 XLSX 中,我有 2 张纸:

I try to create a XLSX file with xlsxwriter python plugin. In this XLSX, I have 2 sheets:

  • 分析:包含一个包含信息的表格
  • Stat:包含一些信息和2个公式
  • Analyse: Contain a table with informations
  • Stat: Contain some informations and 2 formulas

这两个公式是:

=NBVAL(Analyse!C:C)-1
=NB.SI(Analyse!D:D;"To change")

我的问题是当我打开生成的文件时,出现错误.并且公式不起作用.如果我编辑公式并按 Enter 键,它会起作用.

My problem is when I open the generated file, I have a error. And the formulas don't work. If I edit the formula and just press Enter, it work.

我的代码:

shInfo    = self.__workbook.add_worksheet("Stat")
shInfo.activate()

information = self.__workbook.add_format({'bg_color': '#BFBFBF',
                                          'font_name': 'Courier New'})

shInfo.write('G3','=NBVAL(Analyse!C:C)-1',information)
shInfo.write('G5','=NB.SI(Analyse!D:D;"To change")',information)

当我打开 XML 错误报告时.我有这个:

When I open the XML error report. I have this:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <logFileName>error056160_04.xml</logFileName>
  <summary>Des erreurs ont été détectées dans le fichier « L:\UNMS\InputBEB\Output\UNMSViewer\public_html\Data\XLSX\todo\A6S54300.xlsx »</summary>
  <removedRecords summary="Liste des enregistrements supprimés ci-dessous :">  
    <removedRecord>Enregistrements supprimés: Formule dans la partie /xl/worksheets/sheet2.xml</removedRecord>
    </removedRecords>
</recoveryLog>

推荐答案

问题可能是公式函数名称是法语,但 Excel 希望它以 英语.至少在 XlsxWriter 编写的文件中.

The issue is probably that the formula function names are in French but Excel expects it to be stored/written in English. At least in the files written by XlsxWriter.

试试这个:

shInfo.write('G3','=COUNTA(Analyse!C:C)-1',information)
shInfo.write('G5','=COUNTIF(Analyse!D:D,"To change")',information)

如果您向我发送一个使用法语版 Excel 保存的小示例文件,我会查看是否可以在 XlsxWriter 编写的文件中设置一个标志来指示公式的语言.

If you send me a small sample file saved using a French version of Excel I'll have a look and see if it is possible to set a flag in the files written by XlsxWriter to indicate the language of the formulas.

更新:COUNTIF() 公式也需要使用美式逗号运算符,而不是 ;.更新 2:根据@gatchan 提供的示例文件,文件中没有语言标识符.公式在保存时会被 Excel 翻译成英文和美式逗号运算符.

Update: The COUNTIF() formula also needs to use the US style comma operator instead of ;. Update 2: Based on the sample file provided by @gatchan there is no language identifier in the file. The formula is translated to English and US style comma operator, by Excel, when it is saved .

这篇关于xlsxwriter:在其中添加带有其他工作表的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆