Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Created January 24, 2025 21:04
Show Gist options
  • Save conholdate-gists/3f5e15090b39ba9319709dc35a1044b6 to your computer and use it in GitHub Desktop.
Save conholdate-gists/3f5e15090b39ba9319709dc35a1044b6 to your computer and use it in GitHub Desktop.
Convert Excel XLSX to JPG or PNG Image in C#
// Load Excel file
Workbook book = new Workbook("input.xlsx");
// Get the reference of the desired worksheet
Worksheet sheet = book.Worksheets[0];
// Set image options
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
options.HorizontalResolution = 200;
options.VerticalResolution = 200;
options.ImageType = Aspose.Cells.Drawing.ImageType.Jpeg;
// Convert sheet to JPG image
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, options);
for (int j = 0; j < sr.PageCount; j++)
{
sr.ToImage(j, "excel-to-jpg" + (j + 1) + ".jpg");
}
// Load Excel file
Workbook book = new Workbook("input.xlsx");
// Get the reference of the desired worksheet
Worksheet sheet = book.Worksheets[0];
// Set image options
Aspose.Cells.Rendering.ImageOrPrintOptions options = new Aspose.Cells.Rendering.ImageOrPrintOptions();
options.HorizontalResolution = 200;
options.VerticalResolution = 200;
options.ImageType = Aspose.Cells.Drawing.ImageType.Png;
// Convert sheet to PNG image
Aspose.Cells.Rendering.SheetRender sr = new Aspose.Cells.Rendering.SheetRender(sheet, options);
for (int j = 0; j < sr.PageCount; j++)
{
sr.ToImage(j, "excel-to-png" + (j + 1) + ".png");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment