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

混江龙づ霸主 提交于 2019-12-23 05:26:42

问题


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.


回答1:


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/




回答2:


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();

   }
}



回答3:


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



来源:https://stackoverflow.com/questions/12120582/how-to-parse-a-xls-file-known-languages-python-java-lua

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!