Çalışma Sayfasını Farklı Görüntü Formatlarına Dönüştürme

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

Bazen, bir çalışma sayfasının resmini kaydetmek yararlıdır. Görüntüler çevrimiçi olarak paylaşılabilir, diğer belgelere eklenebilir (örneğin, Microsoft Word’de yazılan raporlar veya PowerPoint sunumları).

Aspose.Cells üzerinden görüntü aktarımı sağlar**SheetRender** sınıf. Bu sınıf, bir görüntüye dönüştürülecek çalışma sayfasını temsil eder. bu**SheetRender** sınıf sağlar**toImage()**çalışma sayfasını görüntü dosyasına dönüştürme yöntemi. BMP, PNG, JPEG, TIFF ve EMF biçimleri desteklenir.

Aşağıdaki kod, Microsoft Excel dosyasındaki bir çalışma sayfasının PNG dosyasına nasıl dönüştürüleceğini gösterir.

// 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(WorksheetToImage.class) + "LoadingSavingConvertingAndManaging/";
// Instantiate a new workbook with path to an Excel file
Workbook book = new Workbook(dataDir + "MyTestBook1.xlsx");
// Create an object for ImageOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Set the image type
imgOptions.setImageType(ImageType.PNG);
// Get the first worksheet.
Worksheet sheet = book.getWorksheets().get(0);
// Create a SheetRender object for the target sheet
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int j = 0; j < sr.getPageCount(); j++) {
// Generate an image for the worksheet
sr.toImage(j, dataDir + "WToImage-out" + j + ".png");
}

Çalışma Sayfasını SVG’e Dönüştürme

SVG şu anlama gelir:ölçeklendirilebilir Vektör GrafiğiSVG, iki boyutlu vektör grafikleri için XML standartlarına dayalı bir belirtimdir. World Wide Web Consortium (W3C) tarafından 1999’dan beri geliştirilmekte olan açık bir standarttır.

v7.1.0’ın piyasaya sürülmesinden bu yana,Aspose.Cells for Java çalışma sayfalarını SVG resimlere dönüştürebilir.

Bu özelliği kullanmak için com.aspose.cells ad alanını programınıza veya projenize aktarmanız gerekir. Oluşturma ve yazdırma için çeşitli değerli sınıflara sahiptir, örneğin,SheetRender, ImageOrPrintOptions, WorkbookRender, ve diğerleri.

bu**com.aspose.cells.ImageOrPrintOptions** class, çalışma sayfasının SVG biçiminde kaydedileceğini belirtir.

bu**SheetRender**sınıf nesnesini alır**ImageOrPrintOptions** kaydetme formatını SVG formatına ayarlayan bir parametre olarak.

Aşağıdaki kod parçacığı, bir Excel dosyasındaki bir çalışma sayfasının SVG resim dosyasına nasıl dönüştürüleceğini gösterir.

// 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(ConvertingWorksheetToSVG.class) + "loading_saving/";
String path = dataDir + "Book1.xlsx";
// Create a workbook object from the template file
Workbook workbook = new Workbook(path);
// Convert each worksheet into svg format in a single page.
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setSaveFormat(SaveFormat.SVG);
imgOptions.setOnePagePerSheet(true);
// Convert each worksheet into svg format
int sheetCount = workbook.getWorksheets().getCount();
for (int i = 0; i < sheetCount; i++) {
Worksheet sheet = workbook.getWorksheets().get(i);
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int k = 0; k < sr.getPageCount(); k++) {
// Output the worksheet into Svg image format
sr.toImage(k, path + sheet.getName() + k + "_out.svg");
}
}
// Print message
System.out.println("Excel to SVG conversion completed successfully.");

Aktif çalışma sayfasını bir çalışma kitabında işleyin

Bir çalışma kitabındaki etkin çalışma sayfasını dönüştürmenin basit bir yolu, etkin sayfa dizinini ayarlamak ve ardından çalışma kitabını SVG olarak kaydetmektir. Etkin sayfayı SVG olarak işler. Aşağıdaki örnek kod bu özelliği gösterir:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
String outputDir = Utils.Get_OutputDirectory();
// Instantiate a workbook
Workbook workbook = new Workbook();
// Put sample text in the first cell of first worksheet in the newly created workbook
workbook.getWorksheets().get(0).getCells().get("A1").setValue("DEMO TEXT ON SHEET1");
// Add second worksheet in the workbook
workbook.getWorksheets().add(SheetType.WORKSHEET);
// Set text in first cell of the second sheet
workbook.getWorksheets().get(1).getCells().get("A1").setValue("DEMO TEXT ON SHEET2");
// Set currently active sheet index to 1 i.e. Sheet2
workbook.getWorksheets().setActiveSheetIndex(1);
// Save workbook to SVG. It shall render the active sheet only to SVG
workbook.save(outputDir + "ConvertActiveWorksheetToSVG_out.svg");

İlgili Makaleler