Please Help me how. RRS feed

  • Question

  • Dear Sirs.

    Please Help me. I have Task Change all Character "a" formated with font ="a" size ="10" to Characte "b" formated with font "b" and Size "11" and may be with Bold.

    Please help me undertand how to do this task with OpenXML SDK

    Thank you in Advance.
    Irakli Lomidze
    Tuesday, February 9, 2010 7:47 PM

All replies

  • Hello Irakli,

    All Word content text are stored in <w:t> Text() element. <w:t> element is stored in <w:r> where we can specify font and size for a text string.

    I think, we need to find all w:t element. If it contains the character "a", we split the string from "a" character, make two copies the orginal <w:r> fill with strings before and after the character "a".

    And between the two elements, we insert a new w:r and fill it with "a" character. We specify character "a"'s font and size in the <w:r>.

    But if there is a series of "a" characters. The algorithm will be more complicated. So I think this is a complicated task, we may have to think out and write an alogrithm for this.  Comparing to OpenXML SDK, using COM API to do this task would be much simpler. So could the COM API be in your consideration?

    Best regards,
    Ji Zhou
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, February 11, 2010 6:52 AM
  • Hello Ji Zhou

    Thanks for Reply. About  COM API Do you mean Word Automation ? Word Automation Is very Very Very Very Sloooooow.
     I Need do this job for 100 000 Document. So There is Imposilbe to do it with Word Automation.

    Is There Any Better Way to do it ?

    Irakli Lomidze
    Monday, February 15, 2010 9:36 AM
  • This should be easy to accomplish with the SDK. There are two ways to specify character level formatting in Word documents:
    1. Via direct formatting
    2. Via styles

    The direct formatting approach is easy. All you need to do is look at the run properties for a particular run to see if a given font and font size is applied. If so, then grab the text in that run and change character 'a' to 'b'.

    The styles approach requires you to look in the styles.xml part. You need to find all character level formatting styles that have a given font and font size specified. Then you need to look at all runs within your document that have that style applied. Again you will need to look at the run properties.

    Essentially you need to write a method that returns run that satisfy either of the conditions above.

    Hope that helps.
    Zeyad Rajabi (MS)
    Thursday, February 18, 2010 6:25 AM