0

I think my title is clear what I want to know. I already searched google and there's no answer to my problem.

I want to know how can I get the size or length of an specific column in POI Apache Java?

Opal
  • 81,889
  • 28
  • 189
  • 210
Rich
  • 3,928
  • 4
  • 37
  • 66
  • 2
    You mean width or height? – Raffaele May 28 '15 at 03:34
  • 1
    Do you mean width/height in pixels/points or do you mean the number of columns or rows? – grey00 May 28 '15 at 03:45
  • @raffaele i mean number of Rows in a Column. – Rich May 28 '15 at 07:49
  • @user3238865 i mean number of Rows in a Column. – Rich May 28 '15 at 07:49
  • You can look into these two answers: [http://stackoverflow.com/questions/13858846/how-to-calculate-number-of-rows-in-a-column-of-excel-document-using-java][1] [http://stackoverflow.com/questions/13874074/count-number-of-rows-in-a-column-of-excel-sheetjava-code-provided][2] [1]: http://stackoverflow.com/questions/13858846/how-to-calculate-number-of-rows-in-a-column-of-excel-document-using-java [2]: http://stackoverflow.com/questions/13874074/count-number-of-rows-in-a-column-of-excel-sheetjava-code-provided – sudipta06 May 29 '15 at 10:22

4 Answers4

1

I thought you cannot getheight for column.But you can getheight for Specific row . other way is use CellStyle to get Height(It can be done using top border+ bottom border+ font height) for specific cell.

Ragu
  • 373
  • 5
  • 15
0

I think there is no direct method for it.you have to iterate over all rows to know the size of column.

sample :

for (Cell cell : row) {
                ++COLUMNCOUNT;
            }
Avyaan
  • 1,285
  • 6
  • 20
  • 47
0

I already found out how to get the size of column in my on way. Post another answers if you have another one for future references.

int columnSize = 0;
for (int x = 0; x < row.getLastCellNum(); x++) {
  for (int y = 0; y < row.length; y++) {
    columnSize = y;
  }
  break;
}
Rich
  • 3,928
  • 4
  • 37
  • 66
0
Workbook workbook = new XSSFWorkbook(ExcelFile);
Sheet firstSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = firstSheet.iterator();
Row nextRow = iterator.next();
rowCount = firstSheet.getLastRowNum();
columnCount = nextRow.getLastCellNum();
  • getLastRowNum()// Using this number of rows can be calculated getLastCellNum()// Using this number of columns for that particular row can be calculated – Dakshinamoorthy D May 11 '16 at 07:13
  • 2
    Please do not give code-only answers. Some context and/or explanation should be contained. And please edit your comment into the answer. – Uwe Allner May 11 '16 at 07:21