Supprimer les espaces blancs des données avant le rendu à l'image

Contents
[ ]

LeFeuilleRenduest capable de convertir une feuille de calcul en un fichier image avec tous les attributs spécifiés, par exemple, format d’image, feuilles paginées, etc. Plusieurs formats d’image sont pris en charge, notamment BMP, GIF, JPG, TIFF et EMF.

Lorsque vous utilisez la fonction feuille à image, l’image de sortie comporte un espace blanc/vide, c’est-à-dire une bordure, autour d’elle par défaut. Vous pouvez supprimer ceci. Définissez les marges de mise en page supérieure, gauche, inférieure et droite de la feuille de calcul source sur 0 et spécifiezOptions d’image ou d’impressionattributs en conséquence.

// 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");