summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorZsolt Kozaroczy <[email protected]>2020-02-07 09:54:31 +0100
committerGitHub <[email protected]>2020-02-07 09:54:31 +0100
commita58375fa72fac090d6310e2094808e8a477eab82 (patch)
tree164052dd62ff33cb821a04aa42f08395d6fe7799 /examples
parent60a7c333e83c886f2a0597a9d6619fc0e3da0938 (diff)
downloadcaxlsx-a58375fa72fac090d6310e2094808e8a477eab82.tar.gz
caxlsx-a58375fa72fac090d6310e2094808e8a477eab82.zip
Remove global variables from example #32 (#41)
Diffstat (limited to 'examples')
-rw-r--r--examples/colored_links.rb90
1 files changed, 38 insertions, 52 deletions
diff --git a/examples/colored_links.rb b/examples/colored_links.rb
index 2e6bb487..b9d42e33 100644
--- a/examples/colored_links.rb
+++ b/examples/colored_links.rb
@@ -1,59 +1,45 @@
-require 'axlsx'
+require 'axlsx'
-###############################
-# Function to output results data row to summary spreadsheet
-def outputRow (sid, type)
+p = Axlsx::Package.new
+wb = p.workbook
- $sumSheet.add_row [ sid, type, "1", "2", "3", "4", "5" ], :style => $black_cell
+# Each style only needs to be declared once in the workbook.
+s = wb.styles
+title_cell = s.add_style sz: 14, alignment: { horizontal: :center }
+black_cell = s.add_style sz: 10, alignment: { horizontal: :center }
+blue_link = s.add_style fg_color: '0000FF'
+
+# Create summary sheet
+sum_sheet = wb.add_worksheet name: 'Summary'
+sum_sheet.add_row ['Test Results'], sz: 16
+sum_sheet.add_row
+sum_sheet.add_row
+sum_sheet.add_row ['Note: Blue cells below are links to the Log sheet'], sz: 10
+sum_sheet.add_row
+sum_sheet.add_row ['ID', 'Type', 'Match', 'Mismatch', 'Diffs', 'Errors', 'Result'], style: title_cell
+
+sum_sheet.column_widths 10, 10, 1 0, 11, 10, 10, 10
+
+# Starting data row in summary spreadsheet (after header info)
+current_row = 7
+
+# Create Log Sheet
+log_sheet = wb.add_worksheet name: 'Log'
+log_sheet.column_widths 10
+log_sheet.add_row ['Log Detail'], sz: 16
+log_sheet.add_row
+
+# Add rows to summary sheet
+(1..10).each do |sid|
+ sum_sheet.add_row [sid, 'test', '1', '2', '3', '4', '5'], style: black_cell
if sid.odd?
- link = "A#{$curRow}"
- puts "outputRow: sid: #{sid}, link: #{link}"
- # Setting the style for the link will apply the xf that we created in the Main Program block
- $sumSheet[link].style = $blue_link
- $sumSheet.add_hyperlink :location => "'Log'!A#{$curRow}", :target => :sheet, :ref => link
+ link = "A#{current_row}"
+ sum_sheet[link].style = blue_link
+ sum_sheet.add_hyperlink location: "'Log'!A#{current_row}", target: :sheet, ref: link
end
- $curRow += 1
-end
-##############################
-# Main Program
+ current_row += 1
+end
-$package = Axlsx::Package.new
-$workbook = $package.workbook
-## We want to create our sytles outside of the outputRow method
-# Each style only needs to be declared once in the workbook.
-$workbook.styles do |s|
- $black_cell = s.add_style :sz => 10, :alignment => { :horizontal=> :center }
- $blue_link = s.add_style :fg_color => '0000FF'
-end
-
-
-# Create summary sheet
-$sumSheet = $workbook.add_worksheet(:name => 'Summary')
-$sumSheet.add_row ["Test Results"], :sz => 16
-$sumSheet.add_row
-$sumSheet.add_row
-$sumSheet.add_row ["Note: Blue cells below are links to the Log sheet"], :sz => 10
-$sumSheet.add_row
-$workbook.styles do |s|
- black_cell = s.add_style :sz => 14, :alignment => { :horizontal=> :center }
- $sumSheet.add_row ["ID","Type","Match","Mismatch","Diffs","Errors","Result"], :style => black_cell
-end
-$sumSheet.column_widths 10, 10, 10, 11, 10, 10, 10
-
-# Starting data row in summary spreadsheet (after header info)
-$curRow = 7
-
-# Create Log Sheet
-$logSheet = $workbook.add_worksheet(:name => 'Log')
-$logSheet.column_widths 10
-$logSheet.add_row ['Log Detail'], :sz => 16
-$logSheet.add_row
-
-# Add rows to summary sheet
-for i in 1..10 do
- outputRow(i, 'test')
-end
-
-$package.serialize 'where_is_my_color.xlsx'
+p.serialize 'where_is_my_color.xlsx'