Entfernen Sie Leerzeichen aus den Daten, bevor Sie das Bild rendern
Contents
[
Hide
]
Manchmal müssen Sie Arbeitsblattbilder in Anwendungen oder Webseiten präsentieren. Beispielsweise müssen Sie möglicherweise Bilder in ein Word-Dokument, eine PDF-Datei, eine PowerPoint-Präsentation oder ein anderes Dokument einfügen. Grundsätzlich möchten Sie ein Arbeitsblatt als Bild rendern, damit es in andere Anwendungen eingefügt werden kann. Mit Aspose.Cells-APIs können Sie Microsoft-Excel-Arbeitsblätter in Bilder konvertieren.
DasSheetRender-Klasse kann ein Arbeitsblatt in eine Bilddatei mit beliebigen angegebenen Attributen konvertieren, z. B. Bildformat, paginierte Blätter usw. Mehrere Bildformate werden unterstützt, darunter BMP, GIF, JPG, TIFF und EMF.
Wenn Sie die Blatt-zu-Bild-Funktion verwenden, hat das Ausgabebild standardmäßig einen weißen/leeren Bereich, d. h. einen Rand. Sie können dies entfernen. Legen Sie die oberen, linken, unteren und rechten Seiteneinrichtungsränder für das Quellarbeitsblatt auf 0 fest und geben Sie sie anImageOrPrintOptionsAttribute entsprechend.
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(RemoveWhitespaceAroundData.class) + "TechnicalArticles/"; | |
// Instantiate a workbook | |
// Open the template file | |
Workbook book = new Workbook(dataDir + "book1.xlsx"); | |
// Get the first worksheet | |
Worksheet sheet = book.getWorksheets().get(0); | |
// Specify your print area if you want | |
// sheet.PageSetup.PrintArea = "A1:H8"; | |
// To remove the white border around the image. | |
sheet.getPageSetup().setLeftMargin(0); | |
sheet.getPageSetup().setRightMargin(0); | |
sheet.getPageSetup().setTopMargin(0); | |
sheet.getPageSetup().setBottomMargin(0); | |
// Define ImageOrPrintOptions | |
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); | |
imgOptions.setImageType(ImageType.EMF); | |
// Set only one page would be rendered for the image | |
imgOptions.setOnePagePerSheet(true); | |
imgOptions.setPrintingPage(PrintingPageType.IGNORE_BLANK); | |
// Create the SheetRender object based on the sheet with its | |
// ImageOrPrintOptions attributes | |
SheetRender render = new SheetRender(sheet, imgOptions); | |
// Convert the image | |
render.toImage(0, dataDir + "RWhitespaceAroundData_out.emf"); |