Hi Friends!
I thing this code is usefull for you. I try the jax and it seems to easy to use. I created an excel file with a coloumn header, a row header, a row summary and a coloumn summary line. So ... For example:
test.xls contains that above:
B1 C1 D1 E1 SC
A2 1 1 1 1
A3 1 1 1 1
A3 1 1 1 1
A4 1 1 1 1
SR
My program summarizes the values.
The output will be:
Rows: 6
Cols: 6
Result: 16
-------------------------------------
import java.io.*;
import java.util.Date;
import jxl.*;
public class ImportXLS {
public static void main(String args[]) {
Workbook workbook;
File file;
Cell cel;
String str = "";
long lngSumm;
String strXLSFilename = "d:\\java\\programs\\test.xls";
System.out.println("filename: " + strXLSFilename);
try {
file = new File(strXLSFilename);
workbook = Workbook.getWorkbook(file);
Sheet sheet = workbook.getSheet(0);
lngSumm = 0;
System.out.println("columns:" + sheet.getColumns());
System.out.println("rows: " + sheet.getRows());
for (int a = 1; a < sheet.getColumns()-1; a++) {
for (int b = 1; b < sheet.getRows()-1; b++) {
cel = sheet.getCell(a,b);
str = cel.getContents();
try {
lngSumm += Double.valueOf(str).doubleValue();
} catch (Exception e) {
System.err.println("Error: " + e);
}
}
}
System.out.println("result: " + lngSumm);
workbook.close();
} catch (IOException e) {
System.err.print("I/O error.");
System.exit(0);
} catch (jxl.read.biff.BiffException e) {
System.err.print("Corrupt file or an another program use the XLS.");
System.exit(0);
}
}
}