Elimine los espacios en blanco de los datos antes de representarlos en la imagen
Contents
[
Hide
]
A veces, necesita presentar imágenes de hojas de trabajo en aplicaciones o páginas web. Por ejemplo, es posible que deba insertar imágenes en un documento de Word, un archivo PDF, una presentación PowerPoint o algún otro documento. Básicamente, desea representar una hoja de trabajo como una imagen para que pueda pegarse en otras aplicaciones. Aspose.Cells Las API le permiten convertir Microsoft hojas de cálculo de Excel en imágenes.
ÉlHojaRenderizarclass es capaz de convertir una hoja de trabajo en un archivo de imagen con cualquier atributo especificado, por ejemplo, formato de imagen, hojas paginadas, etc. Se admiten varios formatos de imagen, incluidos BMP, GIF, JPG, TIFF y EMF.
Cuando utiliza la función de hoja a imagen, la imagen de salida tiene un espacio en blanco/en blanco, es decir, un borde, alrededor de forma predeterminada. Puedes eliminar esto. Establezca los márgenes de configuración de página superior, izquierda, inferior y derecha para la hoja de trabajo de origen en 0 y especifiqueImageOrPrintOptionsatributos en consecuencia.
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"); |