Rimuovi gli spazi bianchi dai dati prima del rendering nell'immagine
Contents
[
Hide
]
A volte, è necessario presentare immagini del foglio di lavoro in applicazioni o pagine Web. Ad esempio, potrebbe essere necessario inserire un’immagine in un documento Word, un file PDF, una presentazione PowerPoint o qualche altro documento. Fondamentalmente, vuoi rendere un foglio di lavoro come un’immagine in modo che possa essere incollato in altre applicazioni. Le API Aspose.Cells consentono di convertire i fogli di lavoro Excel Microsoft in immagini.
IlFoglioRenderingclass è in grado di convertire un foglio di lavoro in un file immagine con qualsiasi attributo specificato, ad esempio formato immagine, fogli impaginati, ecc. Sono supportati diversi formati immagine, inclusi BMP, GIF, JPG, TIFF e EMF.
Quando si utilizza la funzione da foglio a immagine, l’immagine di output presenta uno spazio bianco/vuoto, ovvero un bordo, attorno ad essa per impostazione predefinita. Puoi rimuoverlo. Impostare i margini di impostazione della pagina superiore, sinistro, inferiore e destro per il foglio di lavoro di origine su 0 e specificareImageOrPrintOptionsattributi di conseguenza.
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"); |