JAVA容易读取EXCEL文件内容
JAVA简单读取EXCEL文件内容
java 代码
- import jxl.Cell;
- import jxl.Sheet;
- import jxl.Workbook;
- import jxl.read.biff.BiffException;
jxl 包
java 代码
- InputStream is;
- try {
- is = new FileInputStream(filePath + fileName);
- Workbook rwb = Workbook.getWorkbook(is);
- Sheet st = rwb.getSheet("Sheet1");
- int columns = st.getColumns(); // 列
- int rows = st.getRows(); // 行
- // -- 数据读取循环从行定位,单元格读取参数从列开始定位
- for(int i=1;i// 不查找表头第一行
- for(int j=0;j
- Cell coo = st.getCell(j,i); // 列,行 // 单元格先定位列,再定位行
- String strc = coo.getContents(); // 读出内容默认为字符串
- System.out.println(strc);
- }
- }
- rwb.close();
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (BiffException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
如果单元格内容有计算公式的话,读出的内容是计算后的显示内容。
1 楼
dylan_cherie
2007-02-28
晕啊,代码贴完预览还没事呢,怎么就少了一块。
for(int i=1;i<rows;i++) {
for(int j=0;j<columns;j++) {
for(int i=1;i<rows;i++) {
for(int j=0;j<columns;j++) {