In Microsoft Excel, it is pretty easy to export an Excel range as an image with the following procedure.
- Select a section that you need to export as an image.
- Click Home>Copy>Copy as Picture, then the picture will be saved in the clipboard.
- Paste the copied picture to your Paint tool, then save the picture to the specified folder in the specified format.
However, in this article, I'll introduce you top how to convert section(s) to an image programmatically using the free Spire.XLS in C#. As a matter of fact, Spire.XLS has provided a Worksheet.SaveToImage(int firstRow, int firstColumn, int lastRow, int lastColumn) method for programmers to save a selected range of cells to an image easily. Now let's check the detailed procedure as in the following.
Main procedure
Step 1: Create a new Excel document and load the test file.
Step 2: Get the first sheet from the workbook.
Step 3: Save a specific cell's range to an image via Worksheet.SaveToImage().
Test File
Entire Code
-
- Workbook workbook = new Workbook();
-
- workbook.LoadFromFile(“Sample.xlsx”);
-
- Worksheet sheet = workbook.Worksheets[0];
-
- sheet.SaveToImage(1, 1, 6, 6).Save(“Image1.png”, ImageFormat.Png);
- sheet.SaveToImage(7, 1, 13, 6).Save(“Image2.jpeg”, ImageFormat.Jpeg);
- sheet.SaveToImage(14, 1, 19, 6).Save(“Image3.bmp”, ImageFormat.Bmp);
Output