No proper formated table import from calc to writer?

Hi,

I have a calc table with many chemical formulas which include sub- and superscript. Wanting to transfer this table into a writer document, the only way to preserve this formatting is pasting a calc table, which is an unsuitable option if you want a nicely formatted document at the end. All other non-picture options provided under paste special do not preserve the formatting.

Is there another way of importing such a table? It would be disappointing if such a simple operation was not possible.

Best regards.

In what way (by what means) did you create your chemical formulae?
(Please read Guidelines for asking)

They were created in calc using the sub- and superscript formatting. e.g. NH4+ with the 4 in subscript and the + in superscript.

It’s strange.
You can Copy/PasteSpecial a single formula of that kind from a spreadsheet (Calc) to a text document (Writer) using Paste Special... in RTF mode. (This changes the relative size of sub/super, however, a bit.) If you try to import formulae from a CellRange this way, RTF will create a table and ignore Sub/Super.
RTF is an old mess, I can’t help. I would suppose LibreOffice tries to reproduce a behaviour originally introduced by MS. And everything going through the clipboard is afflicted by the properties of that tool and the formats it supports (OS dependent).

Anyway “formulae” based on character styles are very limited. You cannot have a superscript (high index) above a subscript (low index) e.g. as is needed for the common nuclide notation or for a chemical application where charge signs should display above counting indices or the like.

To avoid problems of the kind you may try the ‘Math’ component of LibreOffice which can be used to create formulae as OLE objects in Writer and in Calc as well. No difference in appearance then.

Thanks, at least I know now that I am not too dumb to find the proper way to do it but that amazingly there is no copying function. You can only transfer content but not copy! In 2018! Amazing.

Create a new table in Writer (Table → Insert Table) with the appropriate number of rows and columns.

Then copy and paste special (Formatted text [RTF]) for each individual cell.

If the table is very large, then it may be worth writing a macro to automate the copying and pasting.

Thanks, but in that case I can also rewrite it. A macro is not worth it as I plan to do this only once. Amazing that there is no straightforward way of copying from a to b. If it only transfers the content it does actually not copy.

Quoting @jimk: “If the table is very large, then it may be worth writing a macro to automate the copying and pasting.”
Do you know how to do this kind of Copy/Paste without losing formats by custom code?
I tried but did not succeed with an insertion on the paragraph level. So far I had to insert on the TextPortion level, and for preserving the format to pass every sigle property as an element of a PropertyValues array.
That’s too complicated.

My idea was a dispatcher call to .uno:PasteSpecial using the RTF setting, at the paragraph level of each cell. However, I did not verify that it works. Is that what you tried?

I tried that the manual way and observed “(This changes the relative size of sub/super, however, a bit.)” as I reported in my answer.
To Copy/Paste formatted Text correctly from Calc to Writer by user code seems to be a ticklish task. This may be related to different implementations of the Text service in Calc as compared with Writer. However, I don’t understand Text and TextCursors, TextRanges… on a level required to clear this eventually.

Strange enough: Copy/Paste (without “Special”!) works much better in the reverse direction for tables which are mapped to CellRanges.
"The universe is made to be a stage for surprises. " (Lupp)