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

سيناريوهات الاستخدام الممكنة

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

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

لالتقاط صورة لنطاق ، اضبط منطقة الطباعة على النطاق المطلوب ثم اضبط جميع الهوامش على 0. قم أيضًا بتعيينImageOrPrintOptions.OnePagePerSheet إلىحقيقي . يأخذ الكود التالي صورة للنطاق D8: G16. يوجد أدناه لقطة شاشة لـنموذج لملف Excel المستخدمة في الكود. يمكنك تجربة الكود مع أي ملف Excel.

لقطة شاشة لملف Excel ونسخته المصدرة

! [todo: image_alt_text] (export-range-of-cells-in-a-workheet-to-image_1.png)

يؤدي تنفيذ الكود إلى إنشاء صورة للنطاق D8: G16 فقط.

[todo: image_alt_text] (Output-Image.png)

عينة من الرموز

// 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();
// Create workbook from source file.
Workbook workbook = new Workbook(sourceDir + "sampleExportRangeOfCellsInWorksheetToImage.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Set the print area with your desired range
worksheet.PageSetup.PrintArea = "D8:G16";
// Set all margins as 0
worksheet.PageSetup.LeftMargin = 0;
worksheet.PageSetup.RightMargin = 0;
worksheet.PageSetup.TopMargin = 0;
worksheet.PageSetup.BottomMargin = 0;
// Set OnePagePerSheet option as true
ImageOrPrintOptions options = new ImageOrPrintOptions();
options.OnePagePerSheet = true;
options.ImageType = ImageType.Jpeg;
options.HorizontalResolution = 200;
options.VerticalResolution = 200;
// Take the image of your worksheet
SheetRender sr = new SheetRender(worksheet, options);
sr.ToImage(0, outputDir + "outputExportRangeOfCellsInWorksheetToImage.jpg");