Andrew,

As I am in the middle of my tax - which I truly hate but I have to focus on
it, but I will quickly try to assist:
1) One of the first things I did in ODFDOM, what Simple API is being forked
of, is adding a debug function for OdfElement & OdfAttribute to give out
XML, when I make a mouse hover in the IDE over the object, by overwriting
the toString() method.
Therefore I suggest not to cast to Node, but to OdfElement, or even more
specific TableTableRowElement to get a better transparency during debugging.
2) Then debug and take a look if the objects are really existing. Only if
you are taking XML nodes from another XML, you need to "import" them into
the XML document, like document.import(xml, true); Only by reading the code
I could not spot the problem, sry.
3) If you are still totally helpless send a full test function someone
could copy/paste into a test class of Simple API like in
simple/src/test/java/org/odftoolkit/simple/table/TableTest.java perhaps
reuse an existing table test file or attach one with uncritical data. So
debugging might be easier for one of us, but might take a while till I
could jump on, but perhaps others might help :-)

Good luck! :-)
Svante
ᐧ

Am Mi., 14. Nov. 2018 um 19:29 Uhr schrieb Andrew Willerding <
[email protected]>:

> Hi Svante,
>
> I apologize for this long posting in advance.  Below my message I have
> included three sections - my code, code output and the resultant FODT
> extract.
>
> Thank you for your suggestion and guidance.  I have implemented it but
> I'm having some issues with the result.  It doesn't appear that my
> modifications to the table get saved into the final document for some
> reason. The rows get appended but not with my cloned rows.
>
> In my code output below, I print out the xml of the table before I
> append the cloned row and again afterwards and it appears to be properly
> formed.  However in the actual document FODT file that I also include
> below, the row has been appended it doesn't appear to be with contents
> of my modified table!
>
> Is there something else I'm missing - some sort of "commit" or other
> modifications to the table element that need to be updated?
>
> Thanks,
>
> Andrew
>
>
> Here's the code extract that I have written.
>
> TextDocument template = TextDocument.loadDocument(templateFile);
> Table myTable = template.getTableByName(docSearchFieldName);
> Node myFirstRow = myTable.getRowByIndex(1).getOdfElement();
> System.out.println("@@@@@@MYTABLE-Before=" +
> myTable.getRowByIndex(1).getOdfElement().getParentNode());
>
>   List<List<String>> rowDatas = (List<List<String>>) fields.get(fieldName);
>       for (List<String> dataRow : rowDatas) {
>          if (myFirstRow != null) {
>               Integer cellIndex = 0;
>               Node myFirstRowClone = myFirstRow.cloneNode(true);
>               for (String cellData : dataRow) {
>                  Node cellNode =
> myFirstRowClone.getChildNodes().item(cellIndex++);
>                  cellNode.setTextContent(cellData);
>                  logItem("Template:" + templateFile.getName()
>                     + ",FieldName:" + fieldName
>                     + ",TableSetCellItem " + cellIndex + "=" + cellData,
>                     Level.DEBUG);
>               }
>              System.out.println("---myFirstRowClone=" + myFirstRowClone);
>
> myTable.getRowByIndex(1).getOdfElement().getParentNode().appendChild(myFirstRowClone);
>              System.out.println("@@@@@@MYTABLE-After=" +
> myTable.getRowByIndex(1).getOdfElement().getParentNode());
>              break;
>         }
>
> Here's the resultant output from the System.out statements:
>
> @@@@@@MYTABLE-Before=<table:table table:name="@TableReport"
> table:style-name="_40_TableReport"><table:table-column
> table:style-name="_40_TableReport.A"></table:table-column><table:table-column
>
> table:style-name="_40_TableReport.B"></table:table-column><table:table-column
>
> table:style-name="_40_TableReport.C"></table:table-column><table:table-header-rows><table:table-row><table:table-cell
>
> office:value-type="string" table:style-name="_40_TableReport.A1"><text:p
> text:style-name="P11">Application</text:p></table:table-cell><table:table-cell
>
> office:value-type="string" table:style-name="_40_TableReport.A1"><text:p
> text:style-name="P10">Code</text:p></table:table-cell><table:table-cell
> office:value-type="string" table:style-name="_40_TableReport.C1"><text:p
> text:style-name="P9">Count</text:p></table:table-cell></table:table-row></table:table-header-rows><table:table-row><table:table-cell
>
> office:value-type="string" table:style-name="_40_TableReport.A2"><text:p
> text:style-name="P13">1</text:p></table:table-cell><table:table-cell
> office:value-type="string" table:style-name="_40_TableReport.A2"><text:p
> text:style-name="P14">2</text:p></table:table-cell><table:table-cell
> office:value-type="string" table:style-name="_40_TableReport.C2"><text:p
>
> text:style-name="P15">3</text:p></table:table-cell></table:table-row></table:table>
>
>
> 2018-11-14,08:52:35:195,DEBUG,[http-nio-8080-exec-94],,Template:ActivityLogReport.odt,FieldName:@TableReport,Found
>
> table->@TableReport
>
> 2018-11-14,08:52:35:198,DEBUG,[http-nio-8080-exec-94],,Template:ActivityLogReport.odt,FieldName:@TableReport,TableSetCellItem
>
> 1=qd
>
> 2018-11-14,08:52:35:199,DEBUG,[http-nio-8080-exec-94],,Template:ActivityLogReport.odt,FieldName:@TableReport,TableSetCellItem
>
> 2=--ReportEndDate
>
> 2018-11-14,08:52:35:199,DEBUG,[http-nio-8080-exec-94],,Template:ActivityLogReport.odt,FieldName:@TableReport,TableSetCellItem
>
> 3=20181105
>
> ---myFirstRowClone=<table:table-row><table:table-cell
> office:value-type="string"
> table:style-name="_40_TableReport.A2">qd</table:table-cell><table:table-cell
>
> office:value-type="string"
> table:style-name="_40_TableReport.A2">--ReportEndDate</table:table-cell><table:table-cell
>
> office:value-type="string"
>
> table:style-name="_40_TableReport.C2">20181105</table:table-cell></table:table-row>
>
> @@@@@@MYTABLE-After=<table:table table:name="@TableReport"
> table:style-name="_40_TableReport"><table:table-column
> table:style-name="_40_TableReport.A"></table:table-column><table:table-column
>
> table:style-name="_40_TableReport.B"></table:table-column><table:table-column
>
> table:style-name="_40_TableReport.C"></table:table-column><table:table-header-rows><table:table-row><table:table-cell
>
> office:value-type="string" table:style-name="_40_TableReport.A1"><text:p
> text:style-name="P11">Application</text:p></table:table-cell><table:table-cell
>
> office:value-type="string" table:style-name="_40_TableReport.A1"><text:p
> text:style-name="P10">Code</text:p></table:table-cell><table:table-cell
> office:value-type="string" table:style-name="_40_TableReport.C1"><text:p
> text:style-name="P9">Count</text:p></table:table-cell></table:table-row></table:table-header-rows><table:table-row><table:table-cell
>
> office:value-type="string" table:style-name="_40_TableReport.A2"><text:p
> text:style-name="P13">1</text:p></table:table-cell><table:table-cell
> office:value-type="string" table:style-name="_40_TableReport.A2"><text:p
> text:style-name="P14">2</text:p></table:table-cell><table:table-cell
> office:value-type="string" table:style-name="_40_TableReport.C2"><text:p
> text:style-name="P15">3</text:p></table:table-cell></table:table-row><table:table-row><table:table-cell
>
> office:value-type="string"
> table:style-name="_40_TableReport.A2">qd</table:table-cell><table:table-cell
>
> office:value-type="string"
> table:style-name="_40_TableReport.A2">--ReportEndDate</table:table-cell><table:table-cell
>
> office:value-type="string"
>
> table:style-name="_40_TableReport.C2">20181105</table:table-cell></table:table-row></table:table>
>
> And here is the resultant FODT file extract of the table
>
>     <table:table table:name="@TableReport"
> table:style-name="_40_TableReport">
>      <table:table-column table:style-name="_40_TableReport.A"/>
>      <table:table-column table:style-name="_40_TableReport.B"/>
>      <table:table-column table:style-name="_40_TableReport.C"/>
>      <table:table-header-rows>
>       <table:table-row>
>        <table:table-cell table:style-name="_40_TableReport.A1"
> office:value-type="string">
>         <text:p text:style-name="P14">Application</text:p>
>        </table:table-cell>
>        <table:table-cell table:style-name="_40_TableReport.A1"
> office:value-type="string">
>         <text:p text:style-name="P13">Code</text:p>
>        </table:table-cell>
>        <table:table-cell table:style-name="_40_TableReport.C1"
> office:value-type="string">
>         <text:p text:style-name="P12">Count</text:p>
>        </table:table-cell>
>       </table:table-row>
>      </table:table-header-rows>
>      <table:table-row>
>       <table:table-cell table:style-name="_40_TableReport.A2"
> office:value-type="string">
>        <text:p text:style-name="P2">1</text:p>
>       </table:table-cell>
>       <table:table-cell table:style-name="_40_TableReport.A2"
> office:value-type="string">
>        <text:p text:style-name="P3">2</text:p>
>       </table:table-cell>
>       <table:table-cell table:style-name="_40_TableReport.C2"
> office:value-type="string">
>        <text:p text:style-name="P4">3</text:p>
>       </table:table-cell>
>      </table:table-row>
>      <table:table-row>
>       <table:table-cell table:style-name="_40_TableReport.A2"
> office:value-type="string">
>        <text:p text:style-name="Standard"/>
>       </table:table-cell>
>       <table:table-cell table:style-name="_40_TableReport.A2"
> office:value-type="string">
>        <text:p text:style-name="Standard"/>
>       </table:table-cell>
>       <table:table-cell table:style-name="_40_TableReport.C2"
> office:value-type="string">
>        <text:p text:style-name="Standard"/>
>       </table:table-cell>
>      </table:table-row>
>     </table:table>
>
> On 2018-11-12 2:23 p.m., Svante Schubert wrote:
> > Andrew,
> >
> > I forgot to mention to basic approaches.
> >
> >     1. Create the before and after state of the desired document in your
> ODF
> >     application of your choice. Save the document. Take a look at the
> XML you
> >     need to create.
> >     2. What I suggest and I am not sure if it exists is to go in the W3C
> DOM
> >     tree to the previous row and clone it, which is basic DOM
> functionality:
> >
> >
> https://xerces.apache.org/xerces-j/apiDocs/org/w3c/dom/Node.html#cloneNode(boolean)
> >
> > Now it should help!
> > Svante
> > ᐧ
> >
> > Am Mo., 12. Nov. 2018 um 18:47 Uhr schrieb Svante Schubert <
> > [email protected]>:
> >
> >> Hi Andrew,
> >>
> >>   Simple API is using underneath ODFDOM, which represents an ODF
> Document.
> >> The ODF Document is at least several zipped XML files.
> >> For instance, each XML of the content.xml is represented by a W3C DOM
> >> node. Therefore if you like to duplicate a row, being represented by a
> >> <table:table-row> element you may also duplicate the TableTableElement
> >> object.
> >>
> >> I guess the best way to proceed is to alter an existing test case of
> >> ODFDOM or Simple API.
> >>
> >> Hopefully this could help you!
> >> Svante
> >> ᐧ
> >>
> >> Am Mo., 12. Nov. 2018 um 02:24 Uhr schrieb Andrew Willerding <
> >> [email protected]>:
> >>
> >>> Hi Svante,
> >>>
> >>> Thank you for your reply.  I'm finding it difficult to find out what I
> >>> need to Google to follow the path you suggested below. Do you have some
> >>> examples or web sites or books that you could recommend as a good
> >>> starting point?
> >>>
> >>> Thanks,
> >>>
> >>> Andrew
> >>>
> >>> On 2018-11-10 4:32 a.m., Svante Schubert wrote:
> >>>> Hi Andrew,
> >>>>
> >>>> likely Simple API has not implemented that feature, but Simple API
> >>> relies
> >>>> on ODFDOM and that uses W3C DOM, so you might consider to clone/copy
> the
> >>>> previous table row.
> >>>> Best is to take a look into the ODF XML to check if there are any IDs
> >>> you
> >>>> might need to adjust.
> >>>>
> >>>> Have a nice weekend,
> >>>> Svante
> >>>>
> >>>> PS: I am personally using ODFDOM only, for instance currently I am
> >>>> extracting table data from an EU specification to generate source code
> >>> from.
> >>>>
> >>>> Am Mi., 7. Nov. 2018 um 22:37 Uhr schrieb Andrew Willerding <
> >>>> [email protected]>:
> >>>>
> >>>>> Hi,
> >>>>>
> >>>>> I have an existing table that I am appending rows to and I want the
> new
> >>>>> rows to have the same font, alignment, etc as the rows previous to
> the
> >>>>> additions but I'm finding that the new rows appear in the default
> >>>>> document font style.
> >>>>>
> >>>>> He's a snippet of code I've used to try to manipulate the cell fonts.
> >>>>>
> >>>>>                               Cell cellItem =
> >>>>> newRow.getCellByIndex(cellIndex++);
> >>>>>                                cellItem.setStringValue(cell);
> >>>>>                                if (firstRow != null) {
> >>>>>                                    System.out.println("Cell=" +
> >>>>> firstRow.getCellByIndex(cellIndex - 1).getStringValue());
> >>>>>                                    // System.out.println("Cell=" +
> >>>>> firstRow.getCellByIndex(cellIndex -
> >>>>> 1).getHorizontalAlignmentType().getAlignmentString());
> >>>>>                                    System.out.println("Cell=" +
> >>>>> firstRow.getCellByIndex(cellIndex - 1).getCellStyleName());
> >>>>>                                    System.out.println("Cell=" +
> >>>>> firstRow.getCellByIndex(cellIndex - 1).getStyleHandler());
> >>>>>                                   //
> >>>>> cellItem.setHorizontalAlignment(firstRow.getCellByIndex(cellIndex -
> >>>>> 1).getHorizontalAlignmentType());
> >>>>> //cellItem.setFont(firstRow.getCellByIndex(cellIndex -1).getFont());
> >>>>> //cellItem.getFont().setSize(firstRow.getCellByIndex(cellIndex
> >>>>> -1).getFont().getSize() - 2);
> >>>>> cellItem.getStyleHandler().setFont(firstRow.getCellByIndex(cellIndex
> -
> >>>>> 1).getStyleHandler().getFont(Document.ScriptType.WESTERN));
> >>>>>                                    //
> >>>>> cellItem.setCellStyleName(firstRow.getCellByIndex(cellIndex -
> >>>>> 1).getCellStyleName());
> >>>>>                                }
> >>>>>
> >>>>> Except for the actual value of the cell, what prints out with the
> >>>>> System.out statements is not the actual font, font size, etc of the
> >>> cell.
> >>>>> Is this a bug or am I not accessing and setting the values correctly?
> >>>>> I've been referencing this web page for trying to get my code to work
> >>>>>
> >>>>>
> >>>>>
> >>>
> https://incubator.apache.org/odftoolkit/simple/document/cookbook/Style%20Handling.html#Advanced%20font%20handling
> >>>>> Thanks,
> >>>>>
> >>>>> Andrew
> >>>>>
> >>>>> P.S.  This list is very quiet but I'm hoping someone is reading it
> from
> >>>>> time to time.
> >>>>>
> >>>>>
>

Reply via email to