62,629
社区成员




import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
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.hssf.util.CellRangeAddress;
/**
* @author idle~`
* @version 0.1
* @date 2008-11-4
*/
public class POITest {
public static String outputFile="E:/TEMP/idleTest.xls";
public static void main(String argv[]){
try{
HSSFWorkbook workbook = new HSSFWorkbook();
// create sheet
HSSFSheet sheet = workbook.createSheet("test");
// create row at line 0
HSSFRow row = sheet.createRow(0);
// create cell at row 0
HSSFCell cell = row.createCell(0);
// set cell value type
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
// set cell value
cell.setCellValue(new HSSFRichTextString(""));
cell.setCellStyle(POIStyleUtil.getTitleStyle(workbook));
// merge row and column from row 0 to row 0,column 0 to column 7
sheet.addMergedRegion(new CellRangeAddress(0,0,0,7));
for(int i = 1; i < 10; i++){
HSSFRow rows = sheet.createRow(i);
for(int j = 0; j < 8; j ++){
HSSFCell cells = rows.createCell(j);
cells.setCellType(HSSFCell.CELL_TYPE_STRING);
cells.setCellValue(new HSSFRichTextString("" + i + " : " + j));
cells.setCellStyle(POIStyleUtil.getColumnTitleStyle(workbook));
}
}
FileOutputStream fOut = new FileOutputStream(outputFile);
workbook.write(fOut);
fOut.flush();
fOut.close();
System.out.println("");
}catch(Exception e) {
System.out.println("问题是" + e );
}
}
}