قم بإنشاء صورة مصغرة لورقة العمل
Contents
[
Hide
]
قد يكون من المفيد إنشاء صور مصغرة من أوراق العمل. الصورة المصغرة هي صورة صغيرة يمكن لصقها في مستند Word أو عرض تقديمي PowerPoint لإعطاء معاينة لما هو موجود في ورقة العمل. يمكن إضافته إلى صفحة ويب بها ارتباط لتنزيل المستند الأصلي وله مجموعة من الاستخدامات الأخرى.
يسمح لك Aspose.Cells for .NET بإخراج أوراق العمل إلى ملفات الصور بحيث يكون إنشاء صورة مصغرة أمرًا سهلاً. يوضح لك نموذج التعليمات البرمجية أدناه ، كيفية إخراج أوراق العمل إلى ملفات الصور.
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(); | |
// Instantiate and open an Excel file | |
Workbook book = new Workbook(sourceDir + "sampleGenerateThumbnailOfWorksheet.xlsx"); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Specify the image format | |
imgOptions.ImageType = Drawing.ImageType.Jpeg; | |
// Set the vertical and horizontal resolution | |
imgOptions.VerticalResolution = 200; | |
imgOptions.HorizontalResolution = 200; | |
// One page per sheet is enabled | |
imgOptions.OnePagePerSheet = true; | |
// Get the first worksheet | |
Worksheet sheet = book.Worksheets[0]; | |
// Render the sheet with respect to specified image/print options | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
// Render the image for the sheet | |
Bitmap bmp = sr.ToImage(0); | |
// Create a bitmap | |
Bitmap thumb = new Bitmap(600, 600); | |
// Get the graphics for the bitmap | |
System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(thumb); | |
if (bmp != null) | |
{ | |
// Draw the image | |
gr.DrawImage(bmp, 0, 0, 600, 600); | |
} | |
// Save the thumbnail | |
thumb.Save(outputDir + "outputGenerateThumbnailOfWorksheet.bmp"); |