我们有一个 Web 应用程序,它使用 Adobe ColdFusion 电子表格函数将报告导出到 Excel,其中两个函数是 SpreadsheetSetHeader 和 SpreadsheetSetFooter。有没有人想出如何使用这些函数嵌入 excel 文件的页码?
在 Excel 中,如果您转到页眉/页脚,您可以放置 &[PAGE] 以在打印时插入页码,但我还没有找到在 ColdFusion 中执行此操作的方法。
最佳答案
POI 是 CF 在底层用于生成电子表格的工具。 POI 有自己的格式代码,但它们是相似的。在页脚字符串中使用 &P
(当前页)和 &N
(总页数)。
<cfscript>
// Create demo spreadsheet
sheet = SpreadsheetNew("Sheet1", true);
sheet.setCellValue("Test", 1,1);
// Add footer with page numbers
sheet.setFooter("", "&P of &N", "");
// Download
cfheader(name="Content-Disposition",value="attachment; filename=Sheet.xlsx");
cfcontent(type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
, variable="#SpreadsheetReadBinary( sheet )#");
</cfscript>
有关格式化代码的更多信息,请参阅 POI 的 XSSHeaderFooter 文档.
关于excel - 有没有办法使用 ColdFusion SpreadsheetSetHeader/Footer 函数在页眉/页脚中添加 Excel 页码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68660442/