navigation

Read Excel files with Java

Read Excel files with Java

by
June 6, 2013

Recently I needed to parse simple Excel sheet to XML format.

Excel does support this operation, but as everything from MS, the process is very intuitive.

Firs you have to create XML Schema with the desired attributes. Then you must map these attributes to the Excel ones. Sounds simple but after 30 minutes clicking in the menus I decided to write a parser in Java myself .

Firs you must download JExcelApi from here.

The way this API is used is fairly simple:

File inputWorkbook = new File("Name_of_excel_file");

Workbook w;

try {

w = Workbook.getWorkbook(inputWorkbook);

Sheet sheet = w.getSheet(0);

for (int j = 0; j < sheet.getColumns(); j++) {

for (int i = 0; i < sheet.getRows(); i++) {

 Cell cell = sheet.getCell(j, i);

 System.out.print(cell.getContents()+ " ");

 //do xml parse job

}

System.out.println();

}

} catch (BiffException e) {

e.printStackTrace(); 

}

So next time you need something simple like that, first consider writing it yourself…

Todor Gigilev

Having entrepreneurial and business knowledge, I am eager to help innovative companies and startups to build their sales strategy and business model, improve their value proposition and design and develop their product. If you want a software project delivered, you can message me and I will make sure to do my best to propose the best solution. My main expertise is in the Oracle Fusion Middleware stack - I have been heavily involved in actual development, consulting and delivery of Webcenter, ADF, SOA Suite, BPM and Java EE solutions.

More Posts - Website

Follow Me:
TwitterLinkedInGoogle Plus

Do you want more great blogs like this?

Subscribe for Dreamix Blog now!