import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import java.io.*; public class Sample9_1{ public static void main(String[] args){ Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet(); Row row1 = sheet.createRow(1); Row row2 = sheet.createRow(2); Cell cell1_1 = row1.createCell(1); Cell cell1_2 = row1.createCell(2); Cell cell1_3 = row1.createCell(3); Cell cell2_3 = row2.createCell(3); cell1_1.setCellValue(30); cell1_2.setCellValue(25); cell1_3.setCellFormula("B2+C2"); cell2_3.setCellFormula("MOD(B2,C2)"); FileOutputStream out = null; try{ out = new FileOutputStream("sample9_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()); } } } }