0

I am reading an already existing excel file and trying to add certain cells for example(C4-C15). I am having difficult manipulating the files through java. I am using apache poi, and would appreciate any help or direction.

1
  • 1
    What is your code so far? Maybe this answer and the link in the first comment to the OP there helps. Commented Sep 26, 2014 at 21:42

1 Answer 1

1

In order to access a cell in Apache POI, you have to get a row first, and then get cell within chosen row. Below is example:

//Input file
InputStream inp = new FileInputStream("workbook.xls");

//Create workbook instance
Workbook wb = WorkbookFactory.create(inp);

//Create sheet instance
Sheet sheet = wb.getSheetAt(0);

for(int i = 3; i <= 16; ++i){ //Rows from 4 to 15 (Apache POI is zero based)
    Row row = sheet.getRow(i);
    Cell cell = row.getCell(2); //Column "C"

    //Do something with cell
}

// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();

Source (more examples here)

Sign up to request clarification or add additional context in comments.

1 Comment

Oops, didn't know there's almost the same question. Hope this answer helps as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.