为渲染自动调整行高(Node.js通过C++)
Contents
[
Hide
]
通常情况下,为了在单元格中显示全部文本,可以在Microsoft Excel中以普通视图(100%的缩放)自动调整行高。这允许在普通视图中完全显示文本,即使打印或保存为PDF,文本也会正确显示。
然而,在某些情况下,自动调整行高在普通视图中效果良好,但切换到打印视图或保存为PDF时,文本会被剪裁。请检查源文件[Book1.xlsx]及截图。
如果想防止在保存的PDF文件中剪裁文本,可以使用带有AutoFitterOptions.getForRendering()选项的自动调整行高。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "Book1.xlsx");
// Init workbook instance.
const workbook = new AsposeCells.Workbook(filePath);
// Set autofit options for rendering.
const autoFitterOptions = new AsposeCells.AutoFitterOptions();
autoFitterOptions.setForRendering(true);
// Autofit rows with options.
workbook.getWorksheets().get(0).autoFitRows(autoFitterOptions);
// Save to pdf.
workbook.save("output.pdf", AsposeCells.SaveFormat.Pdf);
现在,在输出的 PDF 文件中文本不再被截断。