Figen Güngör
Figen Güngör

Reputation: 12559

How to parse a xls file? (Known languages : Python, Java, Lua)

I am trying to parse this xls file:

http://web.iyte.edu.tr/sks/xls/Agustos_Menu_2012.xls

Orange places have date and belove those dates there are food list of that day. So can you please suggest me a way to parse that to get dates and foods? I tried to convert that xls to comma seperated value but some characters are changing and i don't know how to get dates and foods into an array or a file in an organized way in order to use later.Thanks.

Upvotes: 0

Views: 919

Answers (3)

java_xof
java_xof

Reputation: 439

For Java language try using API provided by grimholtz and lamber45 -> sourceforge project jexcelapi

The example will be based on the file which contains no. in col B in rows 1(header)-4 To read xls file first import libraries

import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.read.biff.BiffException;
import jxl.Workbook;

Rest of the code will be in main() method

public class ReadXLS {
   public static void main(String[] args) throws IOException, BiffException {
   Workbook spreadsheet = Workbook.getWorkbook(new File("example.xls"));
   Sheet myspreadsheet = spreadsheet.getSheet(0); //numbers of spreadsheet starts from 0
   Cell mycell = myspreadsheet.getCell(1, 0);
   String header = mycell.getContents();
   System.out.println(header);
   for(int i=1; i<4; i++){
     mycell = myspreadsheet.getCell(1, i);
     System.out.println(mycell.getContents());
     }
   spreadsheet.close();

   }
}

Upvotes: 1

Miljen Mikic
Miljen Mikic

Reputation: 15251

Java: use JExcel API to parse specified document. Here you can find instructions how to use it, focus on Reading spreadsheets section.

Upvotes: 0

Peter
Peter

Reputation: 5884

Probably the simplest and best option is using the Apache POI - the Java API for Microsoft Documents. It can be found here: http://poi.apache.org/

Upvotes: 1

Related Questions