apache 开源项目POI中HSSF(用来处理excel表的)使用中遇到的问题
最近需要处理一些 电子表格,然后下了一个APACHE.POI.HSSF用,
看了一下说明文档,自己写了一段简单的程序,但是编译时老是告诉我
(C:\test\ok\ReadHSSF.java:37: incompatible types
found : double
required: java.lang.Double
cellValue[i][j] = cell.getNumericCellValue();
^
C:\test\ok\ReadHSSF.java:41: incompatible types
found : double
required: java.lang.Double
cellValue[i][j] = (double)0;
^
2 errors)
下面是有问题的代码:
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.poifs.filesystem.*;
import java.io.IOException;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.FileInputStream;
public class ReadHSSF
{
public static void main (String args[]) throws IOException
{
int val=1;
POIFSFileSystem fs=
new POIFSFileSystem(new FileInputStream("E:/workstation/cai3.xls"));
HSSFWorkbook wb=new HSSFWorkbook(fs);
HSSFSheet sheet1 = wb.getSheetAt(0);
//HSSFRow row = sheet1.getRow(0);
//HSSFCell cell = row.getCell((short)0);
FileWriter fw = new FileWriter("hssf.txt");
PrintWriter pw = new PrintWriter(fw);
//System.out.print(cell.getStringCellValue());
Double[][] cellValue = new Double[16][48];
for(int i=0;i<16;i++)
{
for(int j=0;j<48;j++)
{
HSSFRow row = sheet1.getRow(val);
HSSFCell cell = row.getCell((short)1);
try
{
cellValue[i][j] = cell.getNumericCellValue();
}
catch(NullPointerException e)
{
cellValue[i][j] = (double)0;
}
finally
{
pw.println(cellValue[i][j].toString()+'\r');
}
val++;
}
}
fw.close();
pw.close();
}
}