指定されたワークシートをPDFに保存する
デフォルトでは、Aspose.Cellsはブック内の表示されているすべてのワークシートをpdfファイルに保存します。PdfSaveOptions.SheetSet オプションを使用すると、特定のワークシートをpdfファイルに保存できます。例えば、アクティブなワークシートをpdfに保存する、すべてのワークシート(表示されているワークシートと非表示のワークシートの両方)をpdfに保存する、複数のカスタムワークシートをpdfに保存することができます。
アクティブワークシートをPDFに保存する
アクティブなシートのみをPDFにエクスポートする場合は、SheetSet.ActiveをPdfSaveOptions.SheetSetオプションに渡すことでこれを実現できます。
シート Sheet2
はソースファイル sheetset-example.xlsx のアクティブなシートです。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open the template excel file | |
Workbook wb = new Workbook("sheetset-example.xlsx"); | |
// Set active sheet to output | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.SheetSet = SheetSet.Active; | |
// Save the pdf file with PdfSaveOptions | |
wb.Save("output.pdf", pdfSaveOptions); |
すべてのワークシートをPDFに保存
SheetSet.Visible はワークブック内で表示されるシートを示し、SheetSet.All はワークブック内のすべてのシート(表示されているシートと非表示/不可視のシートの両方)を示します。すべてのシートをPDFにエクスポートしたい場合は、SheetSet.All オプションに単に PdfSaveOptions.SheetSet を渡すことができます。
ソースファイル sheetset-example.xlsx には、非表示シート Sheet3
を含むすべての4つのシートが含まれています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open the template excel file | |
Workbook wb = new Workbook("sheetset-example.xlsx"); | |
// Set all sheets to output | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.SheetSet = SheetSet.All; | |
// Save the pdf file with PdfSaveOptions | |
wb.Save("output.pdf", pdfSaveOptions); |
指定されたワークシートをPDFに保存
希望の/カスタム複数のシートをPDFにエクスポートしたい場合は、複数のシートの索引を PdfSaveOptions.SheetSet オプションに渡すことでこれを実現できます。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Open the template excel file | |
Workbook wb = new Workbook("sheetset-example.xlsx"); | |
// Set custom multiple sheets(Sheet1, Sheet3) to output | |
SheetSet sheetSet = new SheetSet(new int[] { 0, 2 }); | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.SheetSet = sheetSet; | |
// Save the pdf file with PdfSaveOptions | |
wb.Save("output.pdf", pdfSaveOptions); |