5

While working on a word template, there was a need to put repeat blocks in an IF field, similar to this:

WordTemplate sample code using .DOC/.DOCX:

{ IF {MERGEFIELD DataSource1.FieldName}=”123456” “IF SECTION
Then a repeat block here using a table row that is bookmarked:

    ------------------------------------------------------------
    | «Datasource1.IdColHeader»  | «Datasource1.NameColHeader» |
    ------------------------------------------------------------
    |«RepeatingDatasource2.Id»   | «RepeatingDatasource2.Name» |
    ------------------------------------------------------------

” “Else Section
   Second set of repeat block with different datasource
    -------------------------------------------------------
    | Id                      | Name                      |
    -------------------------------------------------------
    |«RepeatingDatasource3.Id»|«RepeatingDatasource3.Name»|
    -------------------------------------------------------
”}

C# sample code using WordWriter's WordTemplate:

private static void ProcessWordTemplate(WordTemplate docTemp)
{
    try
    {
        docTemp.Process();
    }
    catch (Exception ex)
    {
        throw new ApplicationException(ex.Message);
    }
}

For a DOCX WordTemplate, the error occurs when docTemp.Process() is called. I get the following exception:

Exception Type: System.Application
Exception Message: WordWriter Error: Bookmarks cannot be rewritten

For a DOC WordTemplate, the documents was rendered but it only shows one row in the repeat block even if the actual result is more than 1.

But, if it is the other way around, an IF field in a repeat block, the IF field and the repeat block where successfully evaluated. The resulting document shows all the records.

Please note that I'm using OfficeWriter's WordWriter Version 9.

CSDev
  • 3,177
  • 6
  • 19
  • 37
shiego926
  • 51
  • 3
  • 1
    What is the exception you get? Also you may want to play with your bookmark on the table row, try it in different positions a slight change in the end of the bookmark can have different meanings. See this page: http://wiki.softartisans.com/display/WW9/Creating+a+Grouped+and+Nested+Document which shows you exactly how the row should be selected. – Sam Plus Plus May 06 '15 at 20:41
  • I get _WordWriter Error: Bookmarks cannot be rewritten_. Updated the details above to include the exception details. Good catch. Regarding your suggestion, yes I did try different position but got the same result or worst a different error. But I'll check out softartisan's page and maybe it will give me other clues. Thanks Sam! @SamPlusPlus – shiego926 May 07 '15 at 05:36
  • I tried working out @SamPlusPlus suggestion but it didn't work. So, we ended up using different document templates for the if conditions that contains **repeat block**. But, I'll keep this open if there will be any other comments or, if in case someone already has a solution for this issue. – shiego926 Jun 09 '15 at 10:51

0 Answers0