Guest User

Untitled

a guest
Jul 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package ExcelAutomate;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7.  
  8. import org.apache.poi.ss.usermodel.Cell;
  9. import org.apache.poi.ss.usermodel.Row;
  10. import org.apache.poi.ss.usermodel.Sheet;
  11. import org.apache.poi.ss.usermodel.Workbook;
  12. import org.apache.poi.ss.util.CellReference;
  13. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  14.  
  15. public class ExcelAutomate {
  16.  
  17. public static void main(String[] args) throws IOException {
  18. FileInputStream inputStream = new FileInputStream(new File("C:\\Users\\Sayantan Mandal\\Desktop\\sm.xlsx"));
  19. Workbook workbook = new XSSFWorkbook(inputStream);
  20. Sheet sheet = workbook.getSheetAt(0);
  21. //int rowCount = sheet.getLastRowNum()- sheet.getFirstRowNum();
  22. //int noOfColumns = sheet.getRow(0).getLastCellNum();
  23.  
  24. //for (int i = 0; i < rowCount+1; i++) {
  25. for (int i=0;i<10;i++){
  26.  
  27. sheet.getRow(i).getCell(2).setCellFormula("SUM(A"+(i+1)+":B"+(i+1)+")");
  28. }
  29. // }
  30. // Row row = sheet.getRow(i);
  31. //Cell cell = row.getCell(j);
  32. //Row nrow = sheet.createRow(i+1);
  33. //Cell ncell = nrow.createCell(j);
  34.  
  35. //System.out.print(cell+" "+ns);
  36. // }
  37. // System.out.println();
  38. //}
  39.  
  40. inputStream.close();
  41.  
  42. FileOutputStream outputStream = new FileOutputStream("C:\\Users\\Sayantan Mandal\\Desktop\\sm.xlsx");
  43. workbook.write(outputStream);
  44. workbook.close();
  45. outputStream.close();
  46. }
  47. }
Add Comment
Please, Sign In to add comment