1 2 17 18 19 package org.apache.poi.hssf.usermodel.examples; 20 21 import org.apache.poi.hssf.usermodel.*; 22 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.util.Date ; 26 27 34 public class CreateDateCells 35 { 36 public static void main(String [] args) 37 throws IOException 38 { 39 HSSFWorkbook wb = new HSSFWorkbook(); 40 HSSFSheet sheet = wb.createSheet("new sheet"); 41 42 HSSFRow row = sheet.createRow((short)0); 44 45 HSSFCell cell = row.createCell((short)0); 47 cell.setCellValue(new Date ()); 48 49 HSSFCellStyle cellStyle = wb.createCellStyle(); 52 cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm")); 53 cell = row.createCell((short)1); 54 cell.setCellValue(new Date ()); 55 cell.setCellStyle(cellStyle); 56 57 FileOutputStream fileOut = new FileOutputStream ("workbook.xls"); 59 wb.write(fileOut); 60 fileOut.close(); 61 62 } 63 } 64 | Popular Tags |