Add extra columns when converting text to table in Writer
Lodev
lodev at ossii.com.tw
Wed Jul 16 08:12:26 UTC 2025
Hi,
We're trying to implement a new feature in Writer. When converting text
to table in Writer, users here want to add additional columns so that
they don't need to manually add it after creating.
We've implemented the Convert Text To Table dialog, adding a spin button
to let users choose how many columns they want to add, and fill the
selected value in SwConvertTableDlg::GetValues() in
sw/source/ui/table/convert.cxx. We also add a new variable in
SwInsertTableOptions (sw/inc/itabenum.hxx) .
We also found that (hope it's correct) the core implementation might be
in SwNodes::TextToTable() in sw/source/core/docnode/ndtbl.cxx. We knew
that the for loop
for( nLines = 0, nBoxes = 0;
aSttIdx.GetIndex() < aEndIdx.GetIndex();
aSttIdx += SwNodeOffset(2), nLines++, nBoxes = 0 )
is the main implementation that creates the table from the text. Each
row of the table was done created after this:
pBox = new SwTableBox( pBoxFormat, *pSttNd, pLine );
pLine->GetTabBoxes().insert( pLine->GetTabBoxes().begin() +
nBoxes++, pBox );
if( nMaxBoxes < nBoxes )
nMaxBoxes = nBoxes;
So we tried to add empty columns, but so far couldn't get it right. The
copilot on Github told us that we should create a start node, an empty
text node, and an end node and insert it to the end of the row. But it
kept giving us illusion code. Either methods that don't exist, or type
that can't be converted, and when we got it compiled successfully, it
kept crashing at
SwTableBox(pBoxFormat, *pSttNd, pLine);
with a message (in console) telling us that "In which table is the box?"
Could anyone please give us some instructions and hints about what we
should do if we want to add (a certain number of) empty cells after each
row?
Thanks for your help.
Lodev
More information about the LibreOffice
mailing list