none
Programmatically duplicate a table row in a RTF file RRS feed

  • Question

  • I need to duplicate  a table row  in a RTF file. I am struggling to understand the definition of what I need to copy and duplicate.

     

    My process at the moment is as follows.

    1.       I search in the RTF data for a string that I know is in a table cell.  In this case <<[QL]
    2.       This row has two cells.
    3.       I then search backwards from this to find the \trowd control character
    4.       From this point I search backwards again to find the start of the group i.e. “{“
    5.       Then from my tag <<[QL>> I search for the end of the row. The \row control character
    6.       From this point I search for the closing “}” of the group
    7.       I then copy this string as the row template
    8.       I then create another string by appending by duplicating the row template , for each appending I change \irowN and \irowbandN with the next number i.e. irow1
    9.       I also check if there is a control character \lastrow if it is not the last row I remove this.
    10.    I now expect this string to have four rows of data.
    11.    I duplicate these by replacing the row template with 4 of these i.e. appending this row template 4 times
    12.    I then write back the file contents.

     

    When I open the RTF file I get an error and the repair tool indicates an error of “Table end-of-cell-markers”

     

    My row template looks like this :

    "{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 \trowd \irow0\irowband0\ltrrow\ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr

    \brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 \trftsWidth1\trftsWidthB3\trftsWidthA3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid16582897\tbllkhdrrows\tbllkhdrcols\tbllknocolband\tblind0\tblindtype3

    \clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth5057\clshdrawnil \cellx4949\clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr

    \brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth4185\clshdrawnil \cellx9134\row \ltrrow}\pard\plain \ltrpar\ql \li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\yts15 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0

    \f31506\fs22\lang2057\langfe1033\cgrid\langnp2057\langfenp1033 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 <<[QL]itemDec>>\cell }\pard \ltrpar\ql \li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\pararsid16582897\yts15 {

    \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 <<[QL]item}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 Qty}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 >>}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 \cell }\pard\plain \ltrpar

    \ql \li0\ri0\sa200\sl276\slmult1\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang2057\langfe1033\cgrid\langnp2057\langfenp1033 {\rtlch\fcs1 \af0 \ltrch\fcs0

    \insrsid16582897 \trowd \irow1\irowband1\lastrow \ltrrow\ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10

    \trftsWidth1\trftsWidthB3\trftsWidthA3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid16582897\tbllkhdrrows\tbllkhdrcols\tbllknocolband\tblind0\tblindtype3 \clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb

    \brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth5057\clshdrawnil \cellx4949\clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth4185\clshdrawnil \cellx9134

    \row }"

     

    My duplicated rows now look like this :

     

    " {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 \trowd \irow0\irowband0\ltrrow\ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr

    \brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 \trftsWidth1\trftsWidthB3\trftsWidthA3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid16582897\tbllkhdrrows\tbllkhdrcols\tbllknocolband\tblind0\tblindtype3

    \clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth5057\clshdrawnil \cellx4949\clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr

    \brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth4185\clshdrawnil \cellx9134\row \ltrrow}\pard\plain \ltrpar\ql \li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\yts15 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0

    \f31506\fs22\lang2057\langfe1033\cgrid\langnp2057\langfenp1033 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 <<[QL]_0itemDec>>\cell }\pard \ltrpar\ql \li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\pararsid16582897\yts15 {

    \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 <<[QL]_0item}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 Qty}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 >>}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 \cell }\pard\plain \ltrpar

    \ql \li0\ri0\sa200\sl276\slmult1\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang2057\langfe1033\cgrid\langnp2057\langfenp1033 {\rtlch\fcs1 \af0 \ltrch\fcs0

    \insrsid16582897 \trowd \irow1\irowband1 \ltrrow\ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10

    \trftsWidth1\trftsWidthB3\trftsWidthA3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid16582897\tbllkhdrrows\tbllkhdrcols\tbllknocolband\tblind0\tblindtype3 \clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb

    \brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth5057\clshdrawnil \cellx4949\clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth4185\clshdrawnil \cellx9134

    \row } {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 \trowd \irow0\irowband0\ltrrow\ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr

    \brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10 \trftsWidth1\trftsWidthB3\trftsWidthA3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid16582897\tbllkhdrrows\tbllkhdrcols\tbllknocolband\tblind0\tblindtype3

    \clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth5057\clshdrawnil \cellx4949\clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr

    \brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth4185\clshdrawnil \cellx9134\row \ltrrow}\pard\plain \ltrpar\ql \li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\yts15 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0

    \f31506\fs22\lang2057\langfe1033\cgrid\langnp2057\langfenp1033 {\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 <<[QL]_1itemDec>>\cell }\pard \ltrpar\ql \li0\ri0\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0\pararsid16582897\yts15 {

    \rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 <<[QL]_1item}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 Qty}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 >>}{\rtlch\fcs1 \af0 \ltrch\fcs0 \insrsid16582897 \cell }\pard\plain \ltrpar

    \ql \li0\ri0\sa200\sl276\slmult1\widctlpar\intbl\wrapdefault\aspalpha\aspnum\faauto\adjustright\rin0\lin0 \rtlch\fcs1 \af0\afs22\alang1025 \ltrch\fcs0 \f31506\fs22\lang2057\langfe1033\cgrid\langnp2057\langfenp1033 {\rtlch\fcs1 \af0 \ltrch\fcs0

    \insrsid16582897 \trowd \irow1\irowband1\lastrow \ltrrow\ts15\trgaph108\trleft-108\trbrdrt\brdrs\brdrw10 \trbrdrl\brdrs\brdrw10 \trbrdrb\brdrs\brdrw10 \trbrdrr\brdrs\brdrw10 \trbrdrh\brdrs\brdrw10 \trbrdrv\brdrs\brdrw10

    \trftsWidth1\trftsWidthB3\trftsWidthA3\trautofit1\trpaddl108\trpaddr108\trpaddfl3\trpaddft3\trpaddfb3\trpaddfr3\tblrsid16582897\tbllkhdrrows\tbllkhdrcols\tbllknocolband\tblind0\tblindtype3 \clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb

    \brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth5057\clshdrawnil \cellx4949\clvertalt\clbrdrt\brdrs\brdrw10 \clbrdrl\brdrs\brdrw10 \clbrdrb\brdrs\brdrw10 \clbrdrr\brdrs\brdrw10 \cltxlrtb\clftsWidth3\clwWidth4185\clshdrawnil \cellx9134

    \row }"

     

     

    My specific questions are

    1.       Is this the correct way to identify a row of data in RTF
    2.       When I duplicate do I need something else between the rows? If I look a the source of a RTF file is see some \pard data but even putting this in does not help
    3.       Any idea why this is invalid RTF ?

    Scott

    Friday, November 8, 2013 9:16 AM

All replies

  • Which technology are you using? VB or C# or others?

    What do you mean by "the repair tool"?

    What's the error message?

    I mentioned that you post this question on Word forum, Is it related to Word?

    Monday, November 11, 2013 7:00 AM