# Newbie

**URL:** <https://www.ruby-forum.com/t/newbie/138049>\
**Category:** Rails\
**Created:** [May 19, 2008, 8:39pm UTC](https://www.ruby-forum.com/t/newbie/138049 "2008-05-19T20:39:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fred](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/db5fbb/32.png) [@fred](https://www.ruby-forum.com/u/fred)\
**Post date:** [May 19, 2008, 8:39pm UTC](https://www.ruby-forum.com/t/newbie/138049/1 "2008-05-19T20:39:32Z")

</div>

Hello  
New to ruby 🙂  
i have to current code :  
xml.Worksheet ‘ss:Name’ =\> ‘Sheet1’ do

```
    xml.Table do

      # Header
      xml.Row do

        for column in @model.content_columns do
          xml.Cell do
            xml.Data column.human_name, 'ss:Type' => 'String'
          end
        end
      end

      # Rows
      for record in @export
        xml.Row do
          for column in @model.content_columns do
            xml.Cell do
              xml.Data record.send(column.name), 'ss:Type' =>

```

‘String’  
end  
end  
end  
end

```
    end
  end

```

it does extract data to an excel worksheet.  
Where @model is the model name ( ex: User)  
and @export is record set( ex: @export=User.find(:all) )

i want to eliminate some columns of being extracted. Let’s say i want  
to export just the first\_name and not the whole table  
Any suggestion will be appreciated  
Thank you  
Fred

---

<div class="post-metadata">

**Author:** ![fred](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/db5fbb/32.png) [@fred](https://www.ruby-forum.com/u/fred)\
**Post date:** [May 19, 2008, 9:00pm UTC](https://www.ruby-forum.com/t/newbie/138049/2 "2008-05-19T21:00:42Z")

</div>

On May 19, 1:33 pm, Fred [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello  
> New to ruby 🙂  
> i have to current code :

I have a feeling you’ve taken this code from somewhere on the web  
without first trying to understand it. Am I right? If so: DON’T DO  
THAT. Understand the code before you steal the code. But see below  
for my hint.

> ```
> end
> end
> 
> ```
> 
> i want to eliminate some columns of being extracted. Let’s say i want  
> to export just the first\_name and not the whole table  
> Any suggestion will be appreciated

Your problem is you don’t understand what @model.content\_columns is  
doing: it’s getting all the columns for that model. If you want only  
specific columns, then just get the data for the columns you want.

Jeff

---

<div class="post-metadata">

**Author:** ![fred](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/db5fbb/32.png) [@fred](https://www.ruby-forum.com/u/fred)\
**Post date:** [May 19, 2008, 9:50pm UTC](https://www.ruby-forum.com/t/newbie/138049/3 "2008-05-19T21:50:17Z")

</div>

Hey though  
i didnt steal it from anywhere. it comes with a pluging as a sample  
code. I’m looking for help here and not for philosophers.

I use a find\_by\_sql instead of find(:all), so am just extracting 1  
column (first\_name).  
i got the following error : missing attribute: middle\_name.  
maybe because the headers and columns numbers should map?  
Anyone have an idea about what’s going on?  
Thank you

---

<div class="post-metadata">

**Author:** ![fred](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/db5fbb/32.png) [@fred](https://www.ruby-forum.com/u/fred)\
**Post date:** [May 20, 2008, 6:10am UTC](https://www.ruby-forum.com/t/newbie/138049/4 "2008-05-20T06:10:21Z")

</div>

> Anyone have an idea about what’s going on?

Yes

I use a find\_by\_sql instead of find(:all), so am just extracting 1  
column (first\_name).  
i got the following error : missing attribute: middle\_name.  
maybe because the headers and columns numbers should map?

Doing a find\_by\_sql whilst only selecting some columns from the table  
won’t  
make content\_columns play nicely because content\_columns expects the  
returned object to have ALL the columns.

I’m looking for help here and not for philosophers.

May I point out to you that the help is free. Be prepared to get some  
responses you won’t like.

> > I have a feeling you’ve taken this code from somewhere on the web
> > 
> > > ```
> > > # Header
> > > for record in @export
> > > end
> > > 
> > > ```
> > 
> > Your problem is you don’t understand what @model.content\_columns is  
> > doing: it’s getting all the columns for that model. If you want only  
> > specific columns, then just get the data for the columns you want.
> > 
> > Jeff
> > 
> > > Thank you  
> > > Fred
> 
> >

–  
Appreciated my help?  
Recommend me on Working With Rails  
[http://workingwithrails.com/person/11030-ryan-bigg](http://workingwithrails.com/person/11030-ryan-bigg)
