import org.apache.poi.ss.usermodel.*; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import java.io.*; import java.util.Calendar; import java.util.Date; public class Sample5_1{ public static void main(String[] args){ FileInputStream in = null; Workbook wb = null; try{ in = new FileInputStream("sample.xls"); wb = WorkbookFactory.create(in); }catch(IOException e){ System.out.println(e.toString()); }catch(InvalidFormatException e){ System.out.println(e.toString()); }finally{ try{ in.close(); }catch (IOException e){ System.out.println(e.toString()); } } Sheet sheet = wb.getSheetAt(0); for (int i = 1 ; i < 8 ; i++){ Row row = sheet.getRow(i); if (row == null){ row = sheet.createRow(i); } Cell cell1 = row.getCell(1); if (cell1 == null){ cell1 = row.createCell(1); } Cell cell2 = row.createCell(2); switch(cell1.getCellType()) { case Cell.CELL_TYPE_STRING: cell2.setCellValue("String"); break; case Cell.CELL_TYPE_NUMERIC: if(DateUtil.isCellDateFormatted(cell1)) { cell2.setCellValue("Date"); } else { cell2.setCellValue("Numeric"); } break; case Cell.CELL_TYPE_BOOLEAN: cell2.setCellValue("Boolean"); break; case Cell.CELL_TYPE_FORMULA: cell2.setCellValue("Formula"); break; case Cell.CELL_TYPE_ERROR : cell2.setCellValue("Error"); break; case Cell.CELL_TYPE_BLANK : cell2.setCellValue("Blank"); break; } } FileOutputStream out = null; try{ out = new FileOutputStream("sample5_1.xls"); wb.write(out); }catch(IOException e){ System.out.println(e.toString()); }finally{ try { out.close(); }catch(IOException e){ System.out.println(e.toString()); } } } }