ExcelからPDFへの変換時に生成されるページ数を制限 C++版
Contents
[
Hide
]
時には、特定のページ範囲を出力PDFファイルに印刷したいことがあります。Aspose.Cellsには、ExcelスプレッドシートをPDFファイル形式に変換する際に生成されるページ数を制限する機能があります。
生成されるページ数の制限
次の例では、Microsoft Excelファイルのページ3と4をPDFにレンダリングする方法が示されています。
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Path of input Excel file
U16String inputFilePath = srcDir + u"TestBook.xlsx";
// Create workbook
Workbook wb(inputFilePath);
// Instantiate the PdfSaveOption
PdfSaveOptions options;
// 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);
// Path of output PDF file
U16String outputFilePath = srcDir + u"outPDF1.out.pdf";
// Save the PDF file
wb.Save(outputFilePath, options);
std::cout << "PDF file saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}
スプレッドシートに数式が含まれている場合、PDFにレンダリングする直前にWorkbook.CalculateFormula()を呼び出すことが最善です。これにより、数式に依存した値が再計算され、正しい値が出力ファイルに表示されます。