Categories > OpenTBS with DOCX >

Manually creating xml to insert into document.xml

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: hemocyanin
Date: 2013-12-09
Time: 23:59

Manually creating xml to insert into document.xml

I'm wondering if there is a way that I can create the xml I want on the PHP side, and then just slap into various spots in my document.xml file.  I realize that is what openTBS does, but I'm having performance issues with a large complicated multipage table.  I'd like to let openTBS do the lions share of the work, but "manually" create certain parts in my PHP code and then stick that into various spots in the documents.  Is there a function that will allow this?
By: Skrol29
Date: 2013-12-10
Time: 00:15

Re: Manually creating xml to insert into document.xml

Hi,

The property $TBS->Source contains the XML source of the "document.xml" file.
You can modify it.
Use your own placeholders or markers in order to change the contents.
The method $TBS->GetBlockSource() can help you to get e piece of the XML source relative to TBS blocks.
The method $TBS->MergeBlock() can replace a TBS block with a XML contents of yours.
By: hemocyanin
Date: 2013-12-10
Time: 01:42

Re: Manually creating xml to insert into document.xml

This is very interesting but I'm not sure I'm really understanding how to use it.

Here's what I did:
$junkText=array();
$junkText[]=array('junk'=>'<w:p><w:pPr><w:pStyle w:val="Standard"/></w:pPr></w:p>
<w:p><w:pPr><w:pStyle w:val="Standard"/><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
<w:sz w:val="20"/></w:rPr></w:pPr><w:r><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/><w:sz w:val="20"/>
</w:rPr><w:t>JUNK TEXT TO INSERT</w:t></w:r></w:p>');

(note, I inserted some hard returns here so it wouldn't display super wide -- in my code though, it is a single line)
...

$TBS->MergeBlock('junkText', $junkText);

...

in my template:

[junkText.junk]

When I load the document, rather than seeing "JUNK TEXT TO INSERT" as its own paragraph -- I see the entire XML string, from <w:p> to </w:p>.

I don't really want to modify any existing xml, I just want to inject some of my own -- what's the easiest way to do that?
By: Skrol29
Date: 2013-12-13
Time: 10:38

Re: Manually creating xml to insert into document.xml

In order to prevent the conversion into viewable string, you have to use parameter "strconv=no".
[junkText.junk;strconv=no]

If you don't actually have a block but just a single value, you can use MergeFields():
$junkText = '<w:p>...</w:p>';
$TBS->MergeFields('junkText', $junkText);
[junkText;strconv=no]

If your bound is defined by a block, you can also use:
$junkText = '<w:p>...</w:p>';
$TBS->MergeBlock('junkText', 'text', $junkText);
[junkText;block=tbs:cell]
By: hemocyanin
Date: 2013-12-18
Time: 00:42

Re: Manually creating xml to insert into document.xml

Thank you this is great -- it really did the trick.  My document builds in about 2 seconds -- I build all the table rows in my PHP and then just do a text mergeblock as you suggested.  This has me down from 7-12 seconds, which is long enough for people to try clicking twice, to two seconds, which is just fine.

Thanks again for the help -- I really appreciate it.