PDF

Excel ワークブックを PDF に変換する

PDF ファイルは、組織、政府部門、および個人の間でドキュメントを交換するために広く使用されています。これは標準的なドキュメント形式であり、ソフトウェア開発者は、Microsoft Excel ファイルを PDF ドキュメントに変換する方法を見つけるように求められることがよくあります。

Aspose.Cells は、Excel ファイルの PDF への変換をサポートし、変換で高い視覚的忠実度を維持します。

直接変換

Aspose.Cells for .NET は、他のソフトウェアとは独立してスプレッドシートから PDF への変換をサポートします。を使用して Excel ファイルを PDF に保存するだけです。**ワークブッククラス'保存方法。の保存メソッドは、SaveFormat.Pdf**ネイティブ Excel ファイルを PDF 形式に変換する列挙型メンバー。

以下の手順に従って、Excel スプレッドシートを PDF 形式に直接変換します。

  1. のオブジェクトをインスタンス化する**ワークブック**空のコンストラクターを呼び出してクラスを作成します。
  2. ワークブックを最初から作成する場合は、既存のテンプレート ファイルを開いて読み込むか、この手順をスキップできます。
  3. Aspose.Cells' API を使用して、スプレッドシートで任意の作業 (データの入力、書式の適用、数式の設定、画像やその他の描画オブジェクトの挿入など) を実行します。
  4. スプレッドシート コードが完成したら、**ワークブッククラス'保存**スプレッドシートを保存するメソッド。

ファイル形式は PDF である必要があるため、選択しますPDF(定義済みの値) から**保存形式**最終的な PDF ドキュメントを生成するための列挙。

// 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);
// Instantiate the Workbook object
// Open an Excel file
Workbook workbook = new Workbook(dataDir + "Book1.xls");
// Save the document in PDF format
workbook.Save(dataDir + "output.pdf", SaveFormat.Pdf);

高度な変換

また、**PdfSaveOptionsクラスを使用して、変換用にさまざまな属性を設定します。のさまざまなプロパティの設定PdfSaveOptionsクラスを使用すると、出力 PDF の印刷、フォント、セキュリティ、および圧縮設定を制御できます。最も重要なプロパティは次のとおりです。コンプライアンス**これにより、Excel ファイルを PDF/A 準拠の PDF ファイルに保存できます。

ワークブックを PDF/A コンパイル済みファイルに保存する

以下のコード スニペットは、**PdfSaveOptions**クラスを使用して、Excel ファイルを PDF/A 準拠の PDF 形式で保存します。

// 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);
// Instantiate new workbook
Workbook workbook = new Workbook();
// Insert a value into the A1 cell in the first worksheet
workbook.Worksheets[0].Cells[0, 0].PutValue("Testing PDF/A");
// Define PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
// Set the compliance type
pdfSaveOptions.Compliance = PdfCompliance.PdfA1b;
// Save the file
workbook.Save(dataDir + "output.pdf", pdfSaveOptions);

PDF 作成時刻を設定します

とともに**PdfSaveOptions**クラスでは、PDF の作成時刻を取得または設定できます。次のコードは、**PdfSaveOptions.CreatedTime**プロパティを使用して、PDF ファイルの作成時間を設定します。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string inputPath = dataDir + "Book1.xlsx";
// Load excel file containing charts
Workbook workbook = new Workbook(inputPath);
// Create an instance of PdfSaveOptions
PdfSaveOptions options = new PdfSaveOptions();
options.CreatedTime = DateTime.Now;
// Save the workbook to PDF format while passing the object of PdfSaveOptions
workbook.Save(dataDir + "output.pdf", options);

ContentCopyForAccessibility オプションを設定する

とともに**PdfSaveOptions**クラスでは、PDF を取得または設定できます**AccessibilityExtractContent**変換された PDF のコンテンツ アクセスを制御するオプション。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
string inputPath = sourceDir + "BookWithSomeData.xlsx";
// Load excel file containing some data
Workbook workbook = new Workbook(inputPath);
// Create an instance of PdfSaveOptions and pass SaveFormat to the constructor
PdfSaveOptions pdfSaveOpt = new PdfSaveOptions();
// Create an instance of PdfSecurityOptions
PdfSecurityOptions securityOptions = new PdfSecurityOptions();
// Set AccessibilityExtractContent to true
securityOptions.AccessibilityExtractContent = false;
// Set the securityoption in the PdfSaveOptions
pdfSaveOpt.SecurityOptions = securityOptions;
// Save the workbook to PDF format while passing the object of PdfSaveOptions
workbook.Save(outputDir + "outFile.pdf", pdfSaveOpt);

カスタム プロパティを PDF にエクスポート

とともに**PdfSaveOptions**クラスで、ソース ワークブックのカスタム プロパティを PDF にエクスポートできます。**PdfCustomPropertiesExport**列挙子は、プロパティをエクスポートする方法を指定するために提供されています。これらのプロパティは、次の図に示すように、[ファイル] をクリックしてから [プロパティ] オプションをクリックすると、Adobe Acrobat Reader で確認できます。テンプレートファイル「sourceWithCustProps.xlsx」がダウンロード可能ここテストおよび出力用 PDF ファイル「outSourceWithCustProps」が利用可能ここ分析のために。

todo:画像_代替_文章

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Load excel file containing custom properties
Workbook workbook = new Workbook("sourceWithCustProps.xlsx");
// Create an instance of PdfSaveOptions
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
// Set CustomPropertiesExport property to PdfCustomPropertiesExport.Standard
pdfSaveOptions.CustomPropertiesExport = Aspose.Cells.Rendering.PdfCustomPropertiesExport.Standard;
// Save the workbook to PDF format while passing the object of PdfSaveOptions
workbook.Save("outSourceWithCustProps.pdf", pdfSaveOptions);

コンバージョン属性

新しいリリースごとに変換機能の強化に取り組んでいます。 Aspose.Cell の Excel から PDF への変換には、まだいくつかの制限があります。 PDF 形式に変換すると、一部のスプレッドシートの形式が失われる場合があります。また、一部の描画オブジェクトはまだサポートされていません。

次の表は、Aspose.Cells を使用して PDF にエクスポートするときに完全または部分的にサポートされるすべての機能を示しています。 .

ドキュメント要素 属性 対応 ノート
アライメント はい
背景設定 はい
国境 はい
国境 線のスタイル はい
国境 線幅 はい
Cell データ はい
コメント はい
条件付き書式 はい
ドキュメント プロパティ はい
描画オブジェクト 部分的に サポートされているオブジェクト: TextBox、Line、Rectangle、Oval、GroupBox、Button、CheckBox、RadioButton、ListBox、ComboBox、Label
フォント サイズ はい
フォント はい
フォント スタイル はい
フォント 下線 はい
フォント 効果 部分的に 取り消し線効果のみがサポートされています
画像 はい
ハイパーリンク はい
チャート 部分的に
合併Cells はい
改ページ はい
ページ設定 ヘッダー/フッター はい
ページ設定 余白 はい
ページ設定 ページの向き はい
ページ設定 ページサイズ はい
ページ設定 印刷範囲 はい
ページ設定 タイトルを印刷する はい
ページ設定 スケーリング はい
行の高さ/列の幅 はい
RTL (右から左) 言語 はい

先行トピック