using Stream templateXlsStream = File.OpenRead("test.xlsx");
var wb = new Aspose.Cells.Workbook(templateXlsStream);
var sheet1 = wb.Worksheets[4];
// Set the print area with your desired range
sheet1.PageSetup.PrintArea = "H1:T22";
// Set all margins as 0 (optional), this will remove blank spaces around the image.
sheet1.PageSetup.LeftMargin = 0;
sheet1.PageSetup.RightMargin = 0;
sheet1.PageSetup.TopMargin = 0;
sheet1.PageSetup.BottomMargin = 0;
var render = new SheetRender(sheet1, new ImageOrPrintOptions
{
ImageType = Aspose.Cells.Drawing.ImageType.Jpeg,
OnePagePerSheet = true,
});
render.ToImage(0, "jpg".GetPathByExt());