Convertir hoja de cálculo a imagen Eliminar espacios en blanco alrededor de los datos

Eliminar espacios en blanco alrededor de los datos

El API Aspose.Cells.Rendering.SheetRender convierte una hoja de cálculo en un archivo de imagen con atributos especificados, por ejemplo, formato de imagen, hojas paginadas, etc. Se admiten varios formatos de imagen, incluyendo BMP, GIF, JPG, TIFF y EMF.

Cuando utilizas la función de hoja a imagen, la imagen de salida tiene espacios en blanco, es decir, un borde, alrededor de ella de forma predeterminada. Puedes eliminar esto configurando los márgenes de configuración de página superior, inferior, izquierda y derecha de la hoja de origen en 0 y especificar los atributos Aspose.Cells.Rendering.ImageOrPrintOptions en consecuencia.

El siguiente fragmento de código elimina los espacios en blanco alrededor de los datos en la imagen de salida.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Source directory
string sourceDir = RunExamples.Get_SourceDirectory();
//Output directory
string outputDir = RunExamples.Get_OutputDirectory();
// Open the template file
Workbook book = new Workbook(sourceDir + "Book1.xlsx");
// Get the first worksheet
Worksheet sheet = book.Worksheets[0];
LoadOptions options = new LoadOptions();
options.LoadFilter = new LoadFilter(LoadDataFilterOptions.All);
// Specify your print area if you want
// Sheet.PageSetup.PrintArea = "A1:H8";
// To remove the white border around the image.
sheet.PageSetup.LeftMargin = 0;
sheet.PageSetup.RightMargin = 0;
sheet.PageSetup.BottomMargin = 0;
sheet.PageSetup.TopMargin = 0;
// Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageType = Drawing.ImageType.Emf;
// Set only one page would be rendered for the image
imgOptions.OnePagePerSheet = true;
imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;
// Create the SheetRender object based on the sheet with its
// ImageOrPrintOptions attributes
SheetRender sr = new SheetRender(sheet, imgOptions);
// Convert the image
sr.ToImage(0, outputDir + "outputRemoveWhitespaceAroundData.emf");