Created
January 24, 2025 21:04
-
-
Save conholdate-gists/3f5e15090b39ba9319709dc35a1044b6 to your computer and use it in GitHub Desktop.
Convert Excel XLSX to JPG or PNG Image in C#
This file contains hidden or 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
// 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"); | |
} |
This file contains hidden or 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
// 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