تحويل ورقة العمل إلى صورة - إزالة المسافة البيضاء حول البيانات
Contents
[
Hide
]
في بعض الأحيان ، تحتاج إلى تقديم صور ورقة العمل في التطبيقات أو صفحات الويب. على سبيل المثال ، قد تحتاج إلى إدراج صور في مستند Word أو ملف PDF أو عرض تقديمي PowerPoint أو مستند آخر. بشكل أساسي ، تريد عرض ورقة العمل كصورة بحيث يمكن لصقها في تطبيقات أخرى. Aspose.Cells يسمح لك بتحويل أوراق عمل Microsoft Excel إلى صور.
إزالة المسافة البيضاء حول البيانات
الAspose.Cells.Rendering.SheetRenderAPI يحول ورقة العمل إلى ملف صورة مع أي سمات محددة ، على سبيل المثال ، تنسيق الصورة ، والأوراق المرقمة ، إلخ. يتم دعم العديد من تنسيقات الصور ، بما في ذلك BMP ، GIF ، JPG ، TIFF ، و EMF.
عند استخدام ميزة من ورقة إلى صورة ، يكون للصورة الناتجة مسافة بيضاء ، أي حد ، حولها بشكل افتراضي. يمكنك إزالة هذا عن طريق تعيين هوامش إعداد الصفحة العلوية والسفلية واليسرى واليمنى لورقة العمل المصدر على 0 وتحديدهاAspose.Cells.Rendering.ImageOrPrintOptionsالسمات وفقًا لذلك.
يزيل مقتطف الشفرة التالي المسافة البيضاء حول البيانات في صورة الإخراج.
This file contains hidden or 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 | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Open the template file | |
Workbook book = new Workbook(sourceDir + "Book1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.Worksheets[0]; | |
LoadOptions options = new LoadOptions(); | |
options.LoadFilter = new LoadFilter(LoadDataFilterOptions.All); | |
// Specify your print area if you want | |
// Sheet.PageSetup.PrintArea = "A1:H8"; | |
// To remove the white border around the image. | |
sheet.PageSetup.LeftMargin = 0; | |
sheet.PageSetup.RightMargin = 0; | |
sheet.PageSetup.BottomMargin = 0; | |
sheet.PageSetup.TopMargin = 0; | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
imgOptions.ImageType = Drawing.ImageType.Emf; | |
// Set only one page would be rendered for the image | |
imgOptions.OnePagePerSheet = true; | |
imgOptions.PrintingPage = PrintingPageType.IgnoreBlank; | |
// Create the SheetRender object based on the sheet with its | |
// ImageOrPrintOptions attributes | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
// Convert the image | |
sr.ToImage(0, outputDir + "outputRemoveWhitespaceAroundData.emf"); |