import java.io.FileOutputStream; 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; /** * HSSFTest.java * * @author mjeffery * @created 2003/07/16 * @version 1a */ public class HSSFTest { HSSFWorkbook wb = null; HSSFSheet sheet = null; HSSFRow row = null; HSSFCell cell = null; public void createSheetThatCanOpen() { try { wb = new HSSFWorkbook(); sheet = wb.createSheet(); for (int i = 0; i < 6000; i++) { row = sheet.createRow((short)i); cell = row.createCell((short)0); cell.setCellValue("Test0"); cell = row.createCell((short)1); cell.setCellValue("Test1"); cell = row.createCell((short)2); cell.setCellValue("Test2"); } FileOutputStream fileOut = new FileOutputStream("c:/warrawarra/good.xls"); wb.write(fileOut); fileOut.close(); } catch (Exception e) { e.printStackTrace(); } } public void createSheetThatCannotOpen() { try { wb = new HSSFWorkbook(); sheet = wb.createSheet(); String tmp1 = null; String tmp2 = null; String tmp3 = null; for (int i = 0; i < 6000; i++) { tmp1 = "Test1" + i; tmp2 = "Test2" + i; tmp3 = "Test3" + i; row = sheet.createRow((short)i); cell = row.createCell((short)0); cell.setCellValue(tmp1); cell = row.createCell((short)1); cell.setCellValue(tmp2); cell = row.createCell((short)2); cell.setCellValue(tmp3); } FileOutputStream fileOut = new FileOutputStream("c:/warrawarra/bad.xls"); wb.write(fileOut); fileOut.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { HSSFTest test = new HSSFTest(); test.createSheetThatCanOpen(); test.createSheetThatCannotOpen(); } }