Set Dpi when Converting Excel to Image in Java

This article demonstrates how to set dpi on x and y axis when converting an Excel worksheet to an image using Spire.XLS for Java.

import com.spire.xls.*;

public class ConvertExcelToImage {

    public static void main(String[] args) {

        //Create a Workbook object
        Workbook wb = new Workbook();

        //Load an Excel file
        wb.loadFromFile("C:\\Users\\Administrator\\Desktop\\data.xlsx");

        //Set dpi on x and y axis
        wb.getConverterSetting().setXDpi(300);
        wb.getConverterSetting().setYDpi(300);

        //Declare a Worksheet variable
        Worksheet sheet;

        //Loop through the worksheets 
        for (int i = 0; i < wb.getWorksheets().size(); i++) {

            //Get the specific worksheet
            sheet = wb.getWorksheets().get(i);
            
            //Convert worksheet to image 
            sheet.saveToImage("C:\\Users\\Administrator\\Desktop\\Output\\image-" + i + ".png");
        }
    }
}

Set Dpi when Converting Excel to Image in Java