各ワークシートを別の PDF ファイルに保存する
Contents
[
Hide
]
Aspose.Cells は、スプレッドシート ファイル (画像、チャートなどを含む) を PDF ドキュメントに変換することをサポートします。 Aspose.Cells for Java は、スプレッドシートを PDF ドキュメントに変換するために独立して動作することができ、変換に Aspose.PDF for Java を使用する必要がなくなりました。プロセス全体をメモリ内で実行できるため、変換では一時ファイルを作成/使用する必要はありません。
各ワークシートをテンプレート Excel ファイルに保存して、異なる PDF ファイルを生成する必要がある場合。これは簡単に実現できます。ファイル内のシートを非表示にして、PDF をレンダリングすることに基づいて一度に 1 つのシートを表示しようとする場合があります。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(SaveEachWorksheettoDifferentPDF.class); | |
// Instantiate a new workbook and open the Excel | |
// File from its location | |
Workbook workbook = new Workbook(dataDir + "input.xlsx"); | |
// Get the count of the worksheets in the workbook | |
int sheetCount = workbook.getWorksheets().getCount(); | |
// Define PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Take Pdfs of each sheet | |
for (int j = 0; j < sheetCount; j++) { | |
Worksheet ws = workbook.getWorksheets().get(j); | |
//set worksheet to output | |
SheetSet sheetSet = new SheetSet(new int[] { ws.getIndex() }); | |
pdfSaveOptions.setSheetSet(sheetSet); | |
workbook.save(dataDir + "_" + ws.getName() + ".pdf", pdfSaveOptions); | |
} |
スプレッドシートに数式が含まれている場合は、[Workbook.calculateFormula](https://reference.aspose.com/cells/java/com.aspose.cells/workbook#calculateFormula()メソッドをスプレッドシートを PDF にレンダリングする直前に実行します。これにより、式に依存する値が再計算され、正しい値が PDF にレンダリングされます。