إنشاء صورة مصغرة لورقة العمل
Contents
[
Hide
]
يمكن أن يكون من المفيد إنشاء صور مصغرة من ورقة العمل. الصورة المصغرة هي صورة صغيرة يمكن لصقها في مستند Word أو عرض تقديمي بوربوينت لإعطاء معاينة لمحتوى ورقة العمل. يمكن إضافتها إلى صفحة الويب مع رابط لتنزيل الوثيقة الأصلية ولها العديد من الاستخدامات الأخرى.
يتيح لك Aspose.Cells for Java إخراج الأوراق العمل إلى ملفات صور، لذلك فإن إنشاء صورة مصغرة سهل.
يوضح الكود النموذجي أدناه كيفية القيام بذلك، خطوة بخطوة.
This file contains 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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(GenerateThumbnailofWorksheet.class) + "TechnicalArticles/"; | |
// Instantiate and open an Excel file | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
// Set the vertical and horizontal resolution | |
imgOptions.setVerticalResolution(200); | |
imgOptions.setHorizontalResolution(200); | |
// Set the image's format | |
imgOptions.setImageType(ImageType.JPEG); | |
// One page per sheet is enabled | |
imgOptions.setOnePagePerSheet(true); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Render the sheet with respect to specified image/print options | |
SheetRender sr = new SheetRender(sheet, imgOptions); | |
// Render the image for the sheet | |
sr.toImage(0, dataDir + "mythumb.jpg"); | |
// Creating Thumbnail | |
java.awt.Image img = ImageIO.read(new File(dataDir + "mythumb.jpg")).getScaledInstance(100, 100, BufferedImage.SCALE_SMOOTH); | |
BufferedImage img1 = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); | |
img1.createGraphics().drawImage( | |
ImageIO.read(new File(dataDir + "mythumb.jpg")).getScaledInstance(100, 100, img.SCALE_SMOOTH), 0, 0, null); | |
ImageIO.write(img1, "jpg", new File(dataDir + "GTOfWorksheet_out.jpg")); |