EXCEL怎么取每一列的值
JXL中用Cell容器可以将每一列的值取出来么,怎么取,高手们指导下!
------解决方案--------------------
public class ReadXLS{
private static final String ENCODE_WHEN_READING = "GBK";
public String getXlsValue(String path){
DBCon con = new DBCon();
Workbook workbook = null;
String strValueAt = "";
String stralueIm = "";
String strValueInfo ="";
String strValueInfoImage="";
workbook = Workbook.getWorkbook(new File(path));
Sheet sheet = workbook.getSheet(0);
Cell cell = null;
// int columnCount=1;
int rowCount=sheet.getRows();
//读取xls文件,第一列,标题
for (int i = 0; i < rowCount; i++) {
for (int j = 0; j <1; j++) {
//注意,这里的两个参数,第一个是表示列的,第二才表示行
cell=sheet.getCell(j, i);
//要根据单元格的类型分别做处理,否则格式化过的内容可能会不正确
if(cell.getType()==CellType.NUMBER){
NumberCell nc=(NumberCell)cell;
stralueIm = ""+nc.getValue();
// System.out.print(stralueIm);
}
else if(cell.getType()==CellType.DATE){
DateCell dc = (DateCell)cell;
// stralueIm = ""+dc.getContents();
// System.out.println("the stralueIm is value:____"+stralueIm);
}
else{
try {
String temp = cell.getContents().trim();
stralueIm = new String(temp.getBytes(),ENCODE_WHEN_READING).trim();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.print("\t");
}
System.out.print("\n");
}
//关闭
con.close();
workbook.close();
return strValueAt;
}
public static void main(String args[]) throws
IOException{
ReadXLS xls = new ReadXLS();
xls.getXlsValue("D:\\test\\ChinaBusinessNews20090113\\TestRead.xls");
}
}
记得给分啊