تحويل ورقة العمل إلى صورة - إزالة المسافة البيضاء حول البيانات

إزالة المسافة البيضاء حول البيانات

الAspose.Cells.Rendering.SheetRenderAPI يحول ورقة العمل إلى ملف صورة مع أي سمات محددة ، على سبيل المثال ، تنسيق الصورة ، والأوراق المرقمة ، إلخ. يتم دعم العديد من تنسيقات الصور ، بما في ذلك BMP ، GIF ، JPG ، TIFF ، و EMF.

عند استخدام ميزة من ورقة إلى صورة ، يكون للصورة الناتجة مسافة بيضاء ، أي حد ، حولها بشكل افتراضي. يمكنك إزالة هذا عن طريق تعيين هوامش إعداد الصفحة العلوية والسفلية واليسرى واليمنى لورقة العمل المصدر على 0 وتحديدهاAspose.Cells.Rendering.ImageOrPrintOptionsالسمات وفقًا لذلك.

يزيل مقتطف الشفرة التالي المسافة البيضاء حول البيانات في صورة الإخراج.

// 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");