EXCEL怎么取每一列的值

hunluandiaoling 2009-06-19 09:41:04
JXL中用Cell容器可以将每一列的值取出来么,怎么取,高手们指导下!
...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
一洽客服系统 2009-06-19
  • 打赏
  • 举报
回复
把这列所有的cell的值挨个取吧 一下取一列 我还没见过
rsmove 2009-06-19
  • 打赏
  • 举报
回复

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");
}
}

记得给分啊

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧