1 2 17 18 19 package org.apache.poi.hssf.usermodel.examples; 20 21 import org.apache.poi.hssf.usermodel.*; 22 import org.apache.poi.hssf.util.HSSFColor; 23 24 import java.io.FileOutputStream ; 25 import java.io.IOException ; 26 27 33 public class BigExample 34 { 35 public static void main(String [] args) 36 throws IOException 37 { 38 short rownum; 39 40 FileOutputStream out = new FileOutputStream ("workbook.xls"); 42 HSSFWorkbook wb = new HSSFWorkbook(); 44 HSSFSheet s = wb.createSheet(); 46 HSSFRow r = null; 48 HSSFCell c = null; 50 HSSFCellStyle cs = wb.createCellStyle(); 52 HSSFCellStyle cs2 = wb.createCellStyle(); 53 HSSFCellStyle cs3 = wb.createCellStyle(); 54 HSSFFont f = wb.createFont(); 56 HSSFFont f2 = wb.createFont(); 57 58 f.setFontHeightInPoints((short) 12); 60 f.setColor((short) HSSFColor.RED.index); 62 f.setBoldweight(f.BOLDWEIGHT_BOLD); 65 66 f2.setFontHeightInPoints((short) 10); 68 f2.setColor((short) HSSFColor.WHITE.index); 70 f2.setBoldweight(f2.BOLDWEIGHT_BOLD); 72 73 cs.setFont(f); 75 cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); 77 78 cs2.setBorderBottom(cs2.BORDER_THIN); 80 cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND); 82 cs2.setFillForegroundColor((short) HSSFColor.RED.index); 84 85 cs2.setFont(f2); 87 88 wb.setSheetName(0, "HSSF Test"); 90 for (rownum = (short) 0; rownum < 300; rownum++) 92 { 93 r = s.createRow(rownum); 95 if ((rownum % 2) == 0) 97 { 98 r.setHeight((short) 0x249); 100 } 101 102 for (short cellnum = (short) 0; cellnum < 50; cellnum += 2) 105 { 106 c = r.createCell(cellnum); 108 c.setCellValue(rownum * 10000 + cellnum 110 + (((double) rownum / 1000) 111 + ((double) cellnum / 10000))); 112 113 if ((rownum % 2) == 0) 115 { 116 c.setCellStyle(cs); 118 } 119 120 c = r.createCell((short) (cellnum + 1)); 122 123 c.setCellValue("TEST"); 125 s.setColumnWidth((short) (cellnum + 1), (short) ((50 * 8) / ((double) 1 / 20))); 127 128 if ((rownum % 2) == 0) 130 { 131 c.setCellStyle(cs2); 134 } 135 136 } 137 } 138 139 rownum++; 142 rownum++; 143 144 r = s.createRow(rownum); 145 146 cs3.setBorderBottom(cs3.BORDER_THICK); 149 150 for (short cellnum = (short) 0; cellnum < 50; cellnum++) 152 { 153 c = r.createCell(cellnum); 155 c.setCellStyle(cs3); 157 } 158 159 161 162 s = wb.createSheet(); 165 wb.setSheetName(1, "DeletedSheet"); 166 wb.removeSheetAt(1); 167 169 wb.write(out); 172 out.close(); 173 } 174 } 175 | Popular Tags |