Hi,
It is possible to return value of getMaxDataColumn/MaxDataRow methods, includes a merged range of cell, that are max?
For example :
I have a book (attachments) and i want to receive a:
1) Max Data Column = 7
2) Max Data Row = 4
@Test
public void maxColumnTets() throws Exception {
Workbook wb = new Workbook("D://lastColumn.xlsx");
Cells cells = wb.getWorksheets().get(0).getCells();
System.out.println(cells.getMaxDataColumn());
System.out.println(cells.getMaxDataRow());
}
I do not needed to receive a last styled cell, or merged. I needed only data cells.
Best regards. Alexey
Hi. Thanks for answer, but i don’t needed to receive data of another cell. I needed only count of column.
Basicaly, i render a HTML table and if i will render only one column, then i will have no enough place for text. I needed 6 columns for colspan attribute set.
So, is very complicated to add API function something getLastDataColumn/Row, that will returns data column/row + span (or add optional parameter to getaMaxDataColumn/Row, that will change behavior)?
Best regards. Alexey
Hi,
I am afraid, there is no better way to cope with it and you have to write your own code to accomplish your custom oriented task. For example, I have written a simple code snippet that will check if the last cell is merged. And, if the cell is merged, we can calculate the columns’ range to be added to the MaxDataColumn attribute to get the final/updated value accordingly.
e.g
Sample code:
String filePath = “lastColumn.xlsx”;
Workbook wb = new Workbook(filePath);
Worksheet ws = wb.getWorksheets().get(0);
//Get max data column
int maxdCol = ws.getCells().getMaxDataColumn();
int drow = 1;
//Get the merged cell
Cell mCell = ws.getCells().get(maxdCol, drow);
//If last cell is merged then calculate its merged range accordingly.
if (mCell.isMerged())
{
Range rng = mCell.getMergedRange();
int idxCol = mCell.getColumn() + rng.getColumnCount();
//int idxRow = mCell.getRow() + rng.getRowCount();//if required.
int newmaxdCol = idxCol-1;
System.out.println(newmaxdCol); //7 - Ok
}
Hope, this helps a bit.
Thank you.