none
unable to repeat table code with drawings. RRS feed

  • Question

  • I am not able to open the file generated.

    So I click Ok and some how opened the file and save it with diff. name. Then I was able to open it.

    I compared the 2 files using OPENXML Productivity Tool but was not able to find the differences. I am attaching the file so you can review.

    I am trying to generate a table multiple times but I think the Ids are being duplicated.

     

     

     Body body1 = new Body();
                body1
    .Append(GenerateTable());
                body1
    .Append(new Paragraph(new Run(new Break() { Type = BreakValues.Page })));
                body1
    .Append(GenerateTable());

     

    When I create the second table, that's where the problem comes using dup ids.

    I think the problem is 

     Wp.DocProperties docProperties1 = new Wp.DocProperties() { Id = (UInt32Value)1U, Name = "Straight Connector 1" };

    I have five lines that are generated in the table so when I have the second table the ids of these lines are duplicated.

    any idea how i can autogenerate the ids

    Download the document here

    Thanks

    Thursday, October 3, 2013 11:47 PM

Answers

  • I think you need to show us the code in GenerateTable so that we can understand what it's doing...

    You show us a line of code for a DocProperty. Is this supposed to be a CustomDocumentProperty? If you view the document after it's been repaired so that Word can open it and look at the Custom Document Properties do you find any? How many? Do they contain the information you expect? (Note: CustomDocumentProperties are stored in a CustomXMLPart file, not in document.xml so you may not be looking in the right place in the Productivity Tool)

    <<any idea how i can autogenerate the ids>>

    The usual way is to set up as variable at the class level that acts as a "counter". You increment it by 1 every time you go through a loop that uses it. Append the value of the counter to the basic string you use for the Id.

    However, a custom document property is NOT a DocProperty - that's associated with DRAWING object. If you want a custom document property you need to work with a CustomFileProperties Part and the CustomProperties namespace. See

    http://msdn.microsoft.com/en-us/library/office/hh674468.aspx
    http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.customproperties


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 4, 2013 3:28 PM
    Moderator