Ç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
Bu belge, geliştiricilere bir çalışma sayfasını bir görüntü dosyasına nasıl dönüştürecekleri ve bir çalışma sayfasının birden fazla sayfasının nasıl ayrı bir görüntü dosyasına dönüştürecekleri konusunda detaylı bir anlayış sağlamak üzere tasarlanmıştır.
Bazı durumlarda, çalışma sayfalarını örneğin, uygulamalarda veya web sayfalarında kullanmak için görüntü olarak sunmanız gerekebilir. Görüntüleri bir Word belgesine, bir PDF dosyasına, bir PowerPoint sunumuna yerleştirmeniz gerekebilir veya başka bir senaryoda kullanmanız gerekebilir. Basitçe, çalışma sayfasını bir resim olarak oluşturmak istersiniz. Aspose.Cells API’ları, Microsoft Excel dosyalarındaki çalışma sayfalarını görüntülere dönüştürmeyi destekler. Ayrıca, Aspose.Cells bir çalışma kitabını her sayfa için bir resim dosyasına dönüştürmeyi de destekler.
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
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)
Oluşturulan resim dosyası (Sheet 1 Page 2.Tiff)