Konvertera kalkylblad till bild Ta bort mellanrum runt data

Ta bort mellanrum runt data

Aspose.Cells.Rendering.SheetRender-API:en konverterar ett kalkylblad till en bildfil med vilka attribut som helst, till exempel bildformat, sidade kalkylblad, osv. Flera bildformat stöds, inklusive BMP, GIF, JPG, TIFF och EMF.

När du använder funktionen ark-till-bild har den resulterande bilden ett mellanrum, det vill säga en ram, runt den som standard. Du kan ta bort detta genom att ställa in de översta, understa, vänstra och högra sidmarginalerna för källkalkylbladet till 0 och ange Aspose.Cells.Rendering.ImageOrPrintOptions-attribut därefter.

Följande kodsippa tar bort mellanrummet runt datan i den resulterande bilden.

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