Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ExcelAutomate;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import org.apache.poi.ss.usermodel.Cell;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.apache.poi.ss.util.CellReference;
- import org.apache.poi.xssf.usermodel.XSSFWorkbook;
- public class ExcelAutomate {
- public static void main(String[] args) throws IOException {
- FileInputStream inputStream = new FileInputStream(new File("C:\\Users\\Sayantan Mandal\\Desktop\\sm.xlsx"));
- Workbook workbook = new XSSFWorkbook(inputStream);
- Sheet sheet = workbook.getSheetAt(0);
- //int rowCount = sheet.getLastRowNum()- sheet.getFirstRowNum();
- //int noOfColumns = sheet.getRow(0).getLastCellNum();
- //for (int i = 0; i < rowCount+1; i++) {
- for (int i=0;i<10;i++){
- sheet.getRow(i).getCell(2).setCellFormula("SUM(A"+(i+1)+":B"+(i+1)+")");
- }
- // }
- // Row row = sheet.getRow(i);
- //Cell cell = row.getCell(j);
- //Row nrow = sheet.createRow(i+1);
- //Cell ncell = nrow.createCell(j);
- //System.out.print(cell+" "+ns);
- // }
- // System.out.println();
- //}
- inputStream.close();
- FileOutputStream outputStream = new FileOutputStream("C:\\Users\\Sayantan Mandal\\Desktop\\sm.xlsx");
- workbook.write(outputStream);
- workbook.close();
- outputStream.close();
- }
- }
Add Comment
Please, Sign In to add comment