writeexcel 0.6.18 → 0.6.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9f08faee160c80efda98d7e3f42d07aa547a92ca
4
+ data.tar.gz: d1e75487c065ad0ac74dc978aac6218c21621aa3
5
+ SHA512:
6
+ metadata.gz: c6e152b9677247808da606c2bacb7f403b4c45f3f6f093ce6958a5de510d1bac8c81adb3f2e47591ffa79183f348db3c5f4429264c4d96abc81783eb6e6cb33f
7
+ data.tar.gz: 61d1223ff7e8884ec3a92d79b8ec6af8d0f15696d0f1958c4a0a45c813d2aee5deebe0b470d6028423562a518265fd1f224d17b850c451ad506a324f71f937e2
@@ -90,6 +90,9 @@ You must save source file in UTF8 and run ruby with -Ku option or set $KCODE='u'
90
90
  when use urf8 string data.
91
91
 
92
92
  == Recent Changes
93
+ v0.6.19
94
+ * Bug fix in Worksheet#write_url_internal
95
+
93
96
  v0.6.18
94
97
  * Bug fix in compatibility_mode (Worksheet#write_number).
95
98
 
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/ruby
2
+ # -*- coding: utf-8 -*-
3
+ ###############################################################################
4
+ #
5
+ # Example of how to use the WriteExcel module to write internal and internal
6
+ # hyperlinks.
7
+ #
8
+ # If you wish to run this program and follow the hyperlinks you should create
9
+ # the following directory structure:
10
+ #
11
+ # C:\ -- Temp --+-- Europe
12
+ # |
13
+ # \-- Asia
14
+ #
15
+ #
16
+ # See also hyperlink1.rb for web URL examples.
17
+ #
18
+ # reverse('©'), March 2002, John McNamara, jmcnamara@cpan.org
19
+ #
20
+ # original written in Perl by John McNamara
21
+ # converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
22
+ #
23
+ require 'rubygems'
24
+ require 'writeexcel'
25
+
26
+ # Create three workbooks:
27
+ # C:\Temp\Europe\Ireland.xls
28
+ # C:\Temp\Europe\Italy.xls
29
+ # C:\Temp\Asia\China.xls
30
+ #
31
+ ireland = WriteExcel.new('C:\Temp\Europe\Ireland.xls')
32
+ ire_links = ireland.add_worksheet('Links')
33
+ ire_sales = ireland.add_worksheet('Sales')
34
+ ire_data = ireland.add_worksheet('Product Data')
35
+
36
+ italy = WriteExcel.new('C:\Temp\Europe\Italy.xls')
37
+ ita_links = italy.add_worksheet('Links')
38
+ ita_sales = italy.add_worksheet('Sales')
39
+ ita_data = italy.add_worksheet('Product Data')
40
+
41
+ china = WriteExcel.new('C:\Temp\Asia\China.xls')
42
+ cha_links = china.add_worksheet('Links')
43
+ cha_sales = china.add_worksheet('Sales')
44
+ cha_data = china.add_worksheet('Product Data')
45
+
46
+ # Add a format
47
+ format = ireland.add_format(:color => 'green', :bold => 1)
48
+ ire_links.set_column('A:B', 25)
49
+
50
+
51
+ ###############################################################################
52
+ #
53
+ # Examples of internal links
54
+ #
55
+ ire_links.write('A1', 'Internal links', format)
56
+
57
+ # Internal link
58
+ ire_links.write('A2', 'internal:Sales!A2')
59
+
60
+ # Internal link to a range
61
+ ire_links.write('A3', 'internal:Sales!A3:D3')
62
+
63
+ # Internal link with an alternative string
64
+ ire_links.write('A4', 'internal:Sales!A4', 'Link')
65
+
66
+ # Internal link with a format
67
+ ire_links.write('A5', 'internal:Sales!A5', format)
68
+
69
+ # Internal link with an alternative string and format
70
+ ire_links.write('A6', 'internal:Sales!A6', 'Link', format)
71
+
72
+ # Internal link (spaces in worksheet name)
73
+ ire_links.write('A7', "internal:'Product Data'!A7")
74
+
75
+
76
+ ###############################################################################
77
+ #
78
+ # Examples of external links
79
+ #
80
+ ire_links.write('B1', 'External links', format)
81
+
82
+ # External link to a local file
83
+ ire_links.write('B2', 'external:Italy.xls')
84
+
85
+ # External link to a local file with worksheet
86
+ ire_links.write('B3', 'external:Italy.xls#Sales!B3')
87
+
88
+ # External link to a local file with worksheet and alternative string
89
+ ire_links.write('B4', 'external:Italy.xls#Sales!B4', 'Link')
90
+
91
+ # External link to a local file with worksheet and format
92
+ ire_links.write('B5', 'external:Italy.xls#Sales!B5', format)
93
+
94
+ # External link to a remote file, absolute path
95
+ ire_links.write('B6', 'external:c:/Temp/Asia/China.xls')
96
+
97
+ # External link to a remote file, relative path
98
+ ire_links.write('B7', 'external:../Asia/China.xls')
99
+
100
+ # External link to a remote file with worksheet
101
+ ire_links.write('B8', 'external:c:/Temp/Asia/China.xls#Sales!B8')
102
+
103
+ # External link to a remote file with worksheet (with spaces in the name)
104
+ ire_links.write('B9', "external:c:/Temp/Asia/China.xls#'Product Data'!B9")
105
+
106
+
107
+ ###############################################################################
108
+ #
109
+ # Some utility links to return to the main sheet
110
+ #
111
+ ire_sales.write('A2', 'internal:Links!A2', 'Back')
112
+ ire_sales.write('A3', 'internal:Links!A3', 'Back')
113
+ ire_sales.write('A4', 'internal:Links!A4', 'Back')
114
+ ire_sales.write('A5', 'internal:Links!A5', 'Back')
115
+ ire_sales.write('A6', 'internal:Links!A6', 'Back')
116
+ ire_data.write('A7', 'internal:Links!A7', 'Back')
117
+
118
+ ita_links.write('A1', 'external:Ireland.xls#Links!B2', 'Back')
119
+ ita_sales.write('B3', 'external:Ireland.xls#Links!B3', 'Back')
120
+ ita_sales.write('B4', 'external:Ireland.xls#Links!B4', 'Back')
121
+ ita_sales.write('B5', 'external:Ireland.xls#Links!B5', 'Back')
122
+ cha_links.write('A1', 'external:../Europe/Ireland.xls#Links!B6', 'Back')
123
+ cha_sales.write('B8', 'external:../Europe/Ireland.xls#Links!B8', 'Back')
124
+ cha_data.write('B9', 'external:../Europe/Ireland.xls#Links!B9', 'Back')
125
+
126
+ ireland.close
127
+ italy.close
128
+ china.close
129
+
@@ -1,3 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  module ConvertDateTime
2
3
  #
3
4
  # The function takes a date and time in ISO8601 "yyyy-mm-ddThh:mm:ss.ss" format
@@ -18,14 +19,7 @@ module ConvertDateTime
18
19
  # undef if the date is invalid.
19
20
  #
20
21
  def convert_date_time(date_time_string, date_1904 = false) #:nodoc:
21
- date_time = date_time_string
22
-
23
- days = 0 # Number of days since epoch
24
- seconds = 0 # Time expressed as fraction of 24h hours in seconds
25
-
26
- # Strip leading and trailing whitespace.
27
- date_time.sub!(/^\s+/, '')
28
- date_time.sub!(/\s+$/, '')
22
+ date_time = date_time_string.sub(/^\s+/, '').sub(/\s+$/, '').sub(/Z$/, '')
29
23
 
30
24
  # Check for invalid date char.
31
25
  return nil if date_time =~ /[^0-9T:\-\.Z]/
@@ -33,8 +27,7 @@ def convert_date_time(date_time_string, date_1904 = false) #:nodoc:
33
27
  # Check for "T" after date or before time.
34
28
  return nil unless date_time =~ /\dT|T\d/
35
29
 
36
- # Strip trailing Z in ISO8601 date.
37
- date_time.sub!(/Z$/, '')
30
+ seconds = 0 # Time expressed as fraction of 24h hours in seconds
38
31
 
39
32
  # Split into date and time.
40
33
  date, time = date_time.split(/T/)
@@ -271,12 +271,11 @@ def pack_dv_formula(formula) #:nodoc:
271
271
 
272
272
  # Strip the = sign at the beginning of the formula string
273
273
  formula = formula.to_s unless formula.respond_to?(:to_str)
274
- formula.sub!(/^=/, '')
275
274
 
276
275
  # In order to raise formula errors from the point of view of the calling
277
276
  # program we use an eval block and re-raise the error from here.
278
277
  #
279
- tokens = @parser.parse_formula(formula) # ????
278
+ tokens = @parser.parse_formula(formula.sub(/^=/, '')) # ????
280
279
 
281
280
  # if ($@) {
282
281
  # $@ =~ s/\n$//; # Strip the \n used in the Formula.pm die()
@@ -1,5 +1,5 @@
1
1
  require 'writeexcel'
2
2
 
3
3
  class WriteExcel < Workbook
4
- VERSION = "0.6.18"
4
+ VERSION = "0.6.19"
5
5
  end
@@ -2876,13 +2876,10 @@ def write_formula(*args)
2876
2876
  # worksheet3.repeat_formula('B1', now)
2877
2877
  #
2878
2878
  def store_formula(formula) #:nodoc:
2879
- # Strip the = sign at the beginning of the formula string
2880
- formula.sub!(/^=/, '')
2881
-
2882
2879
  # In order to raise formula errors from the point of view of the calling
2883
2880
  # program we use an eval block and re-raise the error from here.
2884
2881
  #
2885
- tokens = parser.parse_formula(formula)
2882
+ tokens = parser.parse_formula(formula.sub(/^=/, ''))
2886
2883
 
2887
2884
  # if ($@) {
2888
2885
  # $@ =~ s/\n$// # Strip the \n used in the Formula.pm die()
@@ -5219,10 +5216,10 @@ def write_url_internal(row1, col1, row2, col2, url, str = nil, format = nil)
5219
5216
  xf = format || url_format # The cell format
5220
5217
 
5221
5218
  # Strip URL type
5222
- url.sub!(/^internal:/, '')
5219
+ url = url.sub(/^internal:/, '')
5223
5220
 
5224
5221
  # Write the visible label but protect against url recursion in write().
5225
- str = url unless str
5222
+ str = url.dup unless str
5226
5223
  error = write_string(row1, col1, str, xf)
5227
5224
  return error if error == -2
5228
5225
 
@@ -5236,13 +5233,14 @@ def write_url_internal(row1, col1, row2, col2, url, str = nil, format = nil)
5236
5233
  encoding = 0
5237
5234
 
5238
5235
  # Convert an Utf8 URL type and to a null terminated wchar string.
5239
- if is_utf8?(str)
5240
- # Quote sheet name if not already, i.e., Sheet!A1 to 'Sheet!A1'.
5241
- url.sub!(/^(.+)!/, "'\1'!") if not url =~ /^'/
5242
- # URL is null terminated.
5243
- ruby_18 { url = utf8_to_16be(url) + "\0\0" } ||
5244
- ruby_19 { url = url.encode('UTF-16LE') + "\0\0".encode('UTF-16LE') }
5245
- encoding = 1
5236
+ ruby_18 do
5237
+ if is_utf8?(url)
5238
+ # Quote sheet name if not already, i.e., Sheet!A1 to 'Sheet!A1'.
5239
+ url = "'#{sheetname_from_url(url)}'!#{cell_from_url(url)}" if not url =~ /^'/
5240
+ # URL is null terminated.
5241
+ ruby_18 { url = utf8_to_16be(url) + "\0\0" } ||
5242
+ encoding = 1
5243
+ end
5246
5244
  end
5247
5245
 
5248
5246
  # Convert an Ascii URL type and to a null terminated wchar string.
@@ -5252,7 +5250,7 @@ def write_url_internal(row1, col1, row2, col2, url, str = nil, format = nil)
5252
5250
  end
5253
5251
 
5254
5252
  # Pack the length of the URL as chars (not wchars)
5255
- url_len = [(url.length/2).to_i].pack("V")
5253
+ url_len = [(url.bytesize/2).to_i].pack("V")
5256
5254
 
5257
5255
  # Calculate the data length
5258
5256
  length = 0x24 + url.bytesize
@@ -5267,6 +5265,16 @@ def write_url_internal(row1, col1, row2, col2, url, str = nil, format = nil)
5267
5265
  error
5268
5266
  end
5269
5267
 
5268
+ def sheetname_from_url(url)
5269
+ sheetname, cell = url.split('!')
5270
+ sheetname
5271
+ end
5272
+
5273
+ def cell_from_url(url)
5274
+ sheetname, cell = url.split('!')
5275
+ cell
5276
+ end
5277
+
5270
5278
  #
5271
5279
  # Write links to external directory names such as 'c:\foo.xls',
5272
5280
  # c:\foo.xls#Sheet1!A1', '../../foo.xls'. and '../../foo.xls#Sheet1!A1'.
@@ -5279,7 +5287,7 @@ def write_url_internal(row1, col1, row2, col2, url, str = nil, format = nil)
5279
5287
  def write_url_external(row1, col1, row2, col2, url, str = nil, format = nil) #:nodoc:
5280
5288
  # Network drives are different. We will handle them separately
5281
5289
  # MS/Novell network drives and shares start with \\
5282
- if url =~ /^external:\\\\/
5290
+ if url =~ /^external:(\\\\|\/\/)/
5283
5291
  return write_url_external_net(row1, col1, row2, col2, url, str, format)
5284
5292
  end
5285
5293
 
@@ -5290,12 +5298,10 @@ def write_url_external(row1, col1, row2, col2, url, str = nil, format = nil)
5290
5298
 
5291
5299
  # Strip URL type and change Unix dir separator to Dos style (if needed)
5292
5300
  #
5293
- url.sub!(/^external:/, '')
5294
- url.gsub!(%r|/|, '\\')
5295
-
5301
+ url = url.sub(/^external:/, '').gsub(%r|/|, '\\')
5296
5302
 
5297
5303
  # Write the visible label but protect against url recursion in write().
5298
- str = url.sub!(/\#/, ' - ') unless str
5304
+ str = url.sub(/\#/, ' - ') unless str
5299
5305
  error = write_string(row1, col1, str, xf)
5300
5306
  return error if error == -2
5301
5307
 
@@ -5309,7 +5315,7 @@ def write_url_external(row1, col1, row2, col2, url, str = nil, format = nil)
5309
5315
  dir_long, link_type, sheet_len, sheet = analyze_link(url, absolute)
5310
5316
 
5311
5317
  # Pack the link type
5312
- link_type = link_type.pack("V")
5318
+ link_type = [link_type].pack("V")
5313
5319
 
5314
5320
  # Calculate the up-level dir count e.g. (..\..\..\ == 3)
5315
5321
  up_count = 0
@@ -5375,11 +5381,10 @@ def write_url_external_net(row1, col1, row2, col2, url, str, format) #:nod
5375
5381
 
5376
5382
  # Strip URL type and change Unix dir separator to Dos style (if needed)
5377
5383
  #
5378
- url.sub!(/^external:/, '')
5379
- url.gsub!(%r|/|, '\\')
5384
+ url = url.sub(/^external:/, '').gsub!(%r|/|, '\\')
5380
5385
 
5381
5386
  # Write the visible label but protect against url recursion in write().
5382
- str = url.sub!(/\#/, ' - ') unless str
5387
+ str = url.sub(/\#/, ' - ') unless str
5383
5388
  error = write_string(row1, col1, str, xf)
5384
5389
  return error if error == -2
5385
5390
 
@@ -24,6 +24,15 @@ def setup
24
24
  @smiley = [0x263a].pack('n')
25
25
  end
26
26
 
27
+ def teardown
28
+ if @workbook.instance_variable_get(:@filehandle)
29
+ @workbook.instance_variable_get(:@filehandle).close(true)
30
+ end
31
+ if @worksheet.instance_variable_get(:@filehandle)
32
+ @worksheet.instance_variable_get(:@filehandle).close(true)
33
+ end
34
+ end
35
+
27
36
  def test_no_worksheet_cell_data
28
37
  data = @worksheet.__send__("store_dimensions")
29
38
 
@@ -369,6 +378,13 @@ def test_repeat_formula
369
378
  assert_equal(expected, results)
370
379
  end
371
380
 
381
+ def test_store_formula_should_not_change_formula_string
382
+ formula = '=SUM(A1:D1)'
383
+ @worksheet.store_formula(formula)
384
+
385
+ assert_equal('=SUM(A1:D1)', formula)
386
+ end
387
+
372
388
  def test_merge_range
373
389
  formula = @worksheet.__send__("store_formula", '=A1 * 3 + 50')
374
390
  @worksheet.merge_range('C6:E8', 'Test', @format)
@@ -19,6 +19,15 @@ class TC_rows < Test::Unit::TestCase
19
19
  def setup
20
20
  end
21
21
 
22
+ def teardown
23
+ if @workbook.instance_variable_get(:@filehandle)
24
+ @workbook.instance_variable_get(:@filehandle).close(true)
25
+ end
26
+ if @worksheet.instance_variable_get(:@filehandle)
27
+ @worksheet.instance_variable_get(:@filehandle).close(true)
28
+ end
29
+ end
30
+
22
31
  def test_1
23
32
  file = StringIO.new
24
33
  workbook = WriteExcel.new(file)
@@ -55,6 +55,15 @@ def setup
55
55
  ]
56
56
  end
57
57
 
58
+ def teardown
59
+ if @workbook.instance_variable_get(:@filehandle)
60
+ @workbook.instance_variable_get(:@filehandle).close(true)
61
+ end
62
+ if @worksheet.instance_variable_get(:@filehandle)
63
+ @worksheet.instance_variable_get(:@filehandle).close(true)
64
+ end
65
+ end
66
+
58
67
  def test_to_tests
59
68
  @tests.each do |test|
60
69
  io = StringIO.new
@@ -26,6 +26,13 @@ def fit_cmp(a, b)
26
26
  return (a-b).abs < @fit_delta
27
27
  end
28
28
 
29
+ def test_convert_date_time_should_not_change_date_time_string
30
+ date_time = ' 1899-12-31T00:00:00.0004Z '
31
+ @worksheet.convert_date_time(date_time)
32
+
33
+ assert_equal(' 1899-12-31T00:00:00.0004Z ', date_time)
34
+ end
35
+
29
36
  def test_float_comparison_function
30
37
  # pass: diff < @fit_delta
31
38
  date_time = '1899-12-31T00:00:00.0004'
@@ -29,6 +29,15 @@ def setup
29
29
  @worksheet = @workbook.add_worksheet
30
30
  end
31
31
 
32
+ def teardown
33
+ if @workbook.instance_variable_get(:@filehandle)
34
+ @workbook.instance_variable_get(:@filehandle).close(true)
35
+ end
36
+ if @worksheet.instance_variable_get(:@filehandle)
37
+ @worksheet.instance_variable_get(:@filehandle).close(true)
38
+ end
39
+ end
40
+
32
41
  def test_for_store_mso_dg_container
33
42
  caption = sprintf(" \t_store_mso_dg_container()")
34
43
  data = [0xC8]
@@ -32,6 +32,15 @@ def setup
32
32
  @worksheet3 = @workbook.add_worksheet
33
33
  end
34
34
 
35
+ def teardown
36
+ if @workbook.instance_variable_get(:@filehandle)
37
+ @workbook.instance_variable_get(:@filehandle).close(true)
38
+ end
39
+ if @worksheet.instance_variable_get(:@filehandle)
40
+ @worksheet.instance_variable_get(:@filehandle).close(true)
41
+ end
42
+ end
43
+
35
44
  =begin
36
45
  def test_1_time
37
46
  count = 1
@@ -21,6 +21,15 @@ def setup
21
21
  @worksheet = @workbook.add_worksheet
22
22
  end
23
23
 
24
+ def teardown
25
+ if @workbook.instance_variable_get(:@filehandle)
26
+ @workbook.instance_variable_get(:@filehandle).close(true)
27
+ end
28
+ if @worksheet.instance_variable_get(:@filehandle)
29
+ @worksheet.instance_variable_get(:@filehandle).close(true)
30
+ end
31
+ end
32
+
24
33
  def test_blank_author_name
25
34
  comment = Writeexcel::Worksheet::Comment.new(@worksheet, 2, 0, 'Test')
26
35
  obj_id = 1
@@ -21,6 +21,15 @@ def setup
21
21
  @worksheet = @workbook.add_worksheet
22
22
  end
23
23
 
24
+ def teardown
25
+ if @workbook.instance_variable_get(:@filehandle)
26
+ @workbook.instance_variable_get(:@filehandle).close(true)
27
+ end
28
+ if @worksheet.instance_variable_get(:@filehandle)
29
+ @worksheet.instance_variable_get(:@filehandle).close(true)
30
+ end
31
+ end
32
+
24
33
  def test_txo
25
34
  string = 'aaa'
26
35
  comment = Writeexcel::Worksheet::Comment.new(@worksheet, 1, 1, ' ')
@@ -25,6 +25,15 @@ def setup
25
25
  @worksheet = @workbook.add_worksheet
26
26
  end
27
27
 
28
+ def teardown
29
+ if @workbook.instance_variable_get(:@filehandle)
30
+ @workbook.instance_variable_get(:@filehandle).close(true)
31
+ end
32
+ if @worksheet.instance_variable_get(:@filehandle)
33
+ @worksheet.instance_variable_get(:@filehandle).close(true)
34
+ end
35
+ end
36
+
28
37
  ###############################################################################
29
38
  #
30
39
  # Tests extracted from images imported into Excel.
@@ -21,6 +21,15 @@ def setup
21
21
  @validations = Writeexcel::Worksheet::DataValidations.new
22
22
  end
23
23
 
24
+ def teardown
25
+ if @workbook.instance_variable_get(:@filehandle)
26
+ @workbook.instance_variable_get(:@filehandle).close(true)
27
+ end
28
+ if @worksheet.instance_variable_get(:@filehandle)
29
+ @worksheet.instance_variable_get(:@filehandle).close(true)
30
+ end
31
+ end
32
+
24
33
  def test_1
25
34
  obj_id = 1
26
35
  dv_count = 1
@@ -22,6 +22,15 @@ def setup
22
22
  @data_validation = Writeexcel::Worksheet::DataValidation.new(worksheet.__send__("parser"), {})
23
23
  end
24
24
 
25
+ def teardown
26
+ if @workbook.instance_variable_get(:@filehandle)
27
+ @workbook.instance_variable_get(:@filehandle).close(true)
28
+ end
29
+ if @worksheet.instance_variable_get(:@filehandle)
30
+ @worksheet.instance_variable_get(:@filehandle).close(true)
31
+ end
32
+ end
33
+
25
34
  def test_empty_string
26
35
  string = ''
27
36
  max_length = 32
@@ -22,6 +22,15 @@ def setup
22
22
  @data_validation = Writeexcel::Worksheet::DataValidation.new(@worksheet.__send__("parser"), {})
23
23
  end
24
24
 
25
+ def teardown
26
+ if @workbook.instance_variable_get(:@filehandle)
27
+ @workbook.instance_variable_get(:@filehandle).close(true)
28
+ end
29
+ if @worksheet.instance_variable_get(:@filehandle)
30
+ @worksheet.instance_variable_get(:@filehandle).close(true)
31
+ end
32
+ end
33
+
25
34
  def test_integer_values
26
35
  formula = '10'
27
36
 
@@ -192,6 +201,13 @@ def test_undefined_value
192
201
  assert_equal(target, result, caption)
193
202
  end
194
203
 
204
+ def test_pack_dv_formula_should_not_change_formula_string
205
+ formula = '=SUM(A1:D1)'
206
+ @data_validation.__send__("pack_dv_formula", formula)
207
+
208
+ assert_equal('=SUM(A1:D1)', formula)
209
+ end
210
+
195
211
  ###############################################################################
196
212
  #
197
213
  # Unpack the binary data into a format suitable for printing in tests.
@@ -29,6 +29,15 @@ def setup
29
29
  @test_file = StringIO.new
30
30
  end
31
31
 
32
+ def teardown
33
+ if @workbook.instance_variable_get(:@filehandle)
34
+ @workbook.instance_variable_get(:@filehandle).close(true)
35
+ end
36
+ if @worksheet.instance_variable_get(:@filehandle)
37
+ @worksheet.instance_variable_get(:@filehandle).close(true)
38
+ end
39
+ end
40
+
32
41
  def test_same_as_previous_plus_creation_date
33
42
  smiley = '☺' # chr 0x263A; in perl
34
43
 
@@ -426,6 +426,115 @@ def test_hyperlink1
426
426
  compare_file("#{PERL_OUTDIR}/hyperlink.xls", @file)
427
427
  end
428
428
 
429
+ def test_hyperlink2
430
+ # Create workbook1
431
+ ireland = WriteExcel.new(@file)
432
+ ire_links = ireland.add_worksheet('Links')
433
+ ire_sales = ireland.add_worksheet('Sales')
434
+ ire_data = ireland.add_worksheet('Product Data')
435
+
436
+ file2 = StringIO.new
437
+ italy = WriteExcel.new(file2)
438
+ ita_links = italy.add_worksheet('Links')
439
+ ita_sales = italy.add_worksheet('Sales')
440
+ ita_data = italy.add_worksheet('Product Data')
441
+
442
+ file3 = StringIO.new
443
+ china = WriteExcel.new(file3)
444
+ cha_links = china.add_worksheet('Links')
445
+ cha_sales = china.add_worksheet('Sales')
446
+ cha_data = china.add_worksheet('Product Data')
447
+
448
+ # Add a format
449
+ format = ireland.add_format(:color => 'green', :bold => 1)
450
+ ire_links.set_column('A:B', 25)
451
+
452
+
453
+ ###############################################################################
454
+ #
455
+ # Examples of internal links
456
+ #
457
+ ire_links.write('A1', 'Internal links', format)
458
+
459
+ # Internal link
460
+ ire_links.write('A2', 'internal:Sales!A2')
461
+
462
+ # Internal link to a range
463
+ ire_links.write('A3', 'internal:Sales!A3:D3')
464
+
465
+ # Internal link with an alternative string
466
+ ire_links.write('A4', 'internal:Sales!A4', 'Link')
467
+
468
+ # Internal link with a format
469
+ ire_links.write('A5', 'internal:Sales!A5', format)
470
+
471
+ # Internal link with an alternative string and format
472
+ ire_links.write('A6', 'internal:Sales!A6', 'Link', format)
473
+
474
+ # Internal link (spaces in worksheet name)
475
+ ire_links.write('A7', "internal:'Product Data'!A7")
476
+
477
+
478
+ ###############################################################################
479
+ #
480
+ # Examples of external links
481
+ #
482
+ ire_links.write('B1', 'External links', format)
483
+
484
+ # External link to a local file
485
+ ire_links.write('B2', 'external:Italy.xls')
486
+
487
+ # External link to a local file with worksheet
488
+ ire_links.write('B3', 'external:Italy.xls#Sales!B3')
489
+
490
+ # External link to a local file with worksheet and alternative string
491
+ ire_links.write('B4', 'external:Italy.xls#Sales!B4', 'Link')
492
+
493
+ # External link to a local file with worksheet and format
494
+ ire_links.write('B5', 'external:Italy.xls#Sales!B5', format)
495
+
496
+ # External link to a remote file, absolute path
497
+ ire_links.write('B6', 'external:c:/Temp/Asia/China.xls')
498
+
499
+ # External link to a remote file, relative path
500
+ ire_links.write('B7', 'external:../Asia/China.xls')
501
+
502
+ # External link to a remote file with worksheet
503
+ ire_links.write('B8', 'external:c:/Temp/Asia/China.xls#Sales!B8')
504
+
505
+ # External link to a remote file with worksheet (with spaces in the name)
506
+ ire_links.write('B9', "external:c:/Temp/Asia/China.xls#'Product Data'!B9")
507
+
508
+
509
+ ###############################################################################
510
+ #
511
+ # Some utility links to return to the main sheet
512
+ #
513
+ ire_sales.write('A2', 'internal:Links!A2', 'Back')
514
+ ire_sales.write('A3', 'internal:Links!A3', 'Back')
515
+ ire_sales.write('A4', 'internal:Links!A4', 'Back')
516
+ ire_sales.write('A5', 'internal:Links!A5', 'Back')
517
+ ire_sales.write('A6', 'internal:Links!A6', 'Back')
518
+ ire_data.write('A7', 'internal:Links!A7', 'Back')
519
+
520
+ ita_links.write('A1', 'external:Ireland.xls#Links!B2', 'Back')
521
+ ita_sales.write('B3', 'external:Ireland.xls#Links!B3', 'Back')
522
+ ita_sales.write('B4', 'external:Ireland.xls#Links!B4', 'Back')
523
+ ita_sales.write('B5', 'external:Ireland.xls#Links!B5', 'Back')
524
+ cha_links.write('A1', 'external:../Europe/Ireland.xls#Links!B6', 'Back')
525
+ cha_sales.write('B8', 'external:../Europe/Ireland.xls#Links!B8', 'Back')
526
+ cha_data.write('B9', 'external:../Europe/Ireland.xls#Links!B9', 'Back')
527
+
528
+ ireland.close
529
+ italy.close
530
+ china.close
531
+
532
+ # do assertion
533
+ compare_file("#{PERL_OUTDIR}/Ireland.xls", @file)
534
+ compare_file("#{PERL_OUTDIR}/Italy.xls", file2)
535
+ compare_file("#{PERL_OUTDIR}/China.xls", file3)
536
+ end
537
+
429
538
  def test_copyformat
430
539
  # Create workbook1
431
540
  workbook1 = WriteExcel.new(@file)
@@ -15,6 +15,15 @@ def setup
15
15
  @format = Writeexcel::Format.new(:color=>"green")
16
16
  end
17
17
 
18
+ def teardown
19
+ if @workbook.instance_variable_get(:@filehandle)
20
+ @workbook.instance_variable_get(:@filehandle).close(true)
21
+ end
22
+ if @ws.instance_variable_get(:@filehandle)
23
+ @ws.instance_variable_get(:@filehandle).close(true)
24
+ end
25
+ end
26
+
18
27
  def test_methods_exist
19
28
  assert_respond_to(@ws, :write)
20
29
  assert_respond_to(@ws, :write_blank)
@@ -99,6 +108,26 @@ def test_new
99
108
  assert_equal(@sheetname, @ws.name)
100
109
  end
101
110
 
111
+ def test_write_url_should_not_change_internal_url_string
112
+ internal_url = 'internal:Sheet2!A1'
113
+ @ws.write_url(0, 0, internal_url)
114
+
115
+ assert_equal('internal:Sheet2!A1', internal_url)
116
+ end
117
+
118
+ def test_write_url_should_not_change_external_url_string
119
+ external_url = 'external:c:\temp\foo.xls#Sheet2!A1'
120
+ @ws.write_url(1, 1, external_url)
121
+
122
+ assert_equal('external:c:\temp\foo.xls#Sheet2!A1', external_url)
123
+ end
124
+
125
+ def test_write_url_should_not_change_external_net_url_string
126
+ external_net_url = 'external://NETWORK/share/foo.xls'
127
+ @ws.write_url(1, 1, external_net_url)
128
+
129
+ assert_equal('external://NETWORK/share/foo.xls', external_net_url)
130
+ end
102
131
 
103
132
  def assert_equal_filesize(target, test, msg = "Bad file size")
104
133
  assert_equal(File.size(target),File.size(test),msg)
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+ require 'writeexcel'
4
+ require 'stringio'
5
+
6
+ class TestWriteFormula < Test::Unit::TestCase
7
+ def setup
8
+ @workbook = WriteExcel.new(StringIO.new)
9
+ @worksheet = @workbook.add_worksheet('')
10
+ end
11
+
12
+ def teardown
13
+ if @workbook.instance_variable_get(:@filehandle)
14
+ @workbook.instance_variable_get(:@filehandle).close(true)
15
+ end
16
+ if @worksheet.instance_variable_get(:@filehandle)
17
+ @worksheet.instance_variable_get(:@filehandle).close(true)
18
+ end
19
+ end
20
+
21
+ def test_write_formula_does_not_change_formula_string
22
+ formula = '=PI()'
23
+ @worksheet.write('A1', formula)
24
+
25
+ assert_equal('=PI()', formula)
26
+ end
27
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: writeexcel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.18
5
- prerelease:
4
+ version: 0.6.19
6
5
  platform: ruby
7
6
  authors:
8
7
  - Hideo NAKAMURA
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-09 00:00:00.000000000 Z
11
+ date: 2013-03-30 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Multiple worksheets can be added to a workbook and formatting can be
15
14
  applied to cells. Text, numbers, formulas, hyperlinks and images can be written
@@ -65,6 +64,7 @@ files:
65
64
  - examples/header.rb
66
65
  - examples/hide_sheet.rb
67
66
  - examples/hyperlink.rb
67
+ - examples/hyperlink2.rb
68
68
  - examples/images.rb
69
69
  - examples/indent.rb
70
70
  - examples/merge1.rb
@@ -156,6 +156,9 @@ files:
156
156
  - test/perl_output/Chart3.xls.data
157
157
  - test/perl_output/Chart4.xls.data
158
158
  - test/perl_output/Chart5.xls.data
159
+ - test/perl_output/China.xls
160
+ - test/perl_output/Ireland.xls
161
+ - test/perl_output/Italy.xls
159
162
  - test/perl_output/README
160
163
  - test/perl_output/a_simple.xls
161
164
  - test/perl_output/autofilter.xls
@@ -269,32 +272,32 @@ files:
269
272
  - test/test_storage_lite.rb
270
273
  - test/test_workbook.rb
271
274
  - test/test_worksheet.rb
275
+ - test/test_write_formula_does_not_change_formula_string.rb
272
276
  - utils/add_magic_comment.rb
273
277
  - writeexcel.gemspec
274
278
  - writeexcel.rdoc
275
279
  homepage: http://github.com/cxn03651/writeexcel#readme
276
280
  licenses: []
281
+ metadata: {}
277
282
  post_install_message:
278
283
  rdoc_options: []
279
284
  require_paths:
280
285
  - lib
281
286
  required_ruby_version: !ruby/object:Gem::Requirement
282
- none: false
283
287
  requirements:
284
- - - ! '>='
288
+ - - '>='
285
289
  - !ruby/object:Gem::Version
286
290
  version: '0'
287
291
  required_rubygems_version: !ruby/object:Gem::Requirement
288
- none: false
289
292
  requirements:
290
- - - ! '>='
293
+ - - '>='
291
294
  - !ruby/object:Gem::Version
292
295
  version: '0'
293
296
  requirements: []
294
297
  rubyforge_project:
295
- rubygems_version: 1.8.25
298
+ rubygems_version: 2.0.0
296
299
  signing_key:
297
- specification_version: 3
300
+ specification_version: 4
298
301
  summary: Write to a cross-platform Excel binary file.
299
302
  test_files:
300
303
  - test/excelfile/Chart1.xls
@@ -308,6 +311,9 @@ test_files:
308
311
  - test/perl_output/Chart3.xls.data
309
312
  - test/perl_output/Chart4.xls.data
310
313
  - test/perl_output/Chart5.xls.data
314
+ - test/perl_output/China.xls
315
+ - test/perl_output/Ireland.xls
316
+ - test/perl_output/Italy.xls
311
317
  - test/perl_output/README
312
318
  - test/perl_output/a_simple.xls
313
319
  - test/perl_output/autofilter.xls
@@ -421,3 +427,4 @@ test_files:
421
427
  - test/test_storage_lite.rb
422
428
  - test/test_workbook.rb
423
429
  - test/test_worksheet.rb
430
+ - test/test_write_formula_does_not_change_formula_string.rb