PDF へのレンダリング中に、MS Excel ワークブックの外部リソースの読み込みを制御します
Contents
[
Hide
]
考えられる使用シナリオ
Excel ファイルには、リンクされた画像やオブジェクトなどの外部リソースが含まれている場合があります。 Excel ファイルを PDF に変換すると、Aspose.Cells はこれらの外部リソースを取得し、それらを PDF にレンダリングします。これを使用して行うことができますWorkbookSettings.StreamProviderを実装するIStreamProviderインターフェース。
PDF へのレンダリング中に、MS Excel ワークブックの外部リソースの読み込みを制御します
次のサンプル コードは、WorkbookSettings.StreamProvider外部リソースのロードを制御し、それらを操作します。を確認してくださいサンプル Excel ファイルコード内で使用され、出力 PDFコードによって生成されます。のスクリーンショット方法を示します古い外観イメージサンプル Excel ファイルの新しいイメージ出力 PDF で。
サンプルコード
This file contains 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 | |
//Implement IStreamProvider | |
class MyStreamProvider : IStreamProvider | |
{ | |
public void CloseStream(StreamProviderOptions options) | |
{ | |
System.Diagnostics.Debug.WriteLine("-----Close Stream-----"); | |
} | |
public void InitStream(StreamProviderOptions options) | |
{ | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
System.Diagnostics.Debug.WriteLine("-----Init Stream-----"); | |
//Read the new image in a memory stream and assign it to Stream property | |
byte[] bts = File.ReadAllBytes(sourceDir + "newPdfSaveOptions_StreamProvider.png"); | |
MemoryStream ms = new MemoryStream(bts); | |
options.Stream = ms; | |
} | |
} | |
public static void Run() | |
{ | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
//Load source Excel file containing external image | |
Workbook wb = new Workbook(sourceDir + "samplePdfSaveOptions_StreamProvider.xlsx"); | |
//Specify Pdf Save Options - Stream Provider | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.OnePagePerSheet = true; | |
wb.Settings.ResourceProvider = new MyStreamProvider(); | |
//Save the workbook to Pdf | |
wb.Save(outputDir + "outputPdfSaveOptions_StreamProvider.pdf", opts); | |
Console.WriteLine("ControlLoadingOfExternalResourcesInExcelToPDF executed successfully.\r\n"); | |
} |