ImageOrPrintOptions kullanarak Çalışma Sayfasını ve Çalışma Kitabını Görüntüye Dönüştürün
genel bakış
Bazen, çalışma sayfalarınızı resimli bir sunum olarak sunmanız gerekebilir. Çalışma sayfası görüntülerini uygulamalarınıza veya web sayfalarınıza sunmanız gerekir. Görüntüleri bir Word belgesine, bir PDF dosyasına, bir PowerPoint sunumuna eklemeniz veya başka bir senaryoda kullanmanız gerekebilir. Basitçe, başka bir yerde kullanabilmeniz için bir çalışma sayfasının görüntü olarak işlenmesini istiyorsunuz. Aspose.Cells, Excel dosyalarındaki çalışma sayfalarının görüntülere dönüştürülmesini destekler. Ayrıca Aspose.Cells, görüntü formatı, çözünürlük (dikey ve yatay), görüntü kalitesi ve diğer görüntü ve baskı seçenekleri gibi farklı seçeneklerin ayarlanmasını destekler.
API, birkaç değerli sınıf sağlar, örneğin,SheetRender, ResimVeyaBaskıSeçenekleri, Çalışma KitabıRender, vb.
buSheetRender class, çalışma sayfası için görüntüleri işleme görevini üstlenirken,Çalışma KitabıRenderbir çalışma kitabı için aynısını yapar. Yukarıda bahsedilen sınıfların her ikisi de, birkaç aşırı yüklenmiş sürüme sahiptir.Hayal etmekbir çalışma sayfasını veya çalışma kitabını, istediğiniz nitelikler veya seçeneklerle belirtilen görüntü dosya(lar)ına doğrudan dönüştürebilen yöntem. Görüntü dosyasını diske/akışa kaydedebilirsiniz. BMP, PNG, GIFF, JPEG, TIFF, EMF gibi desteklenen birkaç görüntü formatı vardır.
Çalışma Sayfasını Resme Dönüştür
// 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(ConvertWorksheettoImage.class) + "TechnicalArticles/"; | |
//Instantiate a new Workbook object | |
//Open template | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
//Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
//Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
//Set Horizontal Resolution | |
options.setHorizontalResolution(300); | |
//Set Vertical Resolution | |
options.setVerticalResolution(300); | |
//Set TiffCompression | |
options.setTiffCompression(TiffCompression.COMPRESSION_LZW); | |
//Set Image Format | |
options.setImageType(ImageType.TIFF); | |
//Set printing page type | |
options.setPrintingPage(PrintingPageType.DEFAULT); | |
//Render the sheet with respect to specified image/print options | |
SheetRender sr = new SheetRender(sheet, options); | |
//Render/save the image for the sheet | |
sr.toImage(0, dataDir + "CWorksheettoImage_out.tiff"); |
Dönüşüm Seçenekleri
Görüntüye belirli sayfaları kaydetmek mümkündür. Aşağıdaki kod, bir çalışma kitabındaki birinci ve ikinci çalışma sayfalarını JPG resimlerine dönüştürür.
// 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(ConversionOptions.class) + "TechnicalArticles/"; | |
// Instantiate a new Workbook object | |
// Open template | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set Horizontal Resolution | |
options.setHorizontalResolution(300); | |
// Set Vertical Resolution | |
options.setVerticalResolution(300); | |
// Set Image Format | |
options.setImageType(ImageType.JPEG); | |
// If you want entire sheet as a single image | |
options.setOnePagePerSheet(true); | |
// Render the sheet with respect to specified image/print options | |
SheetRender sr = new SheetRender(sheet, options); | |
// Render/save the image for the sheet | |
sr.toImage(0, dataDir + "ConversionOptions_out.jpg"); |
Veya çalışma kitabında dolaşabilir ve içindeki her çalışma sayfasını ayrı bir görüntüye dönüştürebilirsiniz:
// 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(WorksheetToSeparateImage.class) + "TechnicalArticles/"; | |
// Instantiate a new Workbook object | |
// Open template | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Iterate over all worksheets in the workbook | |
for (int i = 0; i < book.getWorksheets().getCount(); i++) { | |
Worksheet sheet = book.getWorksheets().get(i); | |
// Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set Horizontal Resolution | |
options.setHorizontalResolution(300); | |
// Set Vertical Resolution | |
options.setVerticalResolution(300); | |
// Set Image Format | |
options.setImageType(ImageType.JPEG); | |
// If you want entire sheet as a single image | |
options.setOnePagePerSheet(true); | |
// Render to image | |
SheetRender sr = new SheetRender(sheet, options); | |
sr.toImage(0, dataDir + "WSheetToSImage_out-" + sheet.getName() + ".jpg"); | |
} |
Çalışma Kitabını Görüntüye Dönüştür:
Tüm çalışma kitabını görüntü formatına dönüştürmek için yukarıdaki yaklaşımı kullanabilir veya basitçeÇalışma KitabıRender örneğini kabul eden sınıfÇalışma kitabı nesnesinin yanı sıraResimVeyaBaskıSeçenekleri.
// 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(ConvertWorkbooktoImage.class) + "TechnicalArticles/"; | |
// Instantiate a new Workbook object | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Apply different Image and Print options | |
ImageOrPrintOptions options = new ImageOrPrintOptions(); | |
// Set Image Format | |
options.setImageType(ImageType.TIFF); | |
// If you want entire sheet as a single image | |
options.setOnePagePerSheet(true); | |
// Render to image | |
WorkbookRender render = new WorkbookRender(book, options); | |
render.toImage(dataDir + "CWorkbooktoImage_out.tiff"); |