QTextDocumentWriter does not create a document with nested tables
-
I want to get a format file at the output .odt. The file should contain tables, text, and pictures. I started with tables.
Made a test code:
ui->textEdit->setHtml(QString( "<style>" //для всех таблиц //"table {width:100%;background: black;border: 2px solid white;}" //"th { padding: 3px; color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}" //"tr { padding: 3px;color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}" //"td { padding: 3px;color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}" //класс на каждую ячейку ".outer {background-color: cyan;}" ".inner {padding: 1px; background-color: black;}" ".cell_A { padding: 3px; color:black; background-color: white;}" ".cell_B { padding: 3px; color:white; background-color: gray;}" "</style> " "<H1><CENTER>" "<font color='black'><b>ПРОТОКОЛ ИСПЫТАНИЯ АККУМУЛЯТОРА №1</b>" "</CENTER></H1>" " <CENTER> " " <TABLE class='outer'>" " <tr>" " <td>" " <TABLE class='inner'>" " <tr class='cell_A'><td class='cell_A'>Емкость при разряде</td><td class='cell_A'>43</td></tr>" " <tr class='cell_A'><td class='cell_A'>Остаточная емкость</td><td class='cell_A'>86</td></tr>" " <tr class='cell_A'><td class='cell_A'>Энергия полная</td><td class='cell_A'>556</td></tr>" " <tr class='cell_A'><td class='cell_A'>Емкость при заряде</td><td class='cell_A'>52</td></tr>" " <tr class='cell_A'><td class='cell_A'>КПД заряда</td><td class='cell_A'>83</td></tr>" " </TABLE> " " </td>" " <td>" " <TABLE class='inner'>" " <tr class='cell_B'><td class='cell_B'>ЭПС 90% разряд</td><td class='cell_B'>11</td></tr>" " <tr class='cell_B'><td class='cell_B'>ЭПС 50% разряд</td><td class='cell_B'>12</td></tr>" " <tr class='cell_B'><td class='cell_B'>ЭПС 90% заряд</td><td class='cell_B'>13</td></tr>" " <tr class='cell_B'><td class='cell_B'>ЭПС 50% заряд</td><td class='cell_B'>11</td></tr>" " <tr class='cell_B'><td class='cell_B'></td><td class='cell_B'>4</td></tr>" " </TABLE> " " </td>" " </tr>" " </TABLE> " " </CENTER>" )); textDocument = ui->textEdit->document(); QTextDocumentWriter writer; writer.setFormat("odf"); writer.setFileName("/media/usb0/report.odt"); writer.write(textDocument);There is no table in the output file. There is a table in QTextEdit, checked by output to the screen.
!

-
I want to get a format file at the output .odt. The file should contain tables, text, and pictures. I started with tables.
Made a test code:
ui->textEdit->setHtml(QString( "<style>" //для всех таблиц //"table {width:100%;background: black;border: 2px solid white;}" //"th { padding: 3px; color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}" //"tr { padding: 3px;color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}" //"td { padding: 3px;color:white; background-color: black;border: 1px solid white;border-collapse:collapse;}" //класс на каждую ячейку ".outer {background-color: cyan;}" ".inner {padding: 1px; background-color: black;}" ".cell_A { padding: 3px; color:black; background-color: white;}" ".cell_B { padding: 3px; color:white; background-color: gray;}" "</style> " "<H1><CENTER>" "<font color='black'><b>ПРОТОКОЛ ИСПЫТАНИЯ АККУМУЛЯТОРА №1</b>" "</CENTER></H1>" " <CENTER> " " <TABLE class='outer'>" " <tr>" " <td>" " <TABLE class='inner'>" " <tr class='cell_A'><td class='cell_A'>Емкость при разряде</td><td class='cell_A'>43</td></tr>" " <tr class='cell_A'><td class='cell_A'>Остаточная емкость</td><td class='cell_A'>86</td></tr>" " <tr class='cell_A'><td class='cell_A'>Энергия полная</td><td class='cell_A'>556</td></tr>" " <tr class='cell_A'><td class='cell_A'>Емкость при заряде</td><td class='cell_A'>52</td></tr>" " <tr class='cell_A'><td class='cell_A'>КПД заряда</td><td class='cell_A'>83</td></tr>" " </TABLE> " " </td>" " <td>" " <TABLE class='inner'>" " <tr class='cell_B'><td class='cell_B'>ЭПС 90% разряд</td><td class='cell_B'>11</td></tr>" " <tr class='cell_B'><td class='cell_B'>ЭПС 50% разряд</td><td class='cell_B'>12</td></tr>" " <tr class='cell_B'><td class='cell_B'>ЭПС 90% заряд</td><td class='cell_B'>13</td></tr>" " <tr class='cell_B'><td class='cell_B'>ЭПС 50% заряд</td><td class='cell_B'>11</td></tr>" " <tr class='cell_B'><td class='cell_B'></td><td class='cell_B'>4</td></tr>" " </TABLE> " " </td>" " </tr>" " </TABLE> " " </CENTER>" )); textDocument = ui->textEdit->document(); QTextDocumentWriter writer; writer.setFormat("odf"); writer.setFileName("/media/usb0/report.odt"); writer.write(textDocument);There is no table in the output file. There is a table in QTextEdit, checked by output to the screen.
!

Hi, what Qt version do you use?
I fear, you cant use<style>tags inQTextEdit/ RichText, since in Qt5 LTS and even in the latest Qt6 it doesn't support it. Only the listed tags are usable. That's why your style content is skipped and you only see the empty<tr>table-row.- https://doc.qt.io/qt-5/richtext-html-subset.html#supported-tags
- https://doc.qt.io/qt-6/richtext-html-subset.html#supported-tags
Edit:
But maybe it's an issue when writing it to ODF.
What do you get, when you print yourQTextDocumentwithtextDocument = ui->textEdit->document(); textDocument.toHtml()