【发布时间】:2015-03-20 00:43:53
【问题描述】:
我正在尝试将 Excel 文档的多个工作表的值添加到 ArrayList。不使用 HSSFSheet。这似乎更简单。小心不要忘记将字符串类型更改为数字。
public void setinputfile(String inputfile) {
this.inputfile = inputfile;}
public void read() throws IOException {
File inputWorkbook = new File(inputfile);
try {
Workbook w = Workbook.getWorkbook(inputWorkbook);
int Num = w.getNumberOfSheets();
for (int i = 0; i < Num; i++) {
Sheet sheet = w.getSheet(i);
Sheet s = w.getSheet(i);
int row = s.getRows();
int col = s.getColumns();
for (int i1 = 0; i1 < row; i1++) {
inner = new ArrayList<Double>();
for (int j = 0; j < col; j++) {
Cell c = s.getCell(j, i1);
CellType type = c.getType();
System.out.println(c.getContents());
String text = c.getContents(); // example String
double value = Double.parseDouble(text);
inner.add(value);
}
Kargo_Amount.add(inner);
}
}
} catch (BiffException e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
Facility_Location test = new Facility_Location();
test.setinputfile("C:\\Users\\soheyl\\Desktop\\Kargo miktarii.xls");
test.read();
}
【问题讨论】:
标签: java spreadsheet import-from-excel