如何使unconv自动计算公式转换成pdf格式?

2024-04-26 22:08:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python模块Xlsxwriter创建了一个.xlsx文件。在

运行良好,但运行时,任何包含公式的单元格都将显示为空或0

unoconv -f pdf spreadsheet.xlsx

如何强制unconv在转换为pdf之前自动计算值?在


Tags: 模块文件pdfxlsx公式spreadsheetxlsxwriterunoconv
1条回答
网友
1楼 · 发布于 2024-04-26 22:08:55

在撰写本文时,显然unoconv故意不进行任何重新计算,因为它可能会导致错误。见Issue 97。unoconv源代码的相关部分被注释掉了。在

因此,您可以尝试进入unoconv的副本并取消对这些行的注释(使它们再次处于活动状态)。你可能会犯错,也可能没事。在

如果公式很简单,您可以尝试的另一种方法是使用Python计算它们,并使用XlsxWriter将结果与公式一起编写。注意,^{} method有一个可选的value参数。引用官方文件:

XlsxWriter doesn’t calculate the result of a formula and instead stores the value 0 as the formula result. It then sets a global flag in the XLSX file to say that all formulas and functions should be recalculated when the file is opened. This is the method recommended in the Excel documentation and in general it works fine with spreadsheet applications. However, applications that don’t have a facility to calculate formulas, such as Excel Viewer, or some mobile applications will only display the 0 results.

If required, it is also possible to specify the calculated result of the formula using the optional value parameter. This is occasionally necessary when working with non-Excel applications that don’t calculate the result of the formula: [...]

请注意,如果公式是这样的,您可以使用Python计算它们,并且您只关心最终的PDF(没有人会使用电子表格,并且在您将其转换为PDF之后,您可以将其丢弃),那么您可以直接编写值,而不需要使用公式。在

相关问题 更多 >