生成されるページ数を制限する ExcelからPDFへの変換 with Node.js via C++
Contents
[
Hide
]
場合によっては、ページ範囲を出力のPDFファイルに印刷したいことがあります。Aspose.Cells for Node.js via C++は、ExcelスプレッドシートをPDFファイル形式に変換する際に生成されるページ数の制限を設定する機能を持ちます。
生成されるページ数の制限
次の例では、Microsoft Excelファイルのページ3と4をPDFにレンダリングする方法が示されています。
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Open an Excel file
const workbook = new AsposeCells.Workbook(path.join(dataDir, "TestBook.xlsx"));
// Instantiate the PdfSaveOption
const options = new AsposeCells.PdfSaveOptions();
// Print only Page 3 and Page 4 in the output PDF
// Starting page index (0-based index)
options.setPageIndex(3);
// Number of pages to be printed
options.setPageCount(2);
// Save the PDF file
workbook.save(path.join(dataDir, "outPDF1.out.pdf"), options);
スプレッドシートに数式が含まれている場合は、PDFにレンダリングする直前にWorkbook.calculateFormula()を呼び出すのが最良です。これにより、数式依存の値が再計算され、正しい値が出力ファイルにレンダリングされます。