I am using following POI api to write on excel through java code
public static HSSFWorkbook sampleWorkbook = new HSSFWorkbook();
public static HSSFSheet sampleDataSheet = sampleWorkbook.createSheet("ABC");
It is creating a sheet in excel with name of ABC. That is ok
My Question is I need to add/create another sheet with name of “XYZ” in same workbook. How do I do that? As if I write something like this
public static HSSFSheet sampleDataSheet = sampleWorkbook.createSheet("XYZ");
it would override the first one(ABC)..
It will not override the first one, it will create a new sheet, but you need to assign it to a different variable:
Here’s the documentation: