XLS ファイルを PDF 形式に変換する

Excel を PDF に変換する

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

テンプレート Excel ファイル

テンプレート ファイルには、グラフとメディアとしての画像を含む 3 つのワークシートがあります。以下のスクリーンショットに示すように、最初のワークシートにはグラフがあり、最後のワークシートには画像があります。

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

変換プロセス

  1. Aspose.Cells をダウンロードしてインストールします。
  2. Aspose.Cells for .NET をダウンロードします。
  3. 開発用コンピューターにインストールします。
  4. プロジェクトを作成して参照を追加します。
  5. Visual Studio.Net を起動します。
  6. 新しいコンソール アプリケーションを作成します。
  7. …\Program Files\Aspose\Aspose.Cells\Bin\Net1.0\Aspose.Cells.dll への参照を追加します。
  8. プロジェクトに変換コードを追加します。
// 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.xls";
// 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:画像_代替_文章 todo:画像_代替_文章
最初のワークシート**(販売予測)** 2 番目のワークシート**(売上報告)**
todo:画像_代替_文章 todo:画像_代替_文章
3 番目のワークシート**(データ入力)** 最後のワークシート**(画像)**