Çalışma Sayfasını Görüntüye Dönüştürme ve Sayfa Başına Çalışma Sayfasını Görüntüye Dönüştürme

Aspose.Cells Kullanarak Çalışma Sayfasını Resim Dosyasına Dönüştürme

Bu makale, Aspose.Cells for Java API’sını kullanarak bir çalışma sayfasını resme dönüştürme yöntemini göstermektedir. API, SheetRender, ImageOrPrintOptions, WorkbookRender gibi birçok değerli sınıfı içerir. SheetRender sınıfı, çalışma sayfası için resimleri oluşturmak için kullanılır ve birçok aşırı yüklenmiş toImage yöntemi, herhangi bir özellik veya seçenek ayarlanmaksızın bir çalışma sayfasını doğrudan resim dosyalarına dönüştürebilir.

// 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(ConvertWorksheettoImageFile.class) + "TechnicalArticles/";
// Create a new Workbook object
// Open a template excel file
Workbook book = new Workbook(dataDir + "book1.xlsx");
// Get the first worksheet
Worksheet sheet = book.getWorksheets().get(0);
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Specify the image format
imgOptions.setImageType(ImageType.JPEG);
// Render the sheet with respect to specified image/print options
SheetRender render = new SheetRender(sheet, imgOptions);
// Render the image for the sheet
render.toImage(0, dataDir + "CWToImageFile.jpg");

Sonuç

Yukarıdaki kodu çalıştırdıktan sonra, Sheet1 adlı çalışma sayfası SheetImage.jpg adlı bir resim dosyasına dönüştürülür.

Çıktı JPG

todo:image_alt_text

Aspose.Cells Kullanarak Sayfa Sayfa Çalışma Sayfasını Resim Dosyasına Dönüştürme

Bu örnek, birkaç sayfası olan bir şablon çalışma kitabından bir çalışma sayfasını bir resim dosyasına dönüştürmek için Aspose.Cells’ı kullanmanın nasıl yapıldığını göstermektedir.

// 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(ConvertWorksheetToImageByPage.class) + "TechnicalArticles/";
// Create a new Workbook object
// Open a template excel file
Workbook book = new Workbook(dataDir + "ConvertWorksheetToImageByPage.xlsx");
// Get the first worksheet
Worksheet sheet = book.getWorksheets().get(0);
// Define ImageOrPrintOptions
ImageOrPrintOptions options = new ImageOrPrintOptions();
// Set Resolution
options.setHorizontalResolution(200);
options.setVerticalResolution(200);
options.setImageType(ImageType.TIFF);
// Sheet2Image by page conversion
SheetRender render = new SheetRender(sheet, options);
for (int j = 0; j < render.getPageCount(); j++) {
render.toImage(j, dataDir + sheet.getName() + " Page" + (j + 1) + ".tif");
}

Sonuç

Yukarıdaki kodu çalıştırdıktan sonra, Sheet1 adlı çalışma sayfası iki resim dosyasına dönüştürülür (her biri için bir adet) Sheet 1 Page 1.Tiff ve Sheet 1 Page 2.Tiff.

Oluşturulan resim dosyası (Sheet 1 Page 1.Tiff)

todo:image_alt_text

Oluşturulan resim dosyası (Sheet 1 Page 2.Tiff)

todo:image_alt_text

İlgili Makaleler

  • Farklı Resim Formatlarına Çalışsayısı Dönüştürme
  • Belirtilen Genişlik ve Yükseklikte Çalışsayısı veya Tabloyu Resme Dışa Aktarma