 |
Forums |
Admin Discussion Forums: help Start New Thread
By: Hannes Wyss
RE: How to write global variables to cells [ reply ] 2010-09-23 10:37
|
Hi Joe
You get what you're telling Ruby (not really Spreadsheet) to do:
you're creating a String with the content "$project", or "$tool", or
"$lines", etc.
Just leave the quotes:
$worksheet.row(row_index).push $project, $tool, $date, $lines
Spreadsheet should take care of everything else. In particular, if
$date is a Date, you'll get much better results that way, as
Spreadsheet will treat Date objects very differently from String
objects.
However, if you _want_ everything to be stored as String, just add .to_s:
$worksheet.row(row_index).push $project.to_s, $tool.to_s, $date.to_s,
$lines.to_s
As a side note: are you sure you want these variables to be global?
That looks to me like a code smell. I have no idea where the data
comes from, but if you assume it's being loaded from a database, why
not pass them as arguments to your method? E.g.
load_rows_from_database.each do |project, tool, date, lines| # note:
local block variable, not global $variable
worksheet.row(row_index).push project, tool, date, lines
row_index += 1
end
or something along those lines anyway.
hth,
h.
|
By: Sven Suska
RE: How to write global variables to cells [ reply ] 2010-09-23 10:26
|
Hello Joe,
Am Mittwoch 2010-September-22, 19:25:25 schrieb Joe VanQuakebeke:
> If I do a puts $project then I get the project name exactly as I expect.
What do you get, if you do a
puts "$project"
or
puts '$project'
Regards
Sven
--
Sven Suska * +49-39881-49194 * L'essentiel est invisible...
|
By: Joe VanQuakebeke
How to write global variables to cells [ reply ] 2010-09-22 17:25
|
I am using Spreadheet 0.6.4.1 and ruby 1.9.2 on Windows XP sp3.
I am unable to write variables contents to my spreadsheet. I can write normal strings just fine.
$worksheet.row(0).push 'Project Name', 'Build Date', 'line rate' # works great
but the following all fail:
$worksheet.row(row_index).push "$project" , "$tool" , "$date" , "$lines" # fails with single or double quotes
$worksheet.row(row_index).replace ['$project' , '$tool' , '$date' , '$lines'] # fails with single or double quotes
$worksheet.row(row_index).concat %w{'$project' '$tool' '$date' '$lines'}
row_index is set correctly, but All I see in my spreadsheet is :
Project Name Build Date line rate
'$project' '$tool' '$date' '$lines'
'$project' '$tool' '$date' '$lines'
'$project' '$tool' '$date' '$lines'
'$project' '$tool' '$date' '$lines'
'$project' '$tool' '$date' '$lines'
'$project' '$tool' '$date' '$lines'
'$project' '$tool' '$date' '$lines'
If I do a puts $project then I get the project name exactly as I expect.
Tia,
Joe
|
|
 |