Basic macros in Writer (delete row by cell name)

(in Writer)

i get my bookmark:
Anchor = Doc.Bookmarks.getByName(“MY”).getAnchor()

i get table and cell:
Cell = Anchor.Cell
Table = Anchor.TextTable

how to delete row with my known cell in known table?

Maybe so?

CellName = Cell.CellName
nRow = Val(Right(CellName, Len(CellName)-1)) - 1
table.getRows().removeByIndex(nRow, 1)

yes, maybe, but if row >= 10?

One possibility:

cellName = cell.CellName
startRN = 1
While Asc(Mid(cellName, startRN, 1))>=Asc("A")
 startRN = startRN + 1
Wend
r = 0 + Mid(cellName, startRN, 99)
textTable.Rows.RemoveByIndex(r-1, 1)  

If you need a FunctionAccess service anyway, you can use

r = 0 + fa.callFunction("REGEX", Array(cellName, "\D+", "", 1))  

where fa is the mentioned service.

Mumbling: Good decision. It will definitely be required if the table has more than 52 columns. And if the bookmark is set in the column after “small Z”.

:wink: By the way: Did you ever need a TextTable with that many columns?
Can you imagine a reason for the base-52-without-zero numbering for columns of TextTable as opposed to the base-26-without-zero used in spreadsheets?

I have always believed that if one cannot read one row of a table to the end and at the same time do not forget where this row began, then such a table has no right to exist. Just tried to create a 60-column text table. Even on an unfolded sheet (Landscape) it is very small cells… and useless …

I once did it on a “virtual sheet of paper” with a few thousand columns when I developed my famous functions indexForColumnName_1based() and columnNameForIndex_1based() which are available for a moderate fee from Lupp (smile). You will need the first one if you want to remove an arbitrary coliumn from a TextTable the same way as you did with rows. TextTable treatment seems to “Make everything as litle simple as possibel. But even more.” Tables for which the terms columns and rows have an acceptable meaning at all are called “simple tables”…
If you urgently need to know the proper column name for the 1048576th column of a TextTable: It’s GWnv.
Sorry. I sometimes adopt a playful variant ot the professional attitude and extend “no exceptions” beyond reason.
A main reason to write the mentioned functions was, however, that I noticed I hadn’t understood g-adic systems without zeroes for decades. Kind of self-punishment.

The following functions may be useful.

' Returns the column and row numbers (0-based) by the cell name of the text table (CellName).
' Returns an array of 2 elements (Long): column number and row number.
' For a split cell (name contains a dot), returns the values for the original cell (before the split).
' If the argument is invalid, returns array(-1, -1). 
Function TextTable_ColumnRowByCellName(ByVal cellName As String)
  Dim i As Long, j as Long, c As String
  Dim column As Long, row As Long       ' 1-based
  TextTable_ColumnRowByCellName=Array(column-1, row-1)
  i=Instr(1, cellName, ".")
  If i>1 Then cellName=Left(cellName, i-1)
  i=1 : column=0
  Do While i<Len(cellName)
    c=Mid(cellName, i, 1)
    If c>="A" And c<="Z" Then
      column=column * 52 + Asc(c) - Asc("A") + 1
    ElseIf c>="a" And c<="z" Then
      column=column * 52 + Asc(c) - Asc("a") + 27
    Else
      Exit Do
    End If
    i=i+1
  Loop
  For j=i+1 To Len(cellName)
    c=Mid(cellName, j, 1)
    If c<"0" Or c>"9" Then Exit Function
  Next j  
  row=Clng(Mid(cellName, i))
  If column>0 And row>0 Then TextTable_ColumnRowByCellName=Array(column-1, row-1)
End Function

' Returns the column number (0-based) by the cell name of the text table (CellName).
' For a split cell (name contains a dot), returns the value for the original cell (before the split).
' If the argument is invalid, returns -1. 
Function TextTable_ColumnByCellName(ByVal cellName As String)
  TextTable_ColumnByCellName=TextTable_ColumnRowByCellName(cellName)(0)
End Function

' Returns the row number (0-based) by the cell name of the text table (CellName).
' For a split cell (name contains a dot), returns the value for the original cell (before the split).
' If the argument is invalid, returns -1. 
Function TextTable_RowByCellName(ByVal cellName As String)
  TextTable_RowByCellName=TextTable_ColumnRowByCellName(cellName)(1)
End Function

Sub testTextTable_ColumnRow
  Dim s As String
  s="AA111"
  Msgbox Join(TextTable_ColumnRowByCellName(s))
  Msgbox TextTable_ColumnByCellName(s)
  Msgbox TextTable_RowByCellName(s)
End Sub