jxl读取Excel

zhq10124 2009-10-31 10:16:09
代码:

import java.io.*;
import java.util.*;
import jxl.*;
import jxl.read.biff.BiffException;

public class ReadExcel{

public static void main(String[] args) {
try {
Workbook book = Workbook.getWorkbook(new File("1.xls"));
Sheet sheet = book.getSheet(0);
System.out.println("请输入要读取的单元格");
Scanner in = new Scanner(System.in);
int x = in.nextInt();
in = new Scanner(System.in);
int y = in.nextInt();

Cell cell1 = sheet.getCell(x,y);
if (cell1.getType() == CellType.NUMBER) {
NumberCell nc = (NumberCell) cell1;
System.out.println("value : " + nc.getValue());
System.out.println("type : " + cell1.getType());
System.out.println("Format : " + cell1.getCellFormat());
System.out.println("NumberFormat: " + nc.getNumberFormat());
System.out.println("Font" + cell1.getCellFeatures());
System.out.println("Colum "+ cell1.getColumn());
System.out.println("Class "+ nc.getClass());
System.out.println("");
}

else {
System.out.println("Cell(x, y)" + " value : " + cell1.getContents()
+ "; type : " + cell1.getType()+"Format"+cell1.getCellFormat() );
}

book.close();
} catch (BiffException e) {
// TODO 自动生成 catch 块
System.out.println(e);
} catch (IOException e) {
// TODO 自动生成 catch 块
System.out.println(e);;
}


}
}

输出:

请输入要读取的单元格
3
3
value : 67.0
type : Number
Format : jxl.biff.XFRecord@1ac33c92
NumberFormat: java.text.DecimalFormat@7d1f1
Fontnull
Colum 3
Class class jxl.read.biff.NumberValue



问题:

为什么Format : jxl.biff.XFRecord@1ac33c92
NumberFormat: java.text.DecimalFormat@7d1f1
这两个怎么输出这些啊?是什么?
...全文
68 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
kdjqssl 2009-10-31
  • 打赏
  • 举报
回复
Format ,NumberFormat都是对象,当print对象时,如果对象没有重载toString()方法,就会调用Object的

public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}

所以就会形成上面那样的输出

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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