تصدير مجموعة من الخلايا في ورقة عمل إلى صورة

Contents
[ ]

لأخذ صورة من النطاق، قم بتعيين منطقة الطباعة إلى النطاق المطلوب ثم قم بتعيين جميع الهوامش إلى 0. ثم قم بتعيين ImageOrPrintOptions.setOnePagePerSheet() إلى true.

الكود التالي يأخذ صورة من النطاق E8:H10. أدناه صورة للورقة العمل الأصلية المستخدمة في الكود. يمكنك تجربة الكود مع أي ورقة عمل.

الملف الداخلي

todo:image_alt_text

تنفيذ الكود ينشئ صورة من النطاق E8:H10 فقط.

صورة الناتج

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ExportRangeofCells.class) + "TechnicalArticles/";
// Create workbook from source file.
Workbook workbook = new Workbook(dataDir + "book1.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Set the print area with your desired range
worksheet.getPageSetup().setPrintArea("E8:H10");
// Set all margins as 0
worksheet.getPageSetup().setLeftMargin(0);
worksheet.getPageSetup().setRightMargin(0);
worksheet.getPageSetup().setTopMargin(0);
worksheet.getPageSetup().setBottomMargin(0);
// Set OnePagePerSheet option as true
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.setOnePagePerSheet(true);
options.setImageType(ImageType.JPEG);
// Take the image of your worksheet
SheetRender sr = new SheetRender(worksheet, options);
sr.toImage(0, dataDir + "ERangeofCells_out.jpg");

قد تجد أيضا المقالة تحويل ورقة العمل إلى تنسيقات صور مختلفة مفيدة.