From: Daniel Navarro Date: 2010-11-06T08:10:18+09:00 Subject: Re: Excel and Ruby --90e6ba6e8df6b4bb410494566089 Content-Type: text/plain; charset=ISO-8859-1 eek and the last little bit should be cellcontentsA = cella.text cellcontentsB = callb.value puts cellcontentsA puts cellcontentsB Sorry about that. Was looking at some other code and copy pasted that into the value ; ; Yay me. On Fri, Nov 5, 2010 at 6:05 PM, Daniel Navarro wrote: > ~ *****With regard to your question about what I am trying to do... The > first > objective of my program is to bring me up to speed using Ruby program to > automate the extraction of data from Excel spreadsheets. Once I have got > that working then I will extract data from a large spreadsheet covering > levy payments by occupants in a retirement village and then use Ruby to > print out letters to individual occupants who are wanting to reconcile > their payments. This will then require using Ruby to print reports. > Examples of doing this seems pretty scarce.*****~ > > As far as extracting the data from an excel sheet, I'm assuming Names and > Levy payments and inserting into a report. What kind of report are we > talking about? Is it just text? A crystal report? > > for i in 1..100 do > # Lets iterate of each of these values into an array > worksheet.Range("A#{i}").each do |cella| > worksheet.Range("B#{i}").each do |cellb| > #This could also be done without a loop by simply calling the range of > cells > worksheet.Range("A1:A100").each do |cella| > worksheet.Range("B1:B100").each do |cellb| > =beginAnd make sure we are talking about text and values here. Assuming of > course cell a is names and cell b is a value or number. Value has to to do > with integers and floats. Integars are whole numbers where as floats extend > with past the decimal. 1 = integer 2.22 = float > =end > > cellcontentsA = cella.text > cellcontentsB = callb.value > > puts cellvaluea > puts cellvalueb > > Array's come with their own special methods and you can see what the > methods > are by typing in Array.methods Lots of cool toys in there :) <3 Ruby > > > Hope this explains it better :) There are so many ways to get the same > results, it's fun to look over new things and condense it to the most > simple > form. This is not the most simple form but for learning purposes II hope it > does a good job explaining each element of the code for you. > If everything works out the way you want to let me know and we can get on > to > making the Mailing letters and printing them out. Can do this in many ways > in either word, a text file, simply e-mail automatically. You name it. It's > there. > > On Fri, Nov 5, 2010 at 2:12 PM, Daniel Navarro > wrote: > > > Not a problem, try interpolation with a for loop. > > > > example > > > > for i in 1..100 do > > > > worksheet.Range("B#{i}").value > > > > > > this will loop through i or the range of 1-100. or whatever you want to > > loop > > to. > > > > > > > > > -- Daniel Navarro 9035612340 --90e6ba6e8df6b4bb410494566089--