Excel ワークブックを PDF に変換する
PDF ファイルは、組織、政府部門、および個人の間でドキュメントを交換するために広く使用されています。これは標準的なドキュメント形式であり、ソフトウェア開発者は、Microsoft Excel ファイルを PDF ドキュメントに変換する方法を見つけるように求められることがよくあります。
Aspose.Cells は、Excel ファイルの PDF への変換をサポートし、変換で高い視覚的忠実度を維持します。
Aspose.Cells for .NET は、出力ドキュメントに API とバージョン番号に関する情報を直接書き込みます。たとえば、Document を PDF にレンダリングすると、Aspose.Cells for .NET が読み込まれます。応用値が「Aspose.Cells」のフィールドとPDF プロデューサー値を持つフィールド、例えば「Aspose.Cells v17.9」。
出力ドキュメントからこの情報を変更または削除するように Aspose.Cells for .NET に指示することはできないことに注意してください。
直接変換
Aspose.Cells for .NET は、他のソフトウェアとは独立してスプレッドシートから PDF への変換をサポートします。を使用して Excel ファイルを PDF に保存するだけです。**ワークブッククラス'保存方法。の保存メソッドは、SaveFormat.Pdf**ネイティブ Excel ファイルを PDF 形式に変換する列挙型メンバー。
以下の手順に従って、Excel スプレッドシートを PDF 形式に直接変換します。
- のオブジェクトをインスタンス化する**ワークブック**空のコンストラクターを呼び出してクラスを作成します。
- ワークブックを最初から作成する場合は、既存のテンプレート ファイルを開いて読み込むか、この手順をスキップできます。
- Aspose.Cells' API を使用して、スプレッドシートで任意の作業 (データの入力、書式の適用、数式の設定、画像やその他の描画オブジェクトの挿入など) を実行します。
- スプレッドシート コードが完成したら、**ワークブッククラス'保存**スプレッドシートを保存するメソッド。
ファイル形式は 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」が利用可能ここ分析のために。
// 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 (右から左) 言語 | はい |
先行トピック
- PDF ブックマークを追加
- PDF ブックマークに名前付きの宛先を追加
- 印刷するものが何もない場合、出力 PDF で空白ページを回避する
- PDF に保存するときに、特定の Unicode 文字だけのフォントを変更します
- PDF へのレンダリング中に、MS Excel ワークブックの外部リソースの読み込みを制御します
- XLS ファイルを PDF 形式に変換する
- Excel ファイルを PDFA-1a と互換性のある PDF 形式に変換します
- 画像またはチャートを含む XLS ファイルを PDF に変換します
- グラフ シートの PdfBookmarkEntry を作成する
- ワークシートのすべての列を単一の PDF ページに合わせる
- DrawObjectEventHandler クラスを使用して PDF へのレンダリング中に DrawObject と Bound を取得する
- Excel ファイルのレンダリング中にフォントの置換に関する警告を受け取る
- Excel を PDF にレンダリングする際のエラーを無視する
- 生成されるページ数を制限する - Excel を PDF に変換
- PDF に保存しながらコメントを印刷
- Excel を PDF に変換しながら Office アドインをレンダリングする
- Excel ワークシートごとに 1 つの PDF ページをレンダリング - Excel から PDF への変換
- Aspose.Cells による出力 PDF の Unicode 補助文字のレンダリング
- 追加画像のリサンプリング - Excel から PDF への変換
- 各ワークシートを別の PDF ファイルに保存する
- Excel を PDF に標準サイズまたは最小サイズで保存
- 安全な PDF ドキュメント
- 出力PDFと画像の文字列の交差方法を指定