Excel Operations using Java

Excel Operations :

 

We can create excel by using different jars.
But , I will prefer "Apache POI" .It has it's own features compared to other technologies for generating excel workbook.

For generating excel sheet ,I used Apache POI latest version (version 3.11) .

Apache POI jars are downloaded from following site 



But , I am using following structure for excel operations




 Now,we will start Excel operations.


Creating Excel Workbook:

 

             Following four lines are used for creating excel work book

 
  

when we run the above code excel workbook created .But when we open excel workbook , we will get the following error .



 We got this error , because we are not creating sheet .Excel workbook should have excel sheet.

Creating Excel Sheet:

 

So,for rectifying above issue now we will create sheet .For creating sheet we wi use the following line of code
       
            // Creating Sheet
           Sheet sheet =  wb.createSheet("Learn Differently");





Now , Sheet will be created and excel also opening fine.

 



Creating Row and Cells:

 

 Now for creating row and writing data into cell  , we will use following code.

        // Creating a row (Rows are starting from index 0 ).
            Row row = sheet.createRow(1);
           
            // Create a cell and put a value in it.
            Cell cell = row.createCell(1);
            cell.setCellValue(4);



 Now , sheet will be created with the data.



Now , start to create excel workbooks using Apache POI .Happy coding :)

0 Response to "Excel Operations using Java"

Post a Comment