التحكم في تحميل الموارد الخارجية في مصنف MS Excel أثناء التقديم إلى PDF
Contents
[
Hide
]
سيناريوهات الاستخدام الممكنة
قد يحتوي ملف Excel الخاص بك على موارد خارجية مثل الصور أو الكائنات المرتبطة. عند تحويل ملف Excel إلى PDF ، يقوم Aspose.Cells باسترداد هذه الموارد الخارجية وتقديمها إلى PDF. لكن في بعض الأحيان ، لا تريد تحميل هذه الموارد الخارجية وأكثر من ذلك ، فأنت تريد التلاعب بها. يمكنك القيام بذلك باستخدامWorkbookSettings.StreamProviderالذي ينفذIStreamProviderواجهه المستخدم.
التحكم في تحميل الموارد الخارجية في مصنف MS Excel أثناء التقديم إلى PDF
يشرح نموذج التعليمات البرمجية التالي كيفية الاستفادة من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"); | |
} |