Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

crlf modified ? because i set git config core.autocrlf true.

  • Loading branch information...
commit 431af40f5f78566229b23708fc29b4e6f49ccc45 1 parent b5f7530
@cxn03651 authored
Showing with 28,582 additions and 28,582 deletions.
  1. +51 −51 examples/copyformat.rb
  2. +278 −278 examples/data_validate.rb
  3. +86 −86 examples/date_time.rb
  4. +31 −31 examples/defined_name.rb
  5. +123 −123 examples/demo.rb
  6. +35 −35 examples/diag_border.rb
  7. +489 −489 examples/formats.rb
  8. +29 −29 examples/formula_result.rb
  9. +136 −136 examples/header.rb
  10. +28 −28 examples/hide_sheet.rb
  11. +42 −42 examples/hyperlink.rb
  12. +62 −62 examples/images.rb
  13. +30 −30 examples/indent.rb
  14. +39 −39 examples/merge1.rb
  15. +44 −44 examples/merge2.rb
  16. +65 −65 examples/merge3.rb
  17. +82 −82 examples/merge4.rb
  18. +79 −79 examples/merge5.rb
  19. +254 −254 examples/outline.rb
  20. +208 −208 examples/outline_collapsed.rb
  21. +112 −112 examples/panes.rb
  22. +33 −33 examples/properties.rb
  23. +32 −32 examples/properties_jp.rb
  24. +46 −46 examples/protection.rb
  25. +52 −52 examples/regions.rb
  26. +42 −42 examples/repeat.rb
  27. +26 −26 examples/right_to_left.rb
  28. +52 −52 examples/row_wrap.rb
  29. +73 −73 examples/stats.rb
  30. +80 −80 examples/stocks.rb
  31. +30 −30 examples/tab_colors.rb
  32. +82 −82 examples/write_arrays.rb
  33. +1,052 −1,052 lib/writeexcel/formula.rb
  34. +318 −318 lib/writeexcel/olewriter.rb
  35. +249 −249 lib/writeexcel/properties.rb
  36. +3,294 −3,294 lib/writeexcel/workbook.rb
  37. +9,004 −9,004 lib/writeexcel/worksheet.rb
  38. +9 −9 test/helper.rb
  39. +12 −12 test/test_00_IEEE_double.rb
  40. +9 −9 test/test_01_add_worksheet.rb
  41. +55 −55 test/test_02_merge_formats.rb
  42. +394 −394 test/test_04_dimensions.rb
  43. +179 −179 test/test_05_rows.rb
  44. +77 −77 test/test_06_extsst.rb
  45. +481 −481 test/test_11_date_time.rb
  46. +503 −503 test/test_12_date_only.rb
  47. +483 −483 test/test_13_date_seconds.rb
  48. +639 −639 test/test_21_escher.rb
  49. +747 −747 test/test_22_mso_drawing_group.rb
  50. +75 −75 test/test_23_note.rb
  51. +77 −77 test/test_24_txo.rb
  52. +324 −324 test/test_26_autofilter.rb
  53. +141 −141 test/test_27_autofilter.rb
  54. +171 −171 test/test_28_autofilter.rb
  55. +678 −678 test/test_29_process_jpg.rb
  56. +79 −79 test/test_30_validation_dval.rb
  57. +128 −128 test/test_31_validation_dv_strings.rb
  58. +208 −208 test/test_32_validation_dv_formula.rb
  59. +187 −187 test/test_40_property_types.rb
  60. +234 −234 test/test_41_properties.rb
  61. +438 −438 test/test_42_set_properties.rb
  62. +573 −573 test/test_60_chart_generic.rb
  63. +101 −101 test/test_biff.rb
  64. +3,145 −3,145 test/test_example_match.rb
  65. +1,251 −1,251 test/test_format.rb
  66. +60 −60 test/test_formula.rb
  67. +107 −107 test/test_ole.rb
  68. +137 −137 test/test_workbook.rb
  69. +112 −112 test/test_worksheet.rb
View
102 examples/copyformat.rb
@@ -1,51 +1,51 @@
-#!/usr/bin/ruby -w
-
-###############################################################################
-#
-# Example of how to use the format copying method with WriteExcel #
-# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-require 'rubygems'
-require 'writeexcel'
-
-# Create workbook1
-workbook1 = WriteExcel.new("workbook1.xls")
-worksheet1 = workbook1.add_worksheet
-format1a = workbook1.add_format
-format1b = workbook1.add_format
-
-# Create workbook2
-workbook2 = WriteExcel.new("workbook2.xls")
-worksheet2 = workbook2.add_worksheet
-format2a = workbook2.add_format
-format2b = workbook2.add_format
-
-# Create a global format object that isn't tied to a workbook
-global_format = Format.new
-
-# Set the formatting
-global_format.set_color('blue')
-global_format.set_bold
-global_format.set_italic
-
-# Create another example format
-format1b.set_color('red')
-
-# Copy the global format properties to the worksheet formats
-format1a.copy(global_format)
-format2a.copy(global_format)
-
-# Copy a format from worksheet1 to worksheet2
-format2b.copy(format1b)
-
-# Write some output
-worksheet1.write(0, 0, "Ciao", format1a)
-worksheet1.write(1, 0, "Ciao", format1b)
-
-worksheet2.write(0, 0, "Hello", format2a)
-worksheet2.write(1, 0, "Hello", format2b)
-workbook1.close
-workbook2.close
+#!/usr/bin/ruby -w
+
+###############################################################################
+#
+# Example of how to use the format copying method with WriteExcel #
+# reverse('©'), March 2001, John McNamara, jmcnamara@cpan.org
+#
+# original written in Perl by John McNamara
+# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
+#
+require 'rubygems'
+require 'writeexcel'
+
+# Create workbook1
+workbook1 = WriteExcel.new("workbook1.xls")
+worksheet1 = workbook1.add_worksheet
+format1a = workbook1.add_format
+format1b = workbook1.add_format
+
+# Create workbook2
+workbook2 = WriteExcel.new("workbook2.xls")
+worksheet2 = workbook2.add_worksheet
+format2a = workbook2.add_format
+format2b = workbook2.add_format
+
+# Create a global format object that isn't tied to a workbook
+global_format = Format.new
+
+# Set the formatting
+global_format.set_color('blue')
+global_format.set_bold
+global_format.set_italic
+
+# Create another example format
+format1b.set_color('red')
+
+# Copy the global format properties to the worksheet formats
+format1a.copy(global_format)
+format2a.copy(global_format)
+
+# Copy a format from worksheet1 to worksheet2
+format2b.copy(format1b)
+
+# Write some output
+worksheet1.write(0, 0, "Ciao", format1a)
+worksheet1.write(1, 0, "Ciao", format1b)
+
+worksheet2.write(0, 0, "Hello", format2a)
+worksheet2.write(1, 0, "Hello", format2b)
+workbook1.close
+workbook2.close
View
556 examples/data_validate.rb
@@ -1,278 +1,278 @@
-#!/usr/bin/ruby -w
-
-###############################################################################
-#
-# Example of how to add data validation and dropdown lists to a
-# WriteExcel file.
-#
-# reverse('©'), August 2008, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-
-require 'rubygems'
-require 'writeexcel'
-
-workbook = WriteExcel.new('data_validate.xls')
-worksheet = workbook.add_worksheet
-
-# Add a format for the header cells.
-header_format = workbook.add_format(
- :border => 1,
- :bg_color => 43,
- :bold => 1,
- :text_wrap => 1,
- :valign => 'vcenter',
- :indent => 1
- )
-
-# Set up layout of the worksheet.
-worksheet.set_column('A:A', 64)
-worksheet.set_column('B:B', 15)
-worksheet.set_column('D:D', 15)
-worksheet.set_row(0, 36)
-worksheet.set_selection('B3')
-
-
-# Write the header cells and some data that will be used in the examples.
-row = 0
-heading1 = 'Some examples of data validation in WriteExcel'
-heading2 = 'Enter values in this column'
-heading3 = 'Sample Data'
-
-worksheet.write('A1', heading1, header_format)
-worksheet.write('B1', heading2, header_format)
-worksheet.write('D1', heading3, header_format)
-
-worksheet.write('D3', ['Integers', 1, 10])
-worksheet.write('D4', ['List data', 'open', 'high', 'close'])
-worksheet.write('D5', ['Formula', '=AND(F5=50,G5=60)', 50, 60])
-
-
-#
-# Example 1. Limiting input to an integer in a fixed range.
-#
-txt = 'Enter an integer between 1 and 10'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'integer',
- :criteria => 'between',
- :minimum => 1,
- :maximum => 10
- })
-
-
-#
-# Example 2. Limiting input to an integer outside a fixed range.
-#
-txt = 'Enter an integer that is not between 1 and 10 (using cell references)'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'integer',
- :criteria => 'not between',
- :minimum => '=E3',
- :maximum => '=F3'
- })
-
-
-#
-# Example 3. Limiting input to an integer greater than a fixed value.
-#
-txt = 'Enter an integer greater than 0'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'integer',
- :criteria => '>',
- :value => 0
- })
-
-
-#
-# Example 4. Limiting input to an integer less than a fixed value.
-#
-txt = 'Enter an integer less than 10'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'integer',
- :criteria => '<',
- :value => 10
- })
-
-
-#
-# Example 5. Limiting input to a decimal in a fixed range.
-#
-txt = 'Enter a decimal between 0.1 and 0.5'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'decimal',
- :criteria => 'between',
- :minimum => 0.1,
- :maximum => 0.5
- })
-
-
-#
-# Example 6. Limiting input to a value in a dropdown list.
-#
-txt = 'Select a value from a drop down list'
-row += 2
-bp=1
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'list',
- :source => ['open', 'high', 'close']
- })
-
-
-#
-# Example 6. Limiting input to a value in a dropdown list.
-#
-txt = 'Select a value from a drop down list (using a cell range)'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'list',
- :source => '=E4:G4'
- })
-
-
-#
-# Example 7. Limiting input to a date in a fixed range.
-#
-txt = 'Enter a date between 1/1/2008 and 12/12/2008'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'date',
- :criteria => 'between',
- :minimum => '2008-01-01T',
- :maximum => '2008-12-12T'
- })
-
-
-#
-# Example 8. Limiting input to a time in a fixed range.
-#
-txt = 'Enter a time between 6:00 and 12:00'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'time',
- :criteria => 'between',
- :minimum => 'T06:00',
- :maximum => 'T12:00'
- })
-
-
-#
-# Example 9. Limiting input to a string greater than a fixed length.
-#
-txt = 'Enter a string longer than 3 characters'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'length',
- :criteria => '>',
- :value => 3
- })
-
-
-#
-# Example 10. Limiting input based on a formula.
-#
-txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'custom',
- :value => '=AND(F5=50,G5=60)'
- })
-
-
-#
-# Example 11. Displaying and modify data validation messages.
-#
-txt = 'Displays a message when you select the cell'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'integer',
- :criteria => 'between',
- :minimum => 1,
- :maximum => 100,
- :input_title => 'Enter an integer:',
- :input_message => 'between 1 and 100'
- })
-
-
-#
-# Example 12. Displaying and modify data validation messages.
-#
-txt = 'Display a custom error message when integer isn\'t between 1 and 100'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'integer',
- :criteria => 'between',
- :minimum => 1,
- :maximum => 100,
- :input_title => 'Enter an integer:',
- :input_message => 'between 1 and 100',
- :error_title => 'Input value is not valid!',
- :error_message => 'It should be an integer between 1 and 100'
- })
-
-
-#
-# Example 13. Displaying and modify data validation messages.
-#
-txt = 'Display a custom information message when integer isn\'t between 1 and 100'
-row += 2
-
-worksheet.write(row, 0, txt)
-worksheet.data_validation(row, 1,
- {
- :validate => 'integer',
- :criteria => 'between',
- :minimum => 1,
- :maximum => 100,
- :input_title => 'Enter an integer:',
- :input_message => 'between 1 and 100',
- :error_title => 'Input value is not valid!',
- :error_message => 'It should be an integer between 1 and 100',
- :error_type => 'information'
- })
-
-workbook.close
+#!/usr/bin/ruby -w
+
+###############################################################################
+#
+# Example of how to add data validation and dropdown lists to a
+# WriteExcel file.
+#
+# reverse('©'), August 2008, John McNamara, jmcnamara@cpan.org
+#
+# original written in Perl by John McNamara
+# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
+#
+
+require 'rubygems'
+require 'writeexcel'
+
+workbook = WriteExcel.new('data_validate.xls')
+worksheet = workbook.add_worksheet
+
+# Add a format for the header cells.
+header_format = workbook.add_format(
+ :border => 1,
+ :bg_color => 43,
+ :bold => 1,
+ :text_wrap => 1,
+ :valign => 'vcenter',
+ :indent => 1
+ )
+
+# Set up layout of the worksheet.
+worksheet.set_column('A:A', 64)
+worksheet.set_column('B:B', 15)
+worksheet.set_column('D:D', 15)
+worksheet.set_row(0, 36)
+worksheet.set_selection('B3')
+
+
+# Write the header cells and some data that will be used in the examples.
+row = 0
+heading1 = 'Some examples of data validation in WriteExcel'
+heading2 = 'Enter values in this column'
+heading3 = 'Sample Data'
+
+worksheet.write('A1', heading1, header_format)
+worksheet.write('B1', heading2, header_format)
+worksheet.write('D1', heading3, header_format)
+
+worksheet.write('D3', ['Integers', 1, 10])
+worksheet.write('D4', ['List data', 'open', 'high', 'close'])
+worksheet.write('D5', ['Formula', '=AND(F5=50,G5=60)', 50, 60])
+
+
+#
+# Example 1. Limiting input to an integer in a fixed range.
+#
+txt = 'Enter an integer between 1 and 10'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'integer',
+ :criteria => 'between',
+ :minimum => 1,
+ :maximum => 10
+ })
+
+
+#
+# Example 2. Limiting input to an integer outside a fixed range.
+#
+txt = 'Enter an integer that is not between 1 and 10 (using cell references)'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'integer',
+ :criteria => 'not between',
+ :minimum => '=E3',
+ :maximum => '=F3'
+ })
+
+
+#
+# Example 3. Limiting input to an integer greater than a fixed value.
+#
+txt = 'Enter an integer greater than 0'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'integer',
+ :criteria => '>',
+ :value => 0
+ })
+
+
+#
+# Example 4. Limiting input to an integer less than a fixed value.
+#
+txt = 'Enter an integer less than 10'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'integer',
+ :criteria => '<',
+ :value => 10
+ })
+
+
+#
+# Example 5. Limiting input to a decimal in a fixed range.
+#
+txt = 'Enter a decimal between 0.1 and 0.5'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'decimal',
+ :criteria => 'between',
+ :minimum => 0.1,
+ :maximum => 0.5
+ })
+
+
+#
+# Example 6. Limiting input to a value in a dropdown list.
+#
+txt = 'Select a value from a drop down list'
+row += 2
+bp=1
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'list',
+ :source => ['open', 'high', 'close']
+ })
+
+
+#
+# Example 6. Limiting input to a value in a dropdown list.
+#
+txt = 'Select a value from a drop down list (using a cell range)'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'list',
+ :source => '=E4:G4'
+ })
+
+
+#
+# Example 7. Limiting input to a date in a fixed range.
+#
+txt = 'Enter a date between 1/1/2008 and 12/12/2008'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'date',
+ :criteria => 'between',
+ :minimum => '2008-01-01T',
+ :maximum => '2008-12-12T'
+ })
+
+
+#
+# Example 8. Limiting input to a time in a fixed range.
+#
+txt = 'Enter a time between 6:00 and 12:00'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'time',
+ :criteria => 'between',
+ :minimum => 'T06:00',
+ :maximum => 'T12:00'
+ })
+
+
+#
+# Example 9. Limiting input to a string greater than a fixed length.
+#
+txt = 'Enter a string longer than 3 characters'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'length',
+ :criteria => '>',
+ :value => 3
+ })
+
+
+#
+# Example 10. Limiting input based on a formula.
+#
+txt = 'Enter a value if the following is true "=AND(F5=50,G5=60)"'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'custom',
+ :value => '=AND(F5=50,G5=60)'
+ })
+
+
+#
+# Example 11. Displaying and modify data validation messages.
+#
+txt = 'Displays a message when you select the cell'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'integer',
+ :criteria => 'between',
+ :minimum => 1,
+ :maximum => 100,
+ :input_title => 'Enter an integer:',
+ :input_message => 'between 1 and 100'
+ })
+
+
+#
+# Example 12. Displaying and modify data validation messages.
+#
+txt = 'Display a custom error message when integer isn\'t between 1 and 100'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'integer',
+ :criteria => 'between',
+ :minimum => 1,
+ :maximum => 100,
+ :input_title => 'Enter an integer:',
+ :input_message => 'between 1 and 100',
+ :error_title => 'Input value is not valid!',
+ :error_message => 'It should be an integer between 1 and 100'
+ })
+
+
+#
+# Example 13. Displaying and modify data validation messages.
+#
+txt = 'Display a custom information message when integer isn\'t between 1 and 100'
+row += 2
+
+worksheet.write(row, 0, txt)
+worksheet.data_validation(row, 1,
+ {
+ :validate => 'integer',
+ :criteria => 'between',
+ :minimum => 1,
+ :maximum => 100,
+ :input_title => 'Enter an integer:',
+ :input_message => 'between 1 and 100',
+ :error_title => 'Input value is not valid!',
+ :error_message => 'It should be an integer between 1 and 100',
+ :error_type => 'information'
+ })
+
+workbook.close
View
172 examples/date_time.rb
@@ -1,86 +1,86 @@
-#!/usr/bin/ruby -w
-
-###############################################################################
-#
-# WriteExcel example of writing dates and times using the
-# write_date_time() Worksheet method.
-#
-# reverse('©'), August 2004, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-
-require 'rubygems'
-require 'writeexcel'
-
-# Create a new workbook and add a worksheet
-workbook = WriteExcel.new("date_time.xls")
-worksheet = workbook.add_worksheet
-bold = workbook.add_format(:bold => 1)
-
-# Expand the first column so that the date is visible.
-worksheet.set_column("A:B", 30)
-
-# Write the column headers
-worksheet.write('A1', 'Formatted date', bold)
-worksheet.write('B1', 'Format', bold)
-
-# Examples date and time formats. In the output file compare how changing
-# the format codes change the appearance of the date.
-#
-date_formats = [
- 'dd/mm/yy',
- 'mm/dd/yy',
- '',
- 'd mm yy',
- 'dd mm yy',
- '',
- 'dd m yy',
- 'dd mm yy',
- 'dd mmm yy',
- 'dd mmmm yy',
- '',
- 'dd mm y',
- 'dd mm yyy',
- 'dd mm yyyy',
- '',
- 'd mmmm yyyy',
- '',
- 'dd/mm/yy',
- 'dd/mm/yy hh:mm',
- 'dd/mm/yy hh:mm:ss',
- 'dd/mm/yy hh:mm:ss.000',
- '',
- 'hh:mm',
- 'hh:mm:ss',
- 'hh:mm:ss.000',
-]
-
-# Write the same date and time using each of the above formats. The empty
-# string formats create a blank line to make the example clearer.
-#
-row = 0
-date_formats.each do |date_format|
- row += 1
- next if date_format == ''
-
- # Create a format for the date or time.
- format = workbook.add_format(
- :num_format => date_format,
- :align => 'left'
- )
-
- # Write the same date using different formats.
- worksheet.write_date_time(row, 0, '2004-08-01T12:30:45.123', format)
- worksheet.write(row, 1, date_format)
-end
-
-# The following is an example of an invalid date. It is written as a string instead
-# of a number. This is also Excel's default behaviour.
-#
-row += 2
-worksheet.write_date_time(row, 0, '2004-13-01T12:30:45.123')
-worksheet.write(row, 1, 'Invalid date. Written as string.', bold)
-
-workbook.close
+#!/usr/bin/ruby -w
+
+###############################################################################
+#
+# WriteExcel example of writing dates and times using the
+# write_date_time() Worksheet method.
+#
+# reverse('©'), August 2004, John McNamara, jmcnamara@cpan.org
+#
+# original written in Perl by John McNamara
+# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
+#
+
+require 'rubygems'
+require 'writeexcel'
+
+# Create a new workbook and add a worksheet
+workbook = WriteExcel.new("date_time.xls")
+worksheet = workbook.add_worksheet
+bold = workbook.add_format(:bold => 1)
+
+# Expand the first column so that the date is visible.
+worksheet.set_column("A:B", 30)
+
+# Write the column headers
+worksheet.write('A1', 'Formatted date', bold)
+worksheet.write('B1', 'Format', bold)
+
+# Examples date and time formats. In the output file compare how changing
+# the format codes change the appearance of the date.
+#
+date_formats = [
+ 'dd/mm/yy',
+ 'mm/dd/yy',
+ '',
+ 'd mm yy',
+ 'dd mm yy',
+ '',
+ 'dd m yy',
+ 'dd mm yy',
+ 'dd mmm yy',
+ 'dd mmmm yy',
+ '',
+ 'dd mm y',
+ 'dd mm yyy',
+ 'dd mm yyyy',
+ '',
+ 'd mmmm yyyy',
+ '',
+ 'dd/mm/yy',
+ 'dd/mm/yy hh:mm',
+ 'dd/mm/yy hh:mm:ss',
+ 'dd/mm/yy hh:mm:ss.000',
+ '',
+ 'hh:mm',
+ 'hh:mm:ss',
+ 'hh:mm:ss.000',
+]
+
+# Write the same date and time using each of the above formats. The empty
+# string formats create a blank line to make the example clearer.
+#
+row = 0
+date_formats.each do |date_format|
+ row += 1
+ next if date_format == ''
+
+ # Create a format for the date or time.
+ format = workbook.add_format(
+ :num_format => date_format,
+ :align => 'left'
+ )
+
+ # Write the same date using different formats.
+ worksheet.write_date_time(row, 0, '2004-08-01T12:30:45.123', format)
+ worksheet.write(row, 1, date_format)
+end
+
+# The following is an example of an invalid date. It is written as a string instead
+# of a number. This is also Excel's default behaviour.
+#
+row += 2
+worksheet.write_date_time(row, 0, '2004-13-01T12:30:45.123')
+worksheet.write(row, 1, 'Invalid date. Written as string.', bold)
+
+workbook.close
View
62 examples/defined_name.rb
@@ -1,31 +1,31 @@
-#!/usr/bin/ruby -w
-
-###############################################################################
-#
-# Example of how to create defined names in a WriteExcel file.
-#
-# reverse('ゥ'), September 2008, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-
-require 'writeexcel'
-
-workbook = WriteExcel.new('defined_name.xls')
-worksheet1 = workbook.add_worksheet
-worksheet2 = workbook.add_worksheet
-
-workbook.define_name('Exchange_rate', '=0.96')
-workbook.define_name('Sales', '=Sheet1!$G$1:$H$10')
-workbook.define_name('Sheet2!Sales', '=Sheet2!$G$1:$G$10')
-
-workbook.sheets.each do |worksheet|
- worksheet.set_column('A:A', 45)
- worksheet.write('A2', 'This worksheet contains some defined names,')
- worksheet.write('A3', 'See the Insert -> Name -> Define dialog.')
-end
-
-worksheet1.write('A4', '=Exchange_rate')
-
-workbook.close
+#!/usr/bin/ruby -w
+
+###############################################################################
+#
+# Example of how to create defined names in a WriteExcel file.
+#
+# reverse('ゥ'), September 2008, John McNamara, jmcnamara@cpan.org
+#
+# original written in Perl by John McNamara
+# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
+#
+
+require 'writeexcel'
+
+workbook = WriteExcel.new('defined_name.xls')
+worksheet1 = workbook.add_worksheet
+worksheet2 = workbook.add_worksheet
+
+workbook.define_name('Exchange_rate', '=0.96')
+workbook.define_name('Sales', '=Sheet1!$G$1:$H$10')
+workbook.define_name('Sheet2!Sales', '=Sheet2!$G$1:$G$10')
+
+workbook.sheets.each do |worksheet|
+ worksheet.set_column('A:A', 45)
+ worksheet.write('A2', 'This worksheet contains some defined names,')
+ worksheet.write('A3', 'See the Insert -> Name -> Define dialog.')
+end
+
+worksheet1.write('A4', '=Exchange_rate')
+
+workbook.close
View
246 examples/demo.rb
@@ -1,123 +1,123 @@
-#!/usr/bin/ruby -w
-
-#######################################################################
-#
-# Demo of some of the features of WriteExcel.
-# Used to create the project screenshot for Freshmeat.
-#
-#
-# reverse('©'), October 2001, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-
-require 'rubygems'
-require 'writeexcel'
-
-# $debug = true
-
-workbook = WriteExcel.new("demo.xls")
-worksheet = workbook.add_worksheet('Demo')
-worksheet2 = workbook.add_worksheet('Another sheet')
-worksheet3 = workbook.add_worksheet('And another')
-
-bold = workbook.add_format(:bold => 1)
-
-#######################################################################
-#
-# Write a general heading
-#
-worksheet.set_column('A:A', 36, bold)
-worksheet.set_column('B:B', 20 )
-worksheet.set_row(0, 40 )
-
-heading = workbook.add_format(
- :bold => 1,
- :color => 'blue',
- :size => 16,
- :merge => 1,
- :align => 'vcenter'
- )
-
-headings = ['Features of Spreadsheet::WriteExcel', '']
-worksheet.write_row('A1', headings, heading)
-
-
-#######################################################################
-#
-# Some text examples
-#
-text_format = workbook.add_format(
- :bold => 1,
- :italic => 1,
- :color => 'red',
- :size => 18,
- :font =>'Lucida Calligraphy'
- )
-
-# A phrase in Cyrillic
-unicode = [
- "042d0442043e002004440440043004370430002004"+
- "3d043000200440044304410441043a043e043c0021"
- ].pack('H*')
-
-worksheet.write('A2', "Text")
-worksheet.write('B2', "Hello Excel")
-worksheet.write('A3', "Formatted text")
-worksheet.write('B3', "Hello Excel", text_format)
-worksheet.write('A4', "Unicode text")
-worksheet.write_utf16be_string('B4', unicode)
-
-
-#######################################################################
-#
-# Some numeric examples
-#
-num1_format = workbook.add_format(:num_format => '$#,##0.00')
-num2_format = workbook.add_format(:num_format => ' d mmmm yyy')
-
-worksheet.write('A5', "Numbers")
-worksheet.write('B5', 1234.56)
-worksheet.write('A6', "Formatted numbers")
-worksheet.write('B6', 1234.56, num1_format)
-worksheet.write('A7', "Formatted numbers")
-worksheet.write('B7', 37257, num2_format)
-
-
-#######################################################################
-#
-# Formulae
-#
-worksheet.set_selection('B8')
-worksheet.write('A8', 'Formulas and functions, "=SIN(PI()/4)"')
-worksheet.write('B8', '=SIN(PI()/4)')
-
-
-#######################################################################
-#
-# Hyperlinks
-#
-worksheet.write('A9', "Hyperlinks")
-worksheet.write('B9', 'http://www.perl.com/' )
-
-
-#######################################################################
-#
-# Images
-#
-worksheet.write('A10', "Images")
-worksheet.insert_image('B10',
- File.join(File.dirname(File.expand_path(__FILE__)), 'republic.png'),
- 16, 8
-)
-
-
-#######################################################################
-#
-# Misc
-#
-worksheet.write('A18', "Page/printer setup")
-worksheet.write('A19', "Multiple worksheets")
-
-workbook.close
+#!/usr/bin/ruby -w
+
+#######################################################################
+#
+# Demo of some of the features of WriteExcel.
+# Used to create the project screenshot for Freshmeat.
+#
+#
+# reverse('©'), October 2001, John McNamara, jmcnamara@cpan.org
+#
+# original written in Perl by John McNamara
+# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
+#
+
+require 'rubygems'
+require 'writeexcel'
+
+# $debug = true
+
+workbook = WriteExcel.new("demo.xls")
+worksheet = workbook.add_worksheet('Demo')
+worksheet2 = workbook.add_worksheet('Another sheet')
+worksheet3 = workbook.add_worksheet('And another')
+
+bold = workbook.add_format(:bold => 1)
+
+#######################################################################
+#
+# Write a general heading
+#
+worksheet.set_column('A:A', 36, bold)
+worksheet.set_column('B:B', 20 )
+worksheet.set_row(0, 40 )
+
+heading = workbook.add_format(
+ :bold => 1,
+ :color => 'blue',
+ :size => 16,
+ :merge => 1,
+ :align => 'vcenter'
+ )
+
+headings = ['Features of Spreadsheet::WriteExcel', '']
+worksheet.write_row('A1', headings, heading)
+
+
+#######################################################################
+#
+# Some text examples
+#
+text_format = workbook.add_format(
+ :bold => 1,
+ :italic => 1,
+ :color => 'red',
+ :size => 18,
+ :font =>'Lucida Calligraphy'
+ )
+
+# A phrase in Cyrillic
+unicode = [
+ "042d0442043e002004440440043004370430002004"+
+ "3d043000200440044304410441043a043e043c0021"
+ ].pack('H*')
+
+worksheet.write('A2', "Text")
+worksheet.write('B2', "Hello Excel")
+worksheet.write('A3', "Formatted text")
+worksheet.write('B3', "Hello Excel", text_format)
+worksheet.write('A4', "Unicode text")
+worksheet.write_utf16be_string('B4', unicode)
+
+
+#######################################################################
+#
+# Some numeric examples
+#
+num1_format = workbook.add_format(:num_format => '$#,##0.00')
+num2_format = workbook.add_format(:num_format => ' d mmmm yyy')
+
+worksheet.write('A5', "Numbers")
+worksheet.write('B5', 1234.56)
+worksheet.write('A6', "Formatted numbers")
+worksheet.write('B6', 1234.56, num1_format)
+worksheet.write('A7', "Formatted numbers")
+worksheet.write('B7', 37257, num2_format)
+
+
+#######################################################################
+#
+# Formulae
+#
+worksheet.set_selection('B8')
+worksheet.write('A8', 'Formulas and functions, "=SIN(PI()/4)"')
+worksheet.write('B8', '=SIN(PI()/4)')
+
+
+#######################################################################
+#
+# Hyperlinks
+#
+worksheet.write('A9', "Hyperlinks")
+worksheet.write('B9', 'http://www.perl.com/' )
+
+
+#######################################################################
+#
+# Images
+#
+worksheet.write('A10', "Images")
+worksheet.insert_image('B10',
+ File.join(File.dirname(File.expand_path(__FILE__)), 'republic.png'),
+ 16, 8
+)
+
+
+#######################################################################
+#
+# Misc
+#
+worksheet.write('A18', "Page/printer setup")
+worksheet.write('A19', "Multiple worksheets")
+
+workbook.close
View
70 examples/diag_border.rb
@@ -1,35 +1,35 @@
-#!/usr/bin/ruby -w
-
-##############################################################################
-#
-# A simple formatting example using WriteExcel.
-#
-# This program demonstrates the diagonal border cell format.
-#
-# reverse('©'), May 2004, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-
-require 'rubygems'
-require 'writeexcel'
-
-workbook = WriteExcel.new('diag_border.xls')
-worksheet = workbook.add_worksheet
-
-format1 = workbook.add_format(:diag_type => 1)
-format2 = workbook.add_format(:diag_type => 2)
-format3 = workbook.add_format(:diag_type => 3)
-format4 = workbook.add_format(
- :diag_type => 3,
- :diag_border => 7,
- :diag_color => 'red'
- )
-
-worksheet.write('B3', 'Text', format1)
-worksheet.write('B6', 'Text', format2)
-worksheet.write('B9', 'Text', format3)
-worksheet.write('B12', 'Text', format4)
-
-workbook.close
+#!/usr/bin/ruby -w
+
+##############################################################################
+#
+# A simple formatting example using WriteExcel.
+#
+# This program demonstrates the diagonal border cell format.
+#
+# reverse('©'), May 2004, John McNamara, jmcnamara@cpan.org
+#
+# original written in Perl by John McNamara
+# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
+#
+
+require 'rubygems'
+require 'writeexcel'
+
+workbook = WriteExcel.new('diag_border.xls')
+worksheet = workbook.add_worksheet
+
+format1 = workbook.add_format(:diag_type => 1)
+format2 = workbook.add_format(:diag_type => 2)
+format3 = workbook.add_format(:diag_type => 3)
+format4 = workbook.add_format(
+ :diag_type => 3,
+ :diag_border => 7,
+ :diag_color => 'red'
+ )
+
+worksheet.write('B3', 'Text', format1)
+worksheet.write('B6', 'Text', format2)
+worksheet.write('B9', 'Text', format3)
+worksheet.write('B12', 'Text', format4)
+
+workbook.close
View
978 examples/formats.rb
@@ -1,489 +1,489 @@
-#!/usr/bin/ruby -w
-
-######################################################################
-#
-# Examples of formatting using the WriteExcel module
-#
-# reverse('©'), September 2002, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-
-require 'rubygems'
-require 'writeexcel'
-
-
-######################################################################
-#
-# Intro.
-#
-def intro(workbook)
-
- worksheet = workbook.add_worksheet('Introduction')
-
- worksheet.set_column(0, 0, 60)
-
- format = workbook.add_format()
- format.set_bold()
- format.set_size(14)
- format.set_color('blue')
- format.set_align('center')
-
- format2 = workbook.add_format()
- format2.set_bold()
- format2.set_color('blue')
-
- worksheet.write(2, 0, 'This workbook demonstrates some of', format)
- worksheet.write(3, 0, 'the formatting options provided by', format)
- worksheet.write(4, 0, 'the WriteExcel module.', format)
-
- worksheet.write('A7', 'Sections:', format2)
- worksheet.write('A8', "internal:Fonts!A1", 'Fonts' )
- worksheet.write('A9', "internal:'Named colors'!A1", 'Named colors' )
- worksheet.write('A10', "internal:'Standard colors'!A1", 'Standard colors')
- worksheet.write('A11', "internal:'Numeric formats'!A1", 'Numeric formats')
- worksheet.write('A12', "internal:Borders!A1", 'Borders' )
- worksheet.write('A13', "internal:Patterns!A1", 'Patterns' )
- worksheet.write('A14', "internal:Alignment!A1", 'Alignment' )
- worksheet.write('A15', "internal:Miscellaneous!A1", 'Miscellaneous' )
-
-end
-
-
-######################################################################
-#
-# Demonstrate the named colors.
-#
-def named_colors(workbook, heading, center)
-
- worksheet = workbook.add_worksheet('Named colors')
-
- worksheet.set_column(0, 3, 15)
-
- worksheet.write(0, 0, "Index", heading)
- worksheet.write(0, 1, "Index", heading)
- worksheet.write(0, 2, "Name", heading)
- worksheet.write(0, 3, "Color", heading)
-
- i = 1
-
- COLORS.each do |index, color|
- format = workbook.add_format(
- :bg_color => color,
- :pattern => 1,
- :border => 1
- )
-
- worksheet.write(i+1, 0, index, center)
- worksheet.write(i+1, 1, sprintf("0x%02X", index), center)
- worksheet.write(i+1, 2, color, center)
- worksheet.write(i+1, 3, '', format)
- i += 1
- end
-end
-
-
-######################################################################
-#
-# Demonstrate the standard Excel colors in the range 8..63.
-#
-def standard_colors(workbook, heading, center)
-
- worksheet = workbook.add_worksheet('Standard colors')
-
- worksheet.set_column(0, 3, 15)
-
- worksheet.write(0, 0, "Index", heading)
- worksheet.write(0, 1, "Index", heading)
- worksheet.write(0, 2, "Color", heading)
- worksheet.write(0, 3, "Name", heading)
-
- 8.upto(63) do |i|
- format = workbook.add_format(
- :bg_color => i,
- :pattern => 1,
- :border => 1
- )
-
- worksheet.write((i -7), 0, i, center)
- worksheet.write((i -7), 1, sprintf("0x%02X", i), center)
- worksheet.write((i -7), 2, '', format)
-
- # Add the color names
- if COLORS[i]
- worksheet.write((i -7), 3, COLORS[i], center)
-
- end
- end
-end
-
-
-######################################################################
-#
-# Demonstrate the standard numeric formats.
-#
-def numeric_formats(workbook, heading, center)
-
- worksheet = workbook.add_worksheet('Numeric formats')
-
- worksheet.set_column(0, 4, 15)
- worksheet.set_column(5, 5, 45)
-
- worksheet.write(0, 0, "Index", heading)
- worksheet.write(0, 1, "Index", heading)
- worksheet.write(0, 2, "Unformatted", heading)
- worksheet.write(0, 3, "Formatted", heading)
- worksheet.write(0, 4, "Negative", heading)
- worksheet.write(0, 5, "Format", heading)
-
- formats = []
- formats.push([ 0x00, 1234.567, 0, 'General' ])
- formats.push([ 0x01, 1234.567, 0, '0' ])
- formats.push([ 0x02, 1234.567, 0, '0.00' ])
- formats.push([ 0x03, 1234.567, 0, '#,##0' ])
- formats.push([ 0x04, 1234.567, 0, '#,##0.00' ])
- formats.push([ 0x05, 1234.567, -1234.567, '($#,##0_);($#,##0)' ])
- formats.push([ 0x06, 1234.567, -1234.567, '($#,##0_);[Red]($#,##0)' ])
- formats.push([ 0x07, 1234.567, -1234.567, '($#,##0.00_);($#,##0.00)' ])
- formats.push([ 0x08, 1234.567, -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ])
- formats.push([ 0x09, 0.567, 0, '0%' ])
- formats.push([ 0x0a, 0.567, 0, '0.00%' ])
- formats.push([ 0x0b, 1234.567, 0, '0.00E+00' ])
- formats.push([ 0x0c, 0.75, 0, '# ?/?' ])
- formats.push([ 0x0d, 0.3125, 0, '# ??/??' ])
- formats.push([ 0x0e, 36892.521, 0, 'm/d/yy' ])
- formats.push([ 0x0f, 36892.521, 0, 'd-mmm-yy' ])
- formats.push([ 0x10, 36892.521, 0, 'd-mmm' ])
- formats.push([ 0x11, 36892.521, 0, 'mmm-yy' ])
- formats.push([ 0x12, 36892.521, 0, 'h:mm AM/PM' ])
- formats.push([ 0x13, 36892.521, 0, 'h:mm:ss AM/PM' ])
- formats.push([ 0x14, 36892.521, 0, 'h:mm' ])
- formats.push([ 0x15, 36892.521, 0, 'h:mm:ss' ])
- formats.push([ 0x16, 36892.521, 0, 'm/d/yy h:mm' ])
- formats.push([ 0x25, 1234.567, -1234.567, '(#,##0_);(#,##0)' ])
- formats.push([ 0x26, 1234.567, -1234.567, '(#,##0_);[Red](#,##0)' ])
- formats.push([ 0x27, 1234.567, -1234.567, '(#,##0.00_);(#,##0.00)' ])
- formats.push([ 0x28, 1234.567, -1234.567, '(#,##0.00_);[Red](#,##0.00)' ])
- formats.push([ 0x29, 1234.567, -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ])
- formats.push([ 0x2a, 1234.567, -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ])
- formats.push([ 0x2b, 1234.567, -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ])
- formats.push([ 0x2c, 1234.567, -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ])
- formats.push([ 0x2d, 36892.521, 0, 'mm:ss' ])
- formats.push([ 0x2e, 3.0153, 0, '[h]:mm:ss' ])
- formats.push([ 0x2f, 36892.521, 0, 'mm:ss.0' ])
- formats.push([ 0x30, 1234.567, 0, '##0.0E+0' ])
- formats.push([ 0x31, 1234.567, 0, '@' ])
-
- i = 0
- formats.each do |format|
- style = workbook.add_format()
- style.set_num_format(format[0])
-
- i += 1
- worksheet.write(i, 0, format[0], center)
- worksheet.write(i, 1, sprintf("0x%02X", format[0]), center)
- worksheet.write(i, 2, format[1], center)
- worksheet.write(i, 3, format[1], style)
-
- if format[2] != 0
- worksheet.write(i, 4, format[2], style)
- end
-
- worksheet.write_string(i, 5, format[3])
- end
-end
-
-
-######################################################################
-#
-# Demonstrate the font options.
-#
-def fonts(workbook, heading, center)
-
- worksheet = workbook.add_worksheet('Fonts')
-
- worksheet.set_column(0, 0, 30)
- worksheet.set_column(1, 1, 10)
-
- worksheet.write(0, 0, "Font name", heading)
- worksheet.write(0, 1, "Font size", heading)
-
- fonts = []
- fonts.push([10, 'Arial' ])
- fonts.push([12, 'Arial' ])
- fonts.push([14, 'Arial' ])
- fonts.push([12, 'Arial Black' ])
- fonts.push([12, 'Arial Narrow' ])
- fonts.push([12, 'Century Schoolbook' ])
- fonts.push([12, 'Courier' ])
- fonts.push([12, 'Courier New' ])
- fonts.push([12, 'Garamond' ])
- fonts.push([12, 'Impact' ])
- fonts.push([12, 'Lucida Handwriting'] )
- fonts.push([12, 'Times New Roman' ])
- fonts.push([12, 'Symbol' ])
- fonts.push([12, 'Wingdings' ])
- fonts.push([12, 'A font that doesnt exist' ])
-
- i = 0
- fonts.each do |font|
- format = workbook.add_format()
-
- format.set_size(font[0])
- format.set_font(font[1])
-
- i += 1
- worksheet.write(i, 0, font[1], format)
- worksheet.write(i, 1, font[0], format)
- end
-
-end
-
-
-######################################################################
-#
-# Demonstrate the standard Excel border styles.
-#
-def borders(workbook, heading, center)
-
- worksheet = workbook.add_worksheet('Borders')
-
- worksheet.set_column(0, 4, 10)
- worksheet.set_column(5, 5, 40)
-
- worksheet.write(0, 0, "Index", heading)
- worksheet.write(0, 1, "Index", heading)
- worksheet.write(0, 3, "Style", heading)
- worksheet.write(0, 5, "The style is highlighted in red for ", heading)
- worksheet.write(1, 5, "emphasis, the default color is black.", heading)
-
- 0.upto(13) do |i|
- format = workbook.add_format()
- format.set_border(i)
- format.set_border_color('red')
- format.set_align('center')
-
- worksheet.write((2*(i+1)), 0, i, center)
- worksheet.write((2*(i+1)), 1, sprintf("0x%02X", i), center)
-
- worksheet.write((2*(i+1)), 3, "Border", format)
- end
-
- worksheet.write(30, 0, "Diag type", heading)
- worksheet.write(30, 1, "Index", heading)
- worksheet.write(30, 3, "Style", heading)
- worksheet.write(30, 5, "Diagonal Boder styles", heading)
-
- 1.upto(3) do |i|
- format = workbook.add_format()
- format.set_diag_type(i)
- format.set_diag_border(1)
- format.set_diag_color('red')
- format.set_align('center')
-
- worksheet.write((2*(i+15)), 0, i, center)
- worksheet.write((2*(i+15)), 1, sprintf("0x%02X", i), center)
-
- worksheet.write((2*(i+15)), 3, "Border", format)
- end
-end
-
-
-
-######################################################################
-#
-# Demonstrate the standard Excel cell patterns.
-#
-def patterns(workbook, heading, center)
-
- worksheet = workbook.add_worksheet('Patterns')
-
- worksheet.set_column(0, 4, 10)
- worksheet.set_column(5, 5, 50)
-
- worksheet.write(0, 0, "Index", heading)
- worksheet.write(0, 1, "Index", heading)
- worksheet.write(0, 3, "Pattern", heading)
-
- worksheet.write(0, 5, "The background colour has been set to silver.", heading)
- worksheet.write(1, 5, "The foreground colour has been set to green.", heading)
-
- 0.upto(18) do |i|
- format = workbook.add_format()
-
- format.set_pattern(i)
- format.set_bg_color('silver')
- format.set_fg_color('green')
- format.set_align('center')
-
- worksheet.write((2*(i+1)), 0, i, center)
- worksheet.write((2*(i+1)), 1, sprintf("0x%02X", i), center)
-
- worksheet.write((2*(i+1)), 3, "Pattern", format)
-
- if i == 1
- worksheet.write((2*(i+1)), 5, "This is solid colour, the most useful pattern.", heading)
- end
- end
-end
-
-
-######################################################################
-#
-# Demonstrate the standard Excel cell alignments.
-#
-def alignment(workbook, heading, center)
-
- worksheet = workbook.add_worksheet('Alignment')
-
- worksheet.set_column(0, 7, 12)
- worksheet.set_row(0, 40)
- worksheet.set_selection(7, 0)
-
- format01 = workbook.add_format()
- format02 = workbook.add_format()
- format03 = workbook.add_format()
- format04 = workbook.add_format()
- format05 = workbook.add_format()
- format06 = workbook.add_format()
- format07 = workbook.add_format()
- format08 = workbook.add_format()
- format09 = workbook.add_format()
- format10 = workbook.add_format()
- format11 = workbook.add_format()
- format12 = workbook.add_format()
- format13 = workbook.add_format()
- format14 = workbook.add_format()
- format15 = workbook.add_format()
- format16 = workbook.add_format()
- format17 = workbook.add_format()
-
- format02.set_align('top')
- format03.set_align('bottom')
- format04.set_align('vcenter')
- format05.set_align('vjustify')
- format06.set_text_wrap()
-
- format07.set_align('left')
- format08.set_align('right')
- format09.set_align('center')
- format10.set_align('fill')
- format11.set_align('justify')
- format12.set_merge()
-
- format13.set_rotation(45)
- format14.set_rotation(-45)
- format15.set_rotation(270)
-
- format16.set_shrink()
- format17.set_indent(1)
-
- worksheet.write(0, 0, 'Vertical', heading)
- worksheet.write(0, 1, 'top', format02)
- worksheet.write(0, 2, 'bottom', format03)
- worksheet.write(0, 3, 'vcenter', format04)
- worksheet.write(0, 4, 'vjustify', format05)
- worksheet.write(0, 5, "text\nwrap", format06)
-
- worksheet.write(2, 0, 'Horizontal', heading)
- worksheet.write(2, 1, 'left', format07)
- worksheet.write(2, 2, 'right', format08)
- worksheet.write(2, 3, 'center', format09)
- worksheet.write(2, 4, 'fill', format10)
- worksheet.write(2, 5, 'justify', format11)
-
- worksheet.write(3, 1, 'merge', format12)
- worksheet.write(3, 2, '', format12)
-
- worksheet.write(3, 3, 'Shrink ' * 3, format16)
- worksheet.write(3, 4, 'Indent', format17)
-
-
- worksheet.write(5, 0, 'Rotation', heading)
- worksheet.write(5, 1, 'Rotate 45', format13)
- worksheet.write(6, 1, 'Rotate -45', format14)
- worksheet.write(7, 1, 'Rotate 270', format15)
-end
-
-
-######################################################################
-#
-# Demonstrate other miscellaneous features.
-#
-def misc(workbook)
-
- worksheet = workbook.add_worksheet('Miscellaneous')
-
- worksheet.set_column(2, 2, 25)
-
- format01 = workbook.add_format()
- format02 = workbook.add_format()
- format03 = workbook.add_format()
- format04 = workbook.add_format()
- format05 = workbook.add_format()
- format06 = workbook.add_format()
- format07 = workbook.add_format()
-
- format01.set_underline(0x01)
- format02.set_underline(0x02)
- format03.set_underline(0x21)
- format04.set_underline(0x22)
- format05.set_font_strikeout()
- format06.set_font_outline()
- format07.set_font_shadow()
-
- worksheet.write(1, 2, 'Underline 0x01', format01)
- worksheet.write(3, 2, 'Underline 0x02', format02)
- worksheet.write(5, 2, 'Underline 0x21', format03)
- worksheet.write(7, 2, 'Underline 0x22', format04)
- worksheet.write(9, 2, 'Strikeout', format05)
- worksheet.write(11, 2, 'Outline (Macintosh only)', format06)
- worksheet.write(13, 2, 'Shadow (Macintosh only)', format07)
-end
-
-
-######################################################################
-#
-# main
-#
-workbook = WriteExcel.new('formats.xls')
-
-# Some common formats
-center = workbook.add_format(:align => 'center')
-heading = workbook.add_format(:align => 'center', :bold => 1)
-
-# The named colors
-COLORS = {
- 0x08 => 'black',
- 0x0C => 'blue',
- 0x10 => 'brown',
- 0x0F => 'cyan',
- 0x17 => 'gray',
- 0x11 => 'green',
- 0x0B => 'lime',
- 0x0E => 'magenta',
- 0x12 => 'navy',
- 0x35 => 'orange',
- 0x21 => 'pink',
- 0x14 => 'purple',
- 0x0A => 'red',
- 0x16 => 'silver',
- 0x09 => 'white',
- 0x0D => 'yellow',
-}
-
-# Call these subroutines to demonstrate different formatting options
-intro(workbook)
-fonts(workbook, heading, center)
-named_colors(workbook, heading, center)
-standard_colors(workbook, heading, center)
-numeric_formats(workbook, heading, center)
-borders(workbook, heading, center)
-patterns(workbook, heading, center)
-alignment(workbook, heading, center)
-misc(workbook)
-
-# Note: this is required
-workbook.close
-
+#!/usr/bin/ruby -w
+
+######################################################################
+#
+# Examples of formatting using the WriteExcel module
+#
+# reverse('©'), September 2002, John McNamara, jmcnamara@cpan.org
+#
+# original written in Perl by John McNamara
+# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
+#
+
+require 'rubygems'
+require 'writeexcel'
+
+
+######################################################################
+#
+# Intro.
+#
+def intro(workbook)
+
+ worksheet = workbook.add_worksheet('Introduction')
+
+ worksheet.set_column(0, 0, 60)
+
+ format = workbook.add_format()
+ format.set_bold()
+ format.set_size(14)
+ format.set_color('blue')
+ format.set_align('center')
+
+ format2 = workbook.add_format()
+ format2.set_bold()
+ format2.set_color('blue')
+
+ worksheet.write(2, 0, 'This workbook demonstrates some of', format)
+ worksheet.write(3, 0, 'the formatting options provided by', format)
+ worksheet.write(4, 0, 'the WriteExcel module.', format)
+
+ worksheet.write('A7', 'Sections:', format2)
+ worksheet.write('A8', "internal:Fonts!A1", 'Fonts' )
+ worksheet.write('A9', "internal:'Named colors'!A1", 'Named colors' )
+ worksheet.write('A10', "internal:'Standard colors'!A1", 'Standard colors')
+ worksheet.write('A11', "internal:'Numeric formats'!A1", 'Numeric formats')
+ worksheet.write('A12', "internal:Borders!A1", 'Borders' )
+ worksheet.write('A13', "internal:Patterns!A1", 'Patterns' )
+ worksheet.write('A14', "internal:Alignment!A1", 'Alignment' )
+ worksheet.write('A15', "internal:Miscellaneous!A1", 'Miscellaneous' )
+
+end
+
+
+######################################################################
+#
+# Demonstrate the named colors.
+#
+def named_colors(workbook, heading, center)
+
+ worksheet = workbook.add_worksheet('Named colors')
+
+ worksheet.set_column(0, 3, 15)
+
+ worksheet.write(0, 0, "Index", heading)
+ worksheet.write(0, 1, "Index", heading)
+ worksheet.write(0, 2, "Name", heading)
+ worksheet.write(0, 3, "Color", heading)
+
+ i = 1
+
+ COLORS.each do |index, color|
+ format = workbook.add_format(
+ :bg_color => color,
+ :pattern => 1,
+ :border => 1
+ )
+
+ worksheet.write(i+1, 0, index, center)
+ worksheet.write(i+1, 1, sprintf("0x%02X", index), center)
+ worksheet.write(i+1, 2, color, center)
+ worksheet.write(i+1, 3, '', format)
+ i += 1
+ end
+end
+
+
+######################################################################
+#
+# Demonstrate the standard Excel colors in the range 8..63.
+#
+def standard_colors(workbook, heading, center)
+
+ worksheet = workbook.add_worksheet('Standard colors')
+
+ worksheet.set_column(0, 3, 15)
+
+ worksheet.write(0, 0, "Index", heading)
+ worksheet.write(0, 1, "Index", heading)
+ worksheet.write(0, 2, "Color", heading)
+ worksheet.write(0, 3, "Name", heading)
+
+ 8.upto(63) do |i|
+ format = workbook.add_format(
+ :bg_color => i,
+ :pattern => 1,
+ :border => 1
+ )
+
+ worksheet.write((i -7), 0, i, center)
+ worksheet.write((i -7), 1, sprintf("0x%02X", i), center)
+ worksheet.write((i -7), 2, '', format)
+
+ # Add the color names
+ if COLORS[i]
+ worksheet.write((i -7), 3, COLORS[i], center)
+
+ end
+ end
+end
+
+
+######################################################################
+#
+# Demonstrate the standard numeric formats.
+#
+def numeric_formats(workbook, heading, center)
+
+ worksheet = workbook.add_worksheet('Numeric formats')
+
+ worksheet.set_column(0, 4, 15)
+ worksheet.set_column(5, 5, 45)
+
+ worksheet.write(0, 0, "Index", heading)
+ worksheet.write(0, 1, "Index", heading)
+ worksheet.write(0, 2, "Unformatted", heading)
+ worksheet.write(0, 3, "Formatted", heading)
+ worksheet.write(0, 4, "Negative", heading)
+ worksheet.write(0, 5, "Format", heading)
+
+ formats = []
+ formats.push([ 0x00, 1234.567, 0, 'General' ])
+ formats.push([ 0x01, 1234.567, 0, '0' ])
+ formats.push([ 0x02, 1234.567, 0, '0.00' ])
+ formats.push([ 0x03, 1234.567, 0, '#,##0' ])
+ formats.push([ 0x04, 1234.567, 0, '#,##0.00' ])
+ formats.push([ 0x05, 1234.567, -1234.567, '($#,##0_);($#,##0)' ])
+ formats.push([ 0x06, 1234.567, -1234.567, '($#,##0_);[Red]($#,##0)' ])
+ formats.push([ 0x07, 1234.567, -1234.567, '($#,##0.00_);($#,##0.00)' ])
+ formats.push([ 0x08, 1234.567, -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ])
+ formats.push([ 0x09, 0.567, 0, '0%' ])
+ formats.push([ 0x0a, 0.567, 0, '0.00%' ])
+ formats.push([ 0x0b, 1234.567, 0, '0.00E+00' ])
+ formats.push([ 0x0c, 0.75, 0, '# ?/?' ])
+ formats.push([ 0x0d, 0.3125, 0, '# ??/??' ])
+ formats.push([ 0x0e, 36892.521, 0, 'm/d/yy' ])
+ formats.push([ 0x0f, 36892.521, 0, 'd-mmm-yy' ])
+ formats.push([ 0x10, 36892.521, 0, 'd-mmm' ])
+ formats.push([ 0x11, 36892.521, 0, 'mmm-yy' ])
+ formats.push([ 0x12, 36892.521, 0, 'h:mm AM/PM' ])
+ formats.push([ 0x13, 36892.521, 0, 'h:mm:ss AM/PM' ])
+ formats.push([ 0x14, 36892.521, 0, 'h:mm' ])
+ formats.push([ 0x15, 36892.521, 0, 'h:mm:ss' ])
+ formats.push([ 0x16, 36892.521, 0, 'm/d/yy h:mm' ])
+ formats.push([ 0x25, 1234.567, -1234.567, '(#,##0_);(#,##0)' ])
+ formats.push([ 0x26, 1234.567, -1234.567, '(#,##0_);[Red](#,##0)' ])
+ formats.push([ 0x27, 1234.567, -1234.567, '(#,##0.00_);(#,##0.00)' ])
+ formats.push([ 0x28, 1234.567, -1234.567, '(#,##0.00_);[Red](#,##0.00)' ])
+ formats.push([ 0x29, 1234.567, -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ])
+ formats.push([ 0x2a, 1234.567, -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ])
+ formats.push([ 0x2b, 1234.567, -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ])
+ formats.push([ 0x2c, 1234.567, -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ])
+ formats.push([ 0x2d, 36892.521, 0, 'mm:ss' ])
+ formats.push([ 0x2e, 3.0153, 0, '[h]:mm:ss' ])
+ formats.push([ 0x2f, 36892.521, 0, 'mm:ss.0' ])
+ formats.push([ 0x30, 1234.567, 0, '##0.0E+0' ])
+ formats.push([ 0x31, 1234.567, 0, '@' ])
+
+ i = 0
+ formats.each do |format|
+ style = workbook.add_format()
+ style.set_num_format(format[0])
+
+ i += 1
+ worksheet.write(i, 0, format[0], center)
+ worksheet.write(i, 1, sprintf("0x%02X", format[0]), center)
+ worksheet.write(i, 2, format[1], center)
+ worksheet.write(i, 3, format[1], style)
+
+ if format[2] != 0
+ worksheet.write(i, 4, format[2], style)
+ end
+
+ worksheet.write_string(i, 5, format[3])
+ end
+end
+
+
+######################################################################
+#
+# Demonstrate the font options.
+#
+def fonts(workbook, heading, center)
+
+ worksheet = workbook.add_worksheet('Fonts')
+
+ worksheet.set_column(0, 0, 30)
+ worksheet.set_column(1, 1, 10)
+
+ worksheet.write(0, 0, "Font name", heading)
+ worksheet.write(0, 1, "Font size", heading)
+
+ fonts = []
+ fonts.push([10, 'Arial' ])
+ fonts.push([12, 'Arial' ])
+ fonts.push([14, 'Arial' ])
+ fonts.push([12, 'Arial Black' ])
+ fonts.push([12, 'Arial Narrow' ])
+ fonts.push([12, 'Century Schoolbook' ])
+ fonts.push([12, 'Courier' ])
+ fonts.push([12, 'Courier New' ])
+ fonts.push([12, 'Garamond' ])
+ fonts.push([12, 'Impact' ])
+ fonts.push([12, 'Lucida Handwriting'] )
+ fonts.push([12, 'Times New Roman' ])
+ fonts.push([12, 'Symbol' ])
+ fonts.push([12, 'Wingdings' ])
+ fonts.push([12, 'A font that doesnt exist' ])
+
+ i = 0
+ fonts.each do |font|
+ format = workbook.add_format()
+
+ format.set_size(font[0])
+ format.set_font(font[1])
+
+ i += 1
+ worksheet.write(i, 0, font[1], format)
+ worksheet.write(i, 1, font[0], format)
+ end
+
+end
+
+
+######################################################################
+#
+# Demonstrate the standard Excel border styles.
+#
+def borders(workbook, heading, center)
+
+ worksheet = workbook.add_worksheet('Borders')
+
+ worksheet.set_column(0, 4, 10)
+ worksheet.set_column(5, 5, 40)
+
+ worksheet.write(0, 0, "Index", heading)
+ worksheet.write(0, 1, "Index", heading)
+ worksheet.write(0, 3, "Style", heading)
+ worksheet.write(0, 5, "The style is highlighted in red for ", heading)
+ worksheet.write(1, 5, "emphasis, the default color is black.", heading)
+
+ 0.upto(13) do |i|
+ format = workbook.add_format()
+ format.set_border(i)
+ format.set_border_color('red')
+ format.set_align('center')
+
+ worksheet.write((2*(i+1)), 0, i, center)
+ worksheet.write((2*(i+1)), 1, sprintf("0x%02X", i), center)
+
+ worksheet.write((2*(i+1)), 3, "Border", format)
+ end
+
+ worksheet.write(30, 0, "Diag type", heading)
+ worksheet.write(30, 1, "Index", heading)
+ worksheet.write(30, 3, "Style", heading)
+ worksheet.write(30, 5, "Diagonal Boder styles", heading)
+
+ 1.upto(3) do |i|
+ format = workbook.add_format()
+ format.set_diag_type(i)
+ format.set_diag_border(1)
+ format.set_diag_color('red')
+ format.set_align('center')
+
+ worksheet.write((2*(i+15)), 0, i, center)
+ worksheet.write((2*(i+15)), 1, sprintf("0x%02X", i), center)
+
+ worksheet.write((2*(i+15)), 3, "Border", format)
+ end
+end
+
+
+
+######################################################################
+#
+# Demonstrate the standard Excel cell patterns.
+#
+def patterns(workbook, heading, center)
+
+ worksheet = workbook.add_worksheet('Patterns')
+
+ worksheet.set_column(0, 4, 10)
+ worksheet.set_column(5, 5, 50)
+
+ worksheet.write(0, 0, "Index", heading)
+ worksheet.write(0, 1, "Index", heading)
+ worksheet.write(0, 3, "Pattern", heading)
+
+ worksheet.write(0, 5, "The background colour has been set to silver.", heading)
+ worksheet.write(1, 5, "The foreground colour has been set to green.", heading)
+
+ 0.upto(18) do |i|
+ format = workbook.add_format()
+
+ format.set_pattern(i)
+ format.set_bg_color('silver')
+ format.set_fg_color('green')
+ format.set_align('center')
+
+ worksheet.write((2*(i+1)), 0, i, center)
+ worksheet.write((2*(i+1)), 1, sprintf("0x%02X", i), center)
+
+ worksheet.write((2*(i+1)), 3, "Pattern", format)
+
+ if i == 1
+ worksheet.write((2*(i+1)), 5, "This is solid colour, the most useful pattern.", heading)
+ end
+ end
+end
+
+
+######################################################################
+#
+# Demonstrate the standard Excel cell alignments.
+#
+def alignment(workbook, heading, center)
+
+ worksheet = workbook.add_worksheet('Alignment')
+
+ worksheet.set_column(0, 7, 12)
+ worksheet.set_row(0, 40)
+ worksheet.set_selection(7, 0)
+
+ format01 = workbook.add_format()
+ format02 = workbook.add_format()
+ format03 = workbook.add_format()
+ format04 = workbook.add_format()
+ format05 = workbook.add_format()
+ format06 = workbook.add_format()
+ format07 = workbook.add_format()
+ format08 = workbook.add_format()
+ format09 = workbook.add_format()
+ format10 = workbook.add_format()
+ format11 = workbook.add_format()
+ format12 = workbook.add_format()
+ format13 = workbook.add_format()
+ format14 = workbook.add_format()
+ format15 = workbook.add_format()
+ format16 = workbook.add_format()
+ format17 = workbook.add_format()
+
+ format02.set_align('top')
+ format03.set_align('bottom')
+ format04.set_align('vcenter')
+ format05.set_align('vjustify')
+ format06.set_text_wrap()
+
+ format07.set_align('left')
+ format08.set_align('right')
+ format09.set_align('center')
+ format10.set_align('fill')
+ format11.set_align('justify')
+ format12.set_merge()
+
+ format13.set_rotation(45)
+ format14.set_rotation(-45)
+ format15.set_rotation(270)
+
+ format16.set_shrink()
+ format17.set_indent(1)
+
+ worksheet.write(0, 0, 'Vertical', heading)
+ worksheet.write(0, 1, 'top', format02)
+ worksheet.write(0, 2, 'bottom', format03)
+ worksheet.write(0, 3, 'vcenter', format04)
+ worksheet.write(0, 4, 'vjustify', format05)
+ worksheet.write(0, 5, "text\nwrap", format06)
+
+ worksheet.write(2, 0, 'Horizontal', heading)
+ worksheet.write(2, 1, 'left', format07)
+ worksheet.write(2, 2, 'right', format08)
+ worksheet.write(2, 3, 'center', format09)
+ worksheet.write(2, 4, 'fill', format10)
+ worksheet.write(2, 5, 'justify', format11)
+
+ worksheet.write(3, 1, 'merge', format12)
+ worksheet.write(3, 2, '', format12)
+
+ worksheet.write(3, 3, 'Shrink ' * 3, format16)
+ worksheet.write(3, 4, 'Indent', format17)
+
+
+ worksheet.write(5, 0, 'Rotation', heading)
+ worksheet.write(5, 1, 'Rotate 45', format13)
+ worksheet.write(6, 1, 'Rotate -45', format14)
+ worksheet.write(7, 1, 'Rotate 270', format15)
+end
+
+
+######################################################################
+#
+# Demonstrate other miscellaneous features.
+#
+def misc(workbook)
+
+ worksheet = workbook.add_worksheet('Miscellaneous')
+
+ worksheet.set_column(2, 2, 25)
+
+ format01 = workbook.add_format()
+ format02 = workbook.add_format()
+ format03 = workbook.add_format()
+ format04 = workbook.add_format()
+ format05 = workbook.add_format()
+ format06 = workbook.add_format()
+ format07 = workbook.add_format()
+
+ format01.set_underline(0x01)
+ format02.set_underline(0x02)
+ format03.set_underline(0x21)
+ format04.set_underline(0x22)
+ format05.set_font_strikeout()
+ format06.set_font_outline()
+ format07.set_font_shadow()
+
+ worksheet.write(1, 2, 'Underline 0x01', format01)
+ worksheet.write(3, 2, 'Underline 0x02', format02)
+ worksheet.write(5, 2, 'Underline 0x21', format03)
+ worksheet.write(7, 2, 'Underline 0x22', format04)
+ worksheet.write(9, 2, 'Strikeout', format05)
+ worksheet.write(11, 2, 'Outline (Macintosh only)', format06)
+ worksheet.write(13, 2, 'Shadow (Macintosh only)', format07)
+end
+
+
+######################################################################
+#
+# main
+#
+workbook = WriteExcel.new('formats.xls')
+
+# Some common formats
+center = workbook.add_format(:align => 'center')
+heading = workbook.add_format(:align => 'center', :bold => 1)
+
+# The named colors
+COLORS = {
+ 0x08 => 'black',
+ 0x0C => 'blue',
+ 0x10 => 'brown',
+ 0x0F => 'cyan',
+ 0x17 => 'gray',
+ 0x11 => 'green',
+ 0x0B => 'lime',
+ 0x0E => 'magenta',
+ 0x12 => 'navy',
+ 0x35 => 'orange',
+ 0x21 => 'pink',
+ 0x14 => 'purple',
+ 0x0A => 'red',
+ 0x16 => 'silver',
+ 0x09 => 'white',
+ 0x0D => 'yellow',
+}
+
+# Call these subroutines to demonstrate different formatting options
+intro(workbook)
+fonts(workbook, heading, center)
+named_colors(workbook, heading, center)
+standard_colors(workbook, heading, center)
+numeric_formats(workbook, heading, center)
+borders(workbook, heading, center)
+patterns(workbook, heading, center)
+alignment(workbook, heading, center)
+misc(workbook)
+
+# Note: this is required
+workbook.close
+
View
58 examples/formula_result.rb
@@ -1,29 +1,29 @@
-#!/usr/bin/ruby -w
-
-#######################################################################
-#
-# Example of how to write Spreadsheet::WriteExcel formulas with a user
-# specified result.
-#
-# This is generally only required when writing a spreadsheet for an
-# application other than Excel where the formula isn't evaluated.
-#
-# reverse('©'), August 2005, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-
-require 'writeexcel'
-
-workbook = WriteExcel.new('formula_result.xls')
-worksheet = workbook.add_worksheet()
-format = workbook.add_format(:color => 'blue')
-
-worksheet.write('A1', '=1+2')
-worksheet.write('A2', '=1+2', format, 4)
-worksheet.write('A3', '="ABC"', nil, 'DEF')
-worksheet.write('A4', '=IF(A1 > 1, TRUE, FALSE)', nil, 'TRUE')
-worksheet.write('A5', '=1/0', nil, '#DIV/0!')
-
-workbook.close
+#!/usr/bin/ruby -w
+
+#######################################################################
+#
+# Example of how to write Spreadsheet::WriteExcel formulas with a user
+# specified result.
+#
+# This is generally only required when writing a spreadsheet for an
+# application other than Excel where the formula isn't evaluated.
+#
+# reverse('©'), August 2005, John McNamara, jmcnamara@cpan.org
+#
+# original written in Perl by John McNamara
+# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
+#
+
+require 'writeexcel'
+
+workbook = WriteExcel.new('formula_result.xls')
+worksheet = workbook.add_worksheet()
+format = workbook.add_format(:color => 'blue')
+
+worksheet.write('A1', '=1+2')
+worksheet.write('A2', '=1+2', format, 4)
+worksheet.write('A3', '="ABC"', nil, 'DEF')
+worksheet.write('A4', '=IF(A1 > 1, TRUE, FALSE)', nil, 'TRUE')
+worksheet.write('A5', '=1/0', nil, '#DIV/0!')
+
+workbook.close
View
272 examples/header.rb
@@ -1,136 +1,136 @@
-#!/usr/bin/ruby -w
-
-######################################################################
-#
-# This program shows several examples of how to set up headers and
-# footers with WriteExcel.
-#
-# The control characters used in the header/footer strings are:
-#
-# Control Category Description
-# ======= ======== ===========
-# &L Justification Left
-# &C Center
-# &R Right
-#
-# &P Information Page number
-# &N Total number of pages
-# &D Date
-# &T Time
-# &F File name
-# &A Worksheet name
-#
-# &fontsize Font Font size
-# &"font,style" Font name and style
-# &U Single underline
-# &E Double underline
-# &S Strikethrough
-# &X Superscript
-# &Y Subscript
-#
-# && Miscellaneous Literal ampersand &
-#
-#
-# reverse('©'), March 2002, John McNamara, jmcnamara@cpan.org
-#
-# original written in Perl by John McNamara
-# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
-#
-
-require 'rubygems'
-require 'writeexcel'
-
-workbook = WriteExcel.new("headers.xls")
-preview = "Select Print Preview to see the header and footer"
-
-
-######################################################################
-#
-# A simple example to start