Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6151331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:45:18+00:00 2026-05-23T19:45:18+00:00

I have a docx document that I want to modify via OpenXML SDK. This

  • 0

I have a docx document that I want to modify via OpenXML SDK. This document has a table with bookmarks in its cells. The cells have specific font settings, let’s say it’s Times New Roman, 14pt. When I try to insert some text like this:

    public void ReplaceBookmark(string bookMarkName, string text)
    {
        var bookmarkStart =
            _document.MainDocumentPart.RootElement.Descendants<BookmarkStart>()
        .Where(p => p.Name == bookMarkName)
        .FirstOrDefault();
        if (bookmarkStart == null)
            return;

        bookmarkStart.InsertAfterSelf(new Run(new Text(text)));            
    }

the texts is inserted, but its style is set Calibri, 11pt (the default style). How can I insert the text so that the font settings are preserved? The important thing is that i shouldn’t define any style settings in the code, but use those of the original document instead.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:45:19+00:00Added an answer on May 23, 2026 at 7:45 pm

    I did a little investigating of the docx file format. Obviously I can’t talk specifically about the file you are using… but I thought you might be interested in what I found.

    If you create a copy of the docx file and give it a .zip extension, you can then extract out the contents of the document. In my case, and probably in yours too, the main part of the document is in the extracted file [Extraction Base Path]\word\document.xml.

    The following XML snippet is the one that appears to apply to the first cell in the table (for the document I created):

    <w:tc>
        <w:tcPr>
            <w:tcW w:w="3192" w:type="dxa"/>
        </w:tcPr>
        <w:p w:rsidR="006C4430" w:rsidRPr="006C4430" w:rsidRDefault="006C4430">
            <w:pPr>
                <w:rPr>
                    <w:rFonts w:ascii="Ariel" w:hAnsi="Ariel"/>
                    <w:sz w:val="28"/>
                    <w:szCs w:val="28"/>
                </w:rPr>
            </w:pPr>
            <w:bookmarkStart w:id="0" w:name="First"/>
            <w:bookmarkEnd w:id="0"/>
            <w:r w:rsidRPr="006C4430">
                <w:rPr>
                    <w:rFonts w:ascii="Bauhaus 93" w:hAnsi="Bauhaus 93"/>
                    <w:sz w:val="28"/>
                    <w:szCs w:val="28"/>
                </w:rPr>
                <w:t>Here is some text</w:t>
            </w:r>
        </w:p>
    </w:tc>
    

    As you can see, the w:bookmarkStart and w:bookmarkEnd tags occur outside of the table’s actual content (which appear to be the w:r tag following the bookmark). This happened even though I had selected the entire cell contents before creating the bookmark. As a result, I suspect that any call made to bookmarkStart.InsertAfterSelf will, as you saw, use the default font settings, not any settings associated with the table cell. It looks to me as if you would need to either navigate to the run immediately after the bookmark, and insert your text there, or copy the settings (presumably the contents of the w:rPr tag) from the next run into the new run that you create.

    Hopefully this will point you in the appropriate direction. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a word document (docx format) that I need to populate with data
I have a Document object that looks like this: public class Document { public
I have a bit of code that will open a Word 2007 (docx) document
I have a template in word (.docx) format and want to replace some placeholders
I have some code that uses Open XML to open up a .docx file,
Consider I have an anchor which looks like this <div class=res> <a href=~/Resumes/Resumes1271354404687.docx> ~/Resumes/Resumes1271354404687.docx
I have a document that I have included in my VS 2010 solution. It
We have a web application that displays a variety of document types to the
I have an input string that's generated as in following example: string.Format(Document {0}, was
I have a vbscript file that will open a document with the correct program

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.