import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class Write {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
//创建excel文件对象
File excelFile = new File("workbook.xls");
//如果文件不存在,则创建
if (!excelFile.exists())
{
excelFile.createNewFile();
}
//创建文件对象的输入流
FileInputStream in = new FileInputStream("workbook.xls");
// 先创建工作簿对象,绑定excel
HSSFWorkbook workbook = new HSSFWorkbook(in);//就是这语句总是出错,不知道为什么
//读取行数
System.out.println(workbook.getSheetAt(0).getLastRowNum());
}
}
|