各ワークシートを別の PDF ファイルに保存する
Contents
[
Hide
]
Aspose.Cells は、XLS ファイル (画像、チャートなどを含む) を PDF ドキュメントに変換することをサポートします。 Aspose.Cells for .NET は独立してスプレッドシートを PDF に変換できます。変換に Aspose.PDF for .NET を使用する必要はありません。プロセス全体をメモリ内で実行できるため、変換ではソフトウェアが一時ファイルを作成または使用する必要はありません。
各ワークシートを別の PDF ファイルに保存する
異なる PDF ファイルを生成するためにテンプレート Excel ファイルに各ワークシートを保存する必要がある場合、これは簡単に実現できます。ファイル内のシートを非表示にし、一度に 1 つのシートを表示して PDF にレンダリングすることを試みることができます。
This file contains hidden or 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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Get the Excel file path | |
string filePath = dataDir + "input.xlsx"; | |
// Instantiage a new workbook and open the Excel, File from its location | |
Workbook workbook = new Workbook(filePath); | |
// Get the count of the worksheets in the workbook | |
int sheetCount = workbook.Worksheets.Count; | |
// Define PdfSaveOptions | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
// Take Pdfs of each sheet | |
for (int j = 0; j < sheetCount; j++) | |
{ | |
Worksheet ws = workbook.Worksheets[j]; | |
//set worksheet to output | |
SheetSet sheetSet = new SheetSet(new int[] { ws.Index }); | |
pdfSaveOptions.SheetSet = sheetSet; | |
workbook.Save(dataDir + "worksheet-" + ws.Name + ".out.pdf", pdfSaveOptions); | |
} |
スプレッドシートに数式が含まれている場合は、Workbook.CalculateFormula()スプレッドシートを PDF 形式にレンダリングする直前。そうすることで、式に依存する値が再計算され、正しい値が PDF に表示されるようになります。