# Word + win32ole - how to find formatting of a word?

**URL:** <https://www.ruby-forum.com/t/word-win32ole-how-to-find-formatting-of-a-word/151768>\
**Category:** Ruby\
**Created:** [October 25, 2008, 10:34am UTC](https://www.ruby-forum.com/t/word-win32ole-how-to-find-formatting-of-a-word/151768 "2008-10-25T10:34:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 25, 2008, 10:34am UTC](https://www.ruby-forum.com/t/word-win32ole-how-to-find-formatting-of-a-word/151768/1 "2008-10-25T10:34:59Z")

</div>

HI! I’m trying to use Ruby and win32ole to parse a Word document. So  
far, I’m able to extract the style and text of each paragraph. That  
works great to convert it into individual divs (in the HTML CSS sense).

Now, inside the paragraphs, there are certain words that have special  
formatting (for e.g. the name of a command which is in monospace) - I’m  
trying to find how to extract those special cases. Does anyone know how  
to achieve that?

Appreciate your help - thanks!

Cheers,  
Mohit.  
10/25/2008 | 4:33 PM.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 25, 2008, 4:35pm UTC](https://www.ruby-forum.com/t/word-win32ole-how-to-find-formatting-of-a-word/151768/2 "2008-10-25T16:35:02Z")

</div>

> HI! I’m trying to use Ruby and win32ole to parse a Word document. So  
> far, I’m able to extract the style and text of each paragraph. That  
> works great to convert it into individual divs (in the HTML CSS sense).
> 
> Now, inside the paragraphs, there are certain words that have special  
> formatting (for e.g. the name of a command which is in monospace) - I’m  
> trying to find how to extract those special cases. Does anyone know how  
> to achieve that?

Dear Mohit,

you could save the Word file as an html and then extract the relevant  
information…  
I did that using OpenOffice and got a file containing the font  
information in the following form.

A command in Linux Libertine

A text in Bitstream Charter

If you read in the text of that file as a String, you can then find the  
relevant bits using regexps.

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 26, 2008, 10:49am UTC](https://www.ruby-forum.com/t/word-win32ole-how-to-find-formatting-of-a-word/151768/3 "2008-10-26T10:49:25Z")

</div>

Axel E. wrote:

> Dear Mohit,

Hi Axel

Thanks for replying! Converting to HTML and working with that is my  
last option actually. In a well-written document, I found that using  
Word to return style information about the paragraph is a lot less work  
and relatively easy to work with. I guess it’s time to consider your  
suggestion!

Cheers,  
Mohit.  
10/26/2008 | 5:44 PM.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 26, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/word-win32ole-how-to-find-formatting-of-a-word/151768/4 "2008-10-26T14:15:32Z")

</div>

Mohit S. wrote:

> > >
> 
> Thanks for replying! Converting to HTML and working with that is my  
> last option actually. In a well-written document, I found that using  
> Word to return style information about the paragraph is a lot less  
> work and relatively easy to work with. I guess it’s time to consider  
> your suggestion!

Actually, after digging around, I found that this gets me somewhere  
there:  
words = doc.Words  
words.each {|w|  
index += 1  
ft = w.Font.Name  
ftHash[ft] = 1  
}

Thanks for your help!

Cheers,  
Mohit.  
10/26/2008 | 9:14 PM.

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 26, 2008, 9:30pm UTC](https://www.ruby-forum.com/t/word-win32ole-how-to-find-formatting-of-a-word/151768/5 "2008-10-26T21:30:34Z")

</div>

-------- Original-Nachricht --------

> Datum: Sun, 26 Oct 2008 22:14:53 +0900  
> Von: Mohit S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: Re: Word + win32ole - how to find formatting of a word?

> > > > Does anyone know how to achieve that?
> 
> ft = w.Font.Name  
> ftHash[ft] = 1  
> }
> 
> Thanks for your help!
> 
> Cheers,  
> Mohit.  
> 10/26/2008 | 9:14 PM.

Dear Mohit,

you’re welcome 🙂  
It’s always nice to best answer one’s own questions , isn’t it ? Thanks  
for the info !

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![mohits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bbe5ce/32.png) [@mohits](https://www.ruby-forum.com/u/mohits)\
**Post date:** [October 27, 2008, 4:21am UTC](https://www.ruby-forum.com/t/word-win32ole-how-to-find-formatting-of-a-word/151768/6 "2008-10-27T04:21:21Z")

</div>

Axel E. wrote:

> you’re welcome 🙂  
> It’s always nice to best answer one’s own questions , isn’t it ? Thanks for the info !

Thanks for your reply again! Yes, it’s good to find the answer yourself  
and then share it 🙂

I find that Win32ole is quite powerful, just that it needs a little  
looking around to work with it.

Cheers,  
Mohit.  
10/27/2008 | 11:19 AM.
