# Tables word problem in Ruby

**URL:** <https://www.ruby-forum.com/t/tables-word-problem-in-ruby/155535>\
**Category:** Ruby\
**Created:** [December 13, 2008, 3:54am UTC](https://www.ruby-forum.com/t/tables-word-problem-in-ruby/155535 "2008-12-13T03:54:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hai\_l](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@hai\_l](https://www.ruby-forum.com/u/hai_l)\
**Post date:** [December 13, 2008, 3:54am UTC](https://www.ruby-forum.com/t/tables-word-problem-in-ruby/155535/1 "2008-12-13T03:54:05Z")

</div>

My problem is about table in Word. With Ruby I can access, modify, save  
as… word document to txt document. But I don’t find the code to work  
with tables. I see that every tables is destroyed its format if I save  
as word format-\> txt format. Have anybody know about the issue ? I only  
want the code detect tables and maintain it. If unfortunately, we have  
no way maintain, we can remove all tables from txt document (because  
it’s not necessary)

---

<div class="post-metadata">

**Author:** ![hai\_l](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@hai\_l](https://www.ruby-forum.com/u/hai_l)\
**Post date:** [December 13, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/tables-word-problem-in-ruby/155535/2 "2008-12-13T14:52:12Z")

</div>

Hai anh Le wrote:

> My problem is about table in Word. With Ruby I can access, modify, save  
> as… word document to txt document. But I don’t find the code to work  
> with tables. I see that every tables is destroyed its format if I save  
> as word format-\> txt format. Have anybody know about the issue ? I only  
> want the code detect tables and maintain it. If unfortunately, we have  
> no way maintain, we can remove all tables from txt document (because  
> it’s not necessary)

My first thought is that you could convert your tables to tab-delimited  
text prior to saving the document. This can be done by calling the  
ConvertToText method on each table, passing it a value of 1  
(wdSeparateByTabs):

Where doc is your Word document object:

for table in doc.Content.Tables  
table.ConvertToText(1)  
end

Does that help?

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

> **[Ruby on Windows](http://rubyonwindows.blogspot.com/search/label/word)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![hai\_l](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@hai\_l](https://www.ruby-forum.com/u/hai_l)\
**Post date:** [December 15, 2008, 4:53am UTC](https://www.ruby-forum.com/t/tables-word-problem-in-ruby/155535/3 "2008-12-15T04:53:24Z")

</div>

Hi David

Thank very much for your help. I test both VBA code in word document and  
Ruby code. The result is very good 🙂

I have small query. I want to read word document, convert it to plain  
text and display in website, then find some word follow special  
requirement (don’t find in tables). So I have idea that I will convert  
word document to plain text; mark begin, end point of tables by some  
special symbol. It help me to recognize and don’t search in table area.  
Your blog is very useful. I have found many information in the past. I  
find the code to add some characters into word document but I can’t  
search more information in order to working with tables. Do you know  
about the way to recognize begin and end of tables?

I want to display table with border(e.g. box border). And are you have  
any way to do it?

Hai Anh

Ps : Can I contact with you by email?

David M. wrote:

> My first thought is that you could convert your tables to tab-delimited  
> text prior to saving the document. This can be done by calling the  
> ConvertToText method on each table, passing it a value of 1  
> (wdSeparateByTabs):
> 
> Where doc is your Word document object:
> 
> for table in doc.Content.Tables  
> table.ConvertToText(1)  
> end
> 
> Does that help?
> 
> David
> 
> [http://rubyonwindows.blogspot.com](http://rubyonwindows.blogspot.com)  
> [Ruby on Windows: word](http://rubyonwindows.blogspot.com/search/label/word)

---

<div class="post-metadata">

**Author:** ![hai\_l](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@hai\_l](https://www.ruby-forum.com/u/hai_l)\
**Post date:** [December 16, 2008, 3:28am UTC](https://www.ruby-forum.com/t/tables-word-problem-in-ruby/155535/4 "2008-12-16T03:28:45Z")

</div>

Anyone?
