I am up against a MS Word text formatting problem and wondered if there were any Regular Expression geeks who also use MS Word out there (unlikely, I know...)
I am trying to wrap a sentenc开发者_如何学运维e that appears in italics in Word, using XML markup, e.g.
Text in italics
would become
<i>Text in italics</i>
I can do it for individual words, e.g.
<i>Text</i> <i>in</i> <i>italics</i>
but am having a tough time working out how to find the beginning and the end of a group of italicized text, rather than just individual words.
The only solution i have so far is to export the MS Word doc as wML and do the following:
<w:r w:rsidRPr="00FE6181">
<w:t><hi></w:t>
</w:r>
<w:r w:rsidR="00D555A7" w:rsidRPr="00D77C71">
<w:rPr>
<w:i/>
</w:rPr>
<w:t xml:space="preserve">Text in italics</w:t>
</w:r>
<w:r w:rsidRPr="00FE6181">
<w:t><</w:t>
</w:r>
and then reopen the doc in word. It's just a bit involved to roll out as a solution to a non-technical user.
It looks like this should be possible using RegExps (or maybe VBScript) I just don't know how to get there.
Any help appreciated
thanks
You should be able to do something like that with a VBA macro, using the FIND object.
ie
set find = WordApp.ActiveDocument.Contents.Range.Find
You'd specify the text to find as *
and then specify the formatting as italics. that would find all the text that's formatted with italics.
BUT... Here's the rub, if the user formatted a phrase in italics, they +might+ have formatted the whole phrase, or they might have formatted each word seperately, so you might "find" a single phrase, but you might find 3 seperate words each formatted italics.
To work around +that+ problem would be quite difficult.
精彩评论