تحويل ورقة عمل إلى صورة إزالة الفراغات حول البيانات
إزالة الفراغات حول البيانات
Aspose.Cells.Rendering.SheetRender API يحول ورقة عمل إلى ملف صورة مع أي سمات محددة، على سبيل المثال، تنسيق الصورة، الصفحات المقسمة، وما إلى ذلك. تدعم عدة صيغ للصور، بما في ذلك 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"); |