0
votes

does anybody know how to use frames in wordprocessingdocument using the openxml sdk v 2.5 ? I'm using the openxml sdk v 2.5 to edit docx files in a WPF application. I have several Objects like Tables Text and Images and i want a frame around them, so they won't split at the end of a page.

tried this:

Frame frame = new Frame(xmlElementList);
document.MainDocumentPart.Document.AppendChild(frame);

but after adding the frame to the document the docx file is not valid and cannot be open in word

1
Create a small, sample document in Word then open it in the Open XML SDK Productivity Tool. That will show you the basic code to generate the document or the section of XML you have selected - including the Frame. Looking at your code, I'm guessing you're missing some "bits and pieces" that integrate the frame into the document. For example, a Frame must certainly have a Paragraph with a Run...Cindy Meister

1 Answers

1
votes

You can create ParagraphProperties and add it to your Paragraph like this

ParagraphProperties paragraphProperties = new ParagraphProperties 
{ 
    KeepNext = new KeepNext(), 
    FrameProperties = new FrameProperties 
    { 
        HorizontalSpace = "141", 
        Wrap = TextWrappingValues.Around, 
        HorizontalPosition = HorizontalAnchorValues.Text, 
        VerticalPosition = VerticalAnchorValues.Text, Y = "1" 
    } 
 };

Paragraph paragraph=new Paragraph();
paragragh.ParagraphProperties =paragraphProperties;