Anshul Srivastava
Anshul Srivastava

Reputation: 37

How to select all the cells in an excel using Java and apache poi

I have created an excel sheet and gave it some data. Now i have to select all the cells in the excel sheet, so that i can apply wrapping of text to all of them at once. My data that is stored in the excel sheet is dynamic Can someone help me in this please. I'm using Java and Apache POI.

Thanks for reading!

Upvotes: 0

Views: 2398

Answers (2)

amseager
amseager

Reputation: 6391

There is not need to select cells in Apache POI. You should just iterate over them and perform some actions that you want.

Look at this iteration example: https://poi.apache.org/spreadsheet/quick-guide.html#Iterator

In your case it would be something like this:

    for (Row row : sheet) {
        for (Cell cell : row) {
            cell.getCellStyle().setWrapText(true);
        }
    }

Upvotes: 2

maddy23285
maddy23285

Reputation: 786

Try this:

CellRangeAddress region = new CellRangeAddress(6, 8, 1, 10); //CellRangeAddress(startRow,endRow,startCell,endCell)
RegionUtil.setWrapText(true, region, sheet);

or

CellRangeAddress region = CellRangeAddress.valueOf(A6:J8); 
RegionUtil.setWrapText(true, region, sheet);

Check this documentation on poi.apache.org

Upvotes: 0

Related Questions