XLSX ファイルを PDF フォーマットに変換する

ExcelをPDFに変換する

この例では、Excel ファイル(SampleInput.xlsx)をテンプレートとして使用しています。ワークブックには、フォント、属性、色、網掛け効果、境界などを使用したさまざまな形式のワークシートが含まれています。最初のワークシートには列グラフがあり、最後のワークシートには画像が含まれています。

テンプレートの Excel ファイル

テンプレートファイルには、グラフが含まれたワークシートが3つあり、最後のワークシートには画像が含まれています。以下のスクリーンショットに例示されています。

todo:image_alt_text todo:image_alt_text
最初のワークシート**(売上予測)** 2番目のワークシート**(売上報告)**
todo:image_alt_text todo:image_alt_text
3番目のワークシート**(データ入力)** 最後のワークシート**(画像)**

変換プロセス

// 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);
try
{
// Get the template excel file path.
string designerFile = dataDir + "SampleInput.xlsx";
// Specify the pdf file path.
string pdfFile = dataDir + "Output.out.pdf";
// Open the template excel file
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(designerFile);
// Save the pdf file.
wb.Save(pdfFile, SaveFormat.Pdf);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}

結果

上記のコードを実行すると、アプリケーションディレクトリのFilesフォルダにPDFファイルが作成されます。 以下のスクリーンショットは、PDFページを示しています。ヘッダーとフッターも出力されたPDFファイルに保持されていることに注意してください。

todo:image_alt_text todo:image_alt_text
最初のワークシート**(売上予測)** 2番目のワークシート**(売上報告)**
todo:image_alt_text todo:image_alt_text
3番目のワークシート**(データ入力)** 最後のワークシート**(画像)**