Getting/Setting table cell content?

Previous topic - Next topic


I've been looking through the Scripter API but I'm unable to find a way to access or edit table cell content. Are there no such methods available? 
What I'm looking for specifically is the ability to get and set the text in the cell.

Being able to apply styling (Like in a normal text frame) would be a huge plus!


I completely missed the getCellText and setCellText methods!

Still haven't found a way to actually style the text inside of them through the Scripter API..


the next time i update the api documentation on impagina, i will move those to functions to the "table" section.

this having been said, i don't see either, how it is possible to easily add the formatting of text inside of table cells.

i did a "simple" try but it was not successful:

in plugins/scriptplugin/cmdtext.cpp , i've removed the check for the frame type in scribus_settextfill().
then scribus does not complain about the item not being of the right type, but running


from the scripter console does still not give the expected result.

if you want, you can have a look at the ApplyCharstyleHelper::apply() function in the same file and check where it fails to correctly get the selection or look at the applyCharStyle that is called from there and see if is there is a check for frame type inside of it...

applying the styles from the content palette does work, so there is hope : - )


i did one more check:

if i output item->itemName, i get the name of the table... that might be a big issue, if we don't want to recreate all the text formatting function with calls that are specific to table cells.


I see two solutions to this problem:

First solution is to replicate every formatting function specifically for table cells.. (Like you suggested)
This will essentially create a lot of duplicate code but might be the easier option.

The second solution is to make each text-frame (The table cells essentially) selectable from code and allow them to show up in getPageItems(), etc..
The problem with this approach is that the cells inside the table aren't considered page-items in the traditional sense, since they are children of the table and only (currently) accessible by specifying a row and column.

I'm working on the first solution right now and it's a lot of functions to basically copy/paste.
I'll upload a diff file when I'm satisfied with the result!


sorry, but i really don't think that duplicating the script functions is an acceptable solution.

i fear that the code would not be maintainable.


i did some research.

and i got scribus_settextfill() to work with text selected in a table cell.

my suggestion would be to add a "GetUniqueTextItem()" that only would return a PageItem* if the selection (or name) can be used as a text frame (text frame, path text, table).

with it, we could then even remove

if (!item->isTextFrame() && !item->isPathText())

and, at the end, have less code instead of duplicating everything : - )


I've now opened a ticket and put a draft patch in the bug tracker:

Since the diff is a not as "clean" as it could be, here is the new scribus_settextfill():

PyObject *scribus_settextfill(PyObject* /* self */, PyObject* args)
char *Name = const_cast<char*>("");
char *Color;
if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Color, "utf-8", &Name))
return nullptr;
if (!checkHaveDocument())
return nullptr;
PageItem *item = GetUniqueItemAsText(QString::fromUtf8(Name));
if (item == nullptr)
PyErr_SetString(WrongFrameTypeError, QObject::tr("Can only set text color on an item that behaves as a text frame.","python error").toLocal8Bit().constData());
return nullptr;
ApplyCharstyleHelper<QString>(item, QString::fromUtf8(Color)).apply(&CharStyle::setFillColor, 0, item->itemText.length());