当前位置: 代码迷 >> Java相关 >> 关于POI的一些问题
  详细解决方案

关于POI的一些问题

热度:138   发布时间:2007-01-25 21:07:00.0
关于POI的一些问题

这是一个POI example里的读写excel文件的例子。
1,HSSFCell cell = row.getCell((short)3);//这里为什么参数必须是short呢?如果数据量超过short怎么办呢?
2,为什么只有HSSFRow而没有列的设置呢?

package org.apache.poi.hssf.usermodel.examples;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;


public class ReadWriteWorkbook
{
public static void main(String[] args)
throws IOException
{
POIFSFileSystem fs =
new POIFSFileSystem(new FileInputStream("workbook.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow row = sheet.getRow(2);
if (row == null)
row = sheet.createRow(2);
HSSFCell cell = row.getCell((short)3);//
if (cell == null)
cell = row.createCell((short)3);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue("a test");

// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();

}
}


----------------解决方案--------------------------------------------------------
不是很清楚,你查一下api就可以了.
----------------解决方案--------------------------------------------------------
其实操作excel最好用VBA来做!
----------------解决方案--------------------------------------------------------