Read Excel files with Java

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 […]

by Todor Gigilev

June 6, 2013

1 min read

1 - Read Excel files with Java

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:

[java]
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();

}
[/java]

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

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.