使用Node.js通过C++将所有工作表列适配到单一PDF页面
Contents
[
Hide
]
有时候,您希望生成一个PDF文件,将工作表的所有列适合一页。PdfSaveOptions.getAllColumnsInOnePagePerSheet()属性以一种非常易于使用的方式提供了这种功能。输出PDF的高度和宽度等复杂计算是在内部处理的,是基于工作表中的数据。
使工作表列适合单个PDF页面
PdfSaveOptions.getAllColumnsInOnePagePerSheet()确保工作表中的所有列都呈现在单一PDF页面上,尽管行可能会根据工作表中的数据展开至多多页。
下面的示例代码显示了如何使用PdfSaveOptions.getAllColumnsInOnePagePerSheet()属性呈现一个包含100列的大型工作表。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Create and initialize an instance of Workbook
const workbook = new AsposeCells.Workbook(path.join(dataDir, "TestBook.xlsx"));
// Create and initialize an instance of PdfSaveOptions
const saveOptions = new AsposeCells.PdfSaveOptions();
// Set AllColumnsInOnePagePerSheet to true
saveOptions.setAllColumnsInOnePagePerSheet(true);
// Save Workbook to PDF format by passing the object of PdfSaveOptions
const outputFilePath = path.join(dataDir, "output.out.pdf");
workbook.save(outputFilePath, saveOptions);
当给定的工作表有很多列时,渲染的PDF文件可能以非常小的尺寸显示内容。在类似Acrobat Reader的查看应用程序中缩放后仍然可读。
如果您的电子表格包含公式,最好在将电子表格呈现为PDF格式之前调用 Workbook.calculateFormula()。这样做将确保重新计算依赖于公式的值,并在PDF中呈现正确的值。