POI读取EXCEL 顶。用POI可以用sheet.rowIterator();取得行数,但怎么取得列数呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一个操作excel的例子,看对你有帮助否package excel;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("d:\\foo.xls")); HSSFWorkbook wb = new HSSFWorkbook(fs); wb.removeSheetAt(2); HSSFSheet sheet = wb.getSheetAt(0); sheet.setColumnWidth((short)200,(short)500); 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("asafasfsafasfsfaas test"); // Write the output to a file FileOutputStream fileOut = new FileOutputStream("d:\\ffoo.xls"); wb.write(fileOut); fileOut.close(); }} 何时有必要重写equals()和hashCode() 接值 问一个不能结帖子的问题 值参数和引用参数 如何用Java Socket读写纯文本? 请问 有什么问题呢? Some questions on OICQ 在Jbuilder5中为什么不能输入全角的符号?如“!” 如何将Ext正则表达式转换为Java正则表达式 java有没有能实现定时功能的包? 有关求最大的两个数值的问题
package excel;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("d:\\foo.xls"));
HSSFWorkbook wb = new HSSFWorkbook(fs);
wb.removeSheetAt(2);
HSSFSheet sheet = wb.getSheetAt(0);
sheet.setColumnWidth((short)200,(short)500); 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("asafasfsafasfsfaas test");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("d:\\ffoo.xls");
wb.write(fileOut);
fileOut.close();
}
}