package yuebao;import java.io.*;
import java.text.DateFormat;import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class CallRecord
{
public static void main(String[] args)
{
POIFSFileSystem pfs=null;
HSSFWorkbook hwb=null;
try
{
pfs=new POIFSFileSystem(new FileInputStream("07-06-28-07-07-27.xls"));
hwb=new HSSFWorkbook(pfs);
HSSFSheet sheet=hwb.getSheetAt(0);
System.out.println(sheet.getRow(4).getCell((short)1).toString());
HSSFCell cl=sheet.getRow(5).getCell((short)1);
System.out.println(Integer.parseInt(cl.toString().trim()));
FileOutputStream fos=new FileOutputStream("07-06-28-07-07-27.xls");
hwb.write(fos);
fos.flush();
fos.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
} }
} 执行到一半就出现异常提示:NumberFormatException,
发生异常的地方是System.out.println(Integer.parseInt(cl.toString().trim()));我的excel表中的数据格式为“常规”格式,实在不明白是出现了什么问题
import java.text.DateFormat;import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class CallRecord
{
public static void main(String[] args)
{
POIFSFileSystem pfs=null;
HSSFWorkbook hwb=null;
try
{
pfs=new POIFSFileSystem(new FileInputStream("07-06-28-07-07-27.xls"));
hwb=new HSSFWorkbook(pfs);
HSSFSheet sheet=hwb.getSheetAt(0);
System.out.println(sheet.getRow(4).getCell((short)1).toString());
HSSFCell cl=sheet.getRow(5).getCell((short)1);
System.out.println(Integer.parseInt(cl.toString().trim()));
FileOutputStream fos=new FileOutputStream("07-06-28-07-07-27.xls");
hwb.write(fos);
fos.flush();
fos.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
} }
} 执行到一半就出现异常提示:NumberFormatException,
发生异常的地方是System.out.println(Integer.parseInt(cl.toString().trim()));我的excel表中的数据格式为“常规”格式,实在不明白是出现了什么问题
看看cl是什么
然后看是每个cl都出错还是特定的那个有错
理论上是可以用cl.getStringCellValue()来获取某一单元格的值的,但是修改成
sheet.getRow(4).getCell((short)1).toString().getStringCellValue()
时却根本得不到值