[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

ruby/ole excel delete row?

eching

12/14/2006 8:54:00 PM

How do I delete a row in an excel spreadsheet with win32ole?

I want to loop through some rows and delete a row if a cell in the row
contains a certain value.

Here's the loop I am using:

excel.Range("h2:h305").each do |cell|
if cell.Value == "blah"
# DELETE ROW HERE
end
end

And,where can I find documentation for using win32ols with excel. I've
been looking but haven't found anything to my satisfaction.

Thanks in advance,
Eric

7 Answers

Li Chen

12/15/2006 3:04:00 AM

0

Eric Ching wrote:
> How do I delete a row in an excel spreadsheet with win32ole?
>
> I want to loop through some rows and delete a row if a cell in the row
> contains a certain value.
>
> Here's the loop I am using:
>
> excel.Range("h2:h305").each do |cell|
> if cell.Value == "blah"
> # DELETE ROW HERE
> end
> end


Hi,

Try this:

array=[]
worksheet1.Range("A1:L40").each do |cell|

if cell.Value=~/A/
ad=cell.Address
array=ad.scan(/\w+/)
column,row=array
worksheet1.Rows("#{row}:#{row}").Delete("Shift"=> Excel_constants::XlUp)
end
end

--
Posted via http://www.ruby-....

Li Chen

12/15/2006 2:31:00 PM

0

Simple version:


worksheet1.Range("A1:L40").each do |cell|

if cell.Value=~/A/
column,row=cell.Address.scan(/\w+/)
worksheet1.Rows("#{row}:#{row}").Delete("Shift"=>
Excel_constants::XlUp)
end

end

Li

--
Posted via http://www.ruby-....

Tim Pease

12/15/2006 4:28:00 PM

0

On 12/14/06, Nathan Smith <nlloyds@gmail.com> wrote:
> You could use:
>
> excel.range('h2:h305').each do |cell|
> cell.entireRow.delete if(cell.value == 'blah')
> end
>
> There's not a whole lot of documentation on win32ole ruby out there, but the
> Ruby Standard Library docs at http://ru... are a good place to start,
> and there's a little bit in the PickAxe. If you're working with MS Office,
> I'd recommend going to Tools => Macro => Visual Basic Editor and looking
> through the object browser. You can also record macros, look at the VB
> source, and adapt that to Ruby.
>

I have found it helpful to browse the VBA help modules for the various
MS Office applications. All the methods in those help modules are
mapped to the win32ole ruby methods. You can find the help modules
here

C:\Program Files\Microsoft Office\Office10\1033
or
C:\Program Files\Microsoft Office\OFFICE11\1033

Word => VBAWD10.CHM
Excel => VBAXL10.CHM
Access => VBAAC10.CHM
Outlook => VBAOL11.CHM
PowerPoint => VBAPP10.CHM

Blessings,
TwP

Ara.T.Howard

12/15/2006 4:46:00 PM

0

Tim Pease

12/15/2006 4:55:00 PM

0

On 12/15/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Sat, 16 Dec 2006, Tim Pease wrote:
>
> > I have found it helpful to browse the VBA help modules <snip!!!>
>
> you are a sick man!
>

I actually have had the flu for the past two days. How'd you know?

TwP

Arthur Lipscomb

2/20/2012 4:59:00 PM

0

On 2/20/2012 7:02 AM, Windowwasher wrote:

>
> Shameless -- Fiona gets a big wet one from Jasmine. Grammy nearly gets
> the house blowed up real good after she teaches her young prot?g? how to
> make meth.

And no one seems to have much a problem with this. At least not until
the house almost blew up.

Fi and Frank conspire to get rid of Grammy, but her health
> intervenes. Karen finally wanders back to reality and Lip.
>

Grammy has become the best character on the show. "There's only one way
to settle this. One of you must bleed!"

Windowwasher

2/20/2012 5:18:00 PM

0


"Arthur Lipscomb" <arthur@alum.calberkeley.org> wrote in message
news:jhttvn$oht$1@dont-email.me...
> On 2/20/2012 7:02 AM, Windowwasher wrote:
>
>>
>> Shameless -- Fiona gets a big wet one from Jasmine. Grammy nearly gets
>> the house blowed up real good after she teaches her young prot?g? how to
>> make meth.
>
> And no one seems to have much a problem with this. At least not until the
> house almost blew up.

I don't think any of the others had a clue what Grammy and the boy were up
to. The boy is sort of on his own being quite a bit younger than his older
bros and Grams saw this. That's why she offered him the skills.


>
> Fi and Frank conspire to get rid of Grammy, but her health
>> intervenes. Karen finally wanders back to reality and Lip.
>>
>
> Grammy has become the best character on the show. "There's only one way
> to settle this. One of you must bleed!"

Alas, her time appears to be limited. I'm just glad I didn't grow up in a
family like theirs.