jxl导入excel

jxl读取excel和写excel基本类似,只是WritableWorkbook换成了Workbook; WritableSheet换成了 Sheet ;Label 换成了Cell。

import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadExcel {
 public static void main(String[] args) {
  try {  
            //选取指定的excel  
            Workbook workbook = Workbook.getWorkbook(new File("F:\\test.xls"));  
            //选取制定的sheet  
            Sheet sheet = workbook.getSheet(0);  
            //选取指定的cell  
            //遍历循环得到所要的cell值  
            for(int j = 0 ;j<sheet.getRows() ; j++)  
                    for(int i = 0 ;i<sheet.getColumns();i++){  
            Cell cell = sheet.getCell(i,j);  
            //获取该cell的值  
            String var1 = cell.getContents();  
            //打印输出该值  
            System.out.println(var1);  
            }  
    } catch (BiffException e) {  
            e.printStackTrace();  
    } catch (IOException e) {  
            e.printStackTrace();  
    }  
  }
 }

 

你可能感兴趣的:(Excel)