How to get the last cell containing of each row

i am able to get the last row of the sheet but unable to get the last cell from the row index. how can i get the that. The code for finding the last row is

public int GetLastRow()
{
XSheetCellCursor XSCC = _sheet.createCursor();
((XUsedAreaCursor)XSCC).gotoEndOfUsedArea(true);
XCellRangeAddressable XCRA = (XCellRangeAddressable)XSCC;
CellRangeAddress CRA = XCRA.getRangeAddress();
int lastRow = CRA.EndRow;
return lastRow;
}

i found by searching form libre office thanks to exeye .
and my question is, from the each row how can i get the last cell that containing data in it.

I’m not clear if you want the latest cell with data from the user area (EndOfUsedArea) and the current region (collapseToCurrentRegion).

In both cases, in the return range you have the RangeAddress property. There you have both the last row (EndRow) and the last column (EndColumn).

Thank you very much for the replay. acutally i am using this method in which, from the row i want to find the last cell.
public void ReplaceStringCellValue(string oldString, string newString)
{
int lastRow = GetLastRow();

 for (int rowIndex = 0; rowIndex <= lastRow; rowIndex++)
 {
     int lastCell = GetLastUsedCellInRow(rowIndex);
     for (int colIndex = 0; colIndex <= lastCell; colIndex++)
     {
         XCell cell = _sheet.getCellByPosition(colIndex, rowIndex);
         if (cell == null) continue;

         var cellType = cell.getType();
         if (cellType == CellContentType.TEXT)
         {
             string cellValue = GetCellValue(cell);
             if (cellValue.Contains(oldString))
             {
                 cell.setFormula(cellValue.Replace(oldString, newString));
             }
         }
     }
 }

}

i am retrieving the last cell like this, but if there is anything simple then this then i want to implement that.
public int GetLastUsedCellInRow(int rowIndex)
{
int lastCell = -1;

 for (int colIndex = 0; colIndex < 1024; colIndex++) 
 {
     XCell cell = _sheet.getCellByPosition(colIndex, rowIndex);
     if (cell != null && cell.getType() != CellContentType.EMPTY)
     {
         lastCell = colIndex;
     }
 }

 return lastCell;

}

But you didn’t clear my doubt. If you add a file with example fictitious data and tell me what cell you want, I show you how to do it.

like, i if the rowindex= 0, then from the 0 index how i can find the last cell containg which contains data. how to use EndColumn to get the last cell of specific row. actually i am beginner in this. so can you help me please

You get that with RangeAddress.EndColumn. Do not add more without an example.

   public int GetLastCell()
   {
       XSheetCellCursor XSCC = _sheet.createCursor();
       ((XUsedAreaCursor)XSCC).gotoEndOfUsedArea(true);
       XCellRangeAddressable XCRA = (XCellRangeAddressable)XSCC;
       CellRangeAddress CRA = XCRA.getRangeAddress();
       int lastCell = CRA.EndColumn;
       return lastCell;
   }

i tried it but it does not provide the last cell of specified row, like rowIndex = 0,

  1. You should provide an example as you were told more than once.
  2. The “last column” of a specific row has either the index 2^10-1 or 2^14-1 depending on the version.
  3. If your question is about the last cell of a.row which is “used” you need to use the service …queryContentCells of the row as a SheetCellRange with the proper argument. Die The .EndColumn of the RangeAddress of the range with the highest index in the returned SheetCellRanges object may then be what you want.