POI读取Excel带格式数据

package com.hs.tiger.application;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;

public class ParseValidator {
public static void main(String[] args) throws Exception {
InputStream inp = new FileInputStream(
"E:\\JEE\\Workspaces\\MyEclipse 8.6\\Mirror\\src\\com\\hs\\tiger\\application\\Numeric.xls");
HSSFWorkbook wb = new HSSFWorkbook(inp);
HSSFSheet sheet = wb.getSheetAt(0);
try
{
for (int i = 0; i <= sheet.getLastRowNum(); i++) {
Cell c = sheet.getRow(i).getCell(0);

//System.out.println(c.getCellType());

//c.setCellType(Cell.CELL_TYPE_STRING);
System.out.println(c.getCellStyle().getDataFormatString());
try{
System.out.println(c.getStringCellValue());
}
catch (Exception e) {
try
{
System.out.println(c.getNumericCellValue());
}
catch (Exception ex) {
// TODO: handle exception
}
}

}
}
catch (Exception e) {
// TODO: handle exception
}

/*
* for (Iterator<org.apache.poi.ss.usermodel.Row> rit =
* sheet.rowIterator(); rit.hasNext(); ) { row = rit.next(); for
* (Iterator<Cell> cit = row.cellIterator(); cit.hasNext(); ) { cell =
* cit.next(); System.out.println(cell.getBooleanCellValue()); } }
*/

}
}


使用poi读取excel内容的问题:
例如excel中cell中显示值为20,100,612.00,实际值为20100612,
使用getNumbericCellValue()读取的的实际值,
是否有函数能读取cell的显示值,求大侠指教!


显示值20,100,612.00只是格式化了而已
你读取之后再用JAVA格式化一次就行了
DecimalFormat df=(DecimalFormat)NumberFormat.getInstance();
df.applyPattern("###,###.00");
System.out.println(df.format(new Integer("20100612")));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值