writeexcel 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -77,6 +77,9 @@ when use urf8 string data.
77
77
 
78
78
  == Recent Changes
79
79
 
80
+ v0.6.8
81
+ * Bug fix. Worksheet#protect doesn't work well.
82
+
80
83
  v0.6.7
81
84
  * Bug fix. Worksheet#set_first_sheet doesn't work well.
82
85
  * Bug fix. Worksheet#hide_zero doesn't work well.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.7
1
+ 0.6.8
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'writeexcel'
3
+
4
+ workbook = WriteExcel.new('password_protection.xls')
5
+ worksheet = workbook.add_worksheet
6
+
7
+ # Create some format objects
8
+ locked = workbook.add_format(:locked => 1)
9
+ unlocked = workbook.add_format(:locked => 0)
10
+ hidden = workbook.add_format(:hidden => 1)
11
+
12
+ # Format the columns
13
+ worksheet.set_column('A:A', 42)
14
+ worksheet.set_selection('B3:B3')
15
+
16
+ # Protect the worksheet
17
+ worksheet.protect('password')
18
+
19
+ # Examples of cell locking and hiding
20
+ worksheet.write('A1', 'Cell B1 is locked. It cannot be edited.')
21
+ worksheet.write('B1', '=1+2', locked)
22
+
23
+ worksheet.write('A2', 'Cell B2 is unlocked. It can be edited.')
24
+ worksheet.write('B2', '=1+2', unlocked)
25
+
26
+ worksheet.write('A3', "Cell B3 is hidden. The formula isn't visible.")
27
+ worksheet.write('B3', '=1+2', hidden)
28
+
29
+ worksheet.write('A5', 'Use Menu->Tools->Protection->Unprotect Sheet')
30
+ worksheet.write('A6', 'to remove the worksheet protection. ')
31
+ worksheet.write('A7', 'The password is "password". ')
32
+
33
+ workbook.close
@@ -968,7 +968,7 @@ name="write_string"
968
968
 
969
969
  <pre>
970
970
  # Format as a string. Doesn&#39;t change to a number when edited
971
- format1 = workbook.add_format(num_format =&#62; &#39;@&#39;)
971
+ format1 = workbook.add_format(:num_format =&#62; &#39;@&#39;)
972
972
  worksheet.write_string(&#39;A2&#39;, &#39;01209&#39;, format1)
973
973
  </pre>
974
974
 
@@ -1084,7 +1084,7 @@ name="write_col"
1084
1084
  <p>The <code>write_col</code> method can be used to write a 1D or 2D array of data in one go. This is useful for converting the results of a database query into an Excel worksheet. You must pass a reference to the array of data rather than the array itself. The <code>write</code> method is then called for each element of the data. For example:</p>
1085
1085
 
1086
1086
  <pre>
1087
- array = [39;awk&#39;, &#39;gawk&#39;, &#39;mawk&#39;]
1087
+ array = [&#39;awk&#39;, &#39;gawk&#39;, &#39;mawk&#39;]
1088
1088
 
1089
1089
  worksheet.write_col(0, 0, array)
1090
1090
 
@@ -1173,7 +1173,7 @@ name="write_date_time"
1173
1173
  >&#34;CELL FORMATTING&#34;</a>. Here is a typical example:</p>
1174
1174
 
1175
1175
  <pre>
1176
- date_format = workbook.add_format(num_format =&#62; &#39;mm/dd/yy&#39;)
1176
+ date_format = workbook.add_format(:num_format =&#62; &#39;mm/dd/yy&#39;)
1177
1177
  worksheet.write_date_time(&#39;A1&#39;, &#39;2004-05-13T23:20&#39;, date_format)
1178
1178
  </pre>
1179
1179
 
@@ -1457,7 +1457,7 @@ name="write_comment"
1457
1457
  <p>This option is used to indicate that the comment string is encoded as <code>UTF-16BE</code>.</p>
1458
1458
 
1459
1459
  <pre>
1460
- comment = pack &#39;n&#39;, 0x263a; # UTF-16BE Smiley symbol
1460
+ comment = [0x263a].pack('n') # UTF-16BE Smiley symbol
1461
1461
 
1462
1462
  worksheet.write_comment(&#39;C3&#39;, comment, :encoding =&#62; 1)
1463
1463
  </pre>
@@ -1675,7 +1675,7 @@ name="insert_chart"
1675
1675
  <p>This method can be used to insert a Chart object into a worksheet. The Chart must be created by the <code>add_chart</code> Workbook method and it must have the <code>embedded</code> option set.</p>
1676
1676
 
1677
1677
  <pre>
1678
- chart = workbook.add_chart( type =&#62; &#39;Chart::Line&#39;, :embedded =&#62; true )
1678
+ chart = workbook.add_chart( :type =&#62; &#39;Chart::Line&#39;, :embedded =&#62; true )
1679
1679
 
1680
1680
  # Configure the chart.
1681
1681
  ...
@@ -1831,8 +1831,8 @@ name="protect"
1831
1831
 
1832
1832
  <pre>
1833
1833
  # Set some format properties
1834
- unlocked = workbook.add_format(locked =&#62; 0)
1835
- hidden = workbook.add_format(hidden =&#62; 1)
1834
+ unlocked = workbook.add_format(:locked =&#62; 0)
1835
+ hidden = workbook.add_format(:hidden =&#62; 1)
1836
1836
 
1837
1837
  # Enable worksheet protection
1838
1838
  worksheet.protect
@@ -2109,9 +2109,9 @@ name="merge_range"
2109
2109
 
2110
2110
  <pre>
2111
2111
  format = workbook.add_format(
2112
- border =&#62; 6,
2113
- valign =&#62; &#39;vcenter&#39;,
2114
- align =&#62; &#39;center&#39;,
2112
+ :border =&#62; 6,
2113
+ :valign =&#62; &#39;vcenter&#39;,
2114
+ :align =&#62; &#39;center&#39;,
2115
2115
  )
2116
2116
 
2117
2117
  worksheet.merge_range(&#39;B3:D4&#39;, &#39;Vertical and horizontal&#39;, format)
@@ -2592,7 +2592,7 @@ name="set_landscape"
2592
2592
  <p>This method is used to set the orientation of a worksheet&#39;s printed page to landscape:</p>
2593
2593
 
2594
2594
  <pre>
2595
- worksheet.set_landscape; # Landscape mode
2595
+ worksheet.set_landscape # Landscape mode
2596
2596
  </pre>
2597
2597
 
2598
2598
  <h2><a class='u' href='#___top' title='click to go to top of document'
@@ -2602,7 +2602,7 @@ name="set_portrait"
2602
2602
  <p>This method is used to set the orientation of a worksheet&#39;s printed page to portrait. The default worksheet orientation is portrait, so you won&#39;t generally need to call this method.</p>
2603
2603
 
2604
2604
  <pre>
2605
- worksheet.set_portrait; # Portrait mode
2605
+ worksheet.set_portrait # Portrait mode
2606
2606
  </pre>
2607
2607
 
2608
2608
  <h2><a class='u' href='#___top' title='click to go to top of document'
@@ -2707,10 +2707,10 @@ name="set_margins"
2707
2707
  set_margins # Set all margins to the same value
2708
2708
  set_margins_LR # Set left and right margins to the same value
2709
2709
  set_margins_TB # Set top and bottom margins to the same value
2710
- set_margin_left; # Set left margin
2711
- set_margin_right; # Set right margin
2712
- set_margin_top; # Set top margin
2713
- set_margin_bottom; # Set bottom margin
2710
+ set_margin_left # Set left margin
2711
+ set_margin_right # Set right margin
2712
+ set_margin_top # Set top margin
2713
+ set_margin_bottom # Set bottom margin
2714
2714
  </pre>
2715
2715
 
2716
2716
  <p>All of these methods take a distance in inches as a parameter. Note: 1 inch = 25.4mm. ;-) The default left and right margin is 0.75 inch. The default top and bottom margin is 1.00 inch.</p>
@@ -3226,7 +3226,7 @@ name="Working_with_formats"
3226
3226
 
3227
3227
  <pre>
3228
3228
  format1 = workbook.add_format
3229
- format1.set_bold; # Turns bold on
3229
+ format1.set_bold # Turns bold on
3230
3230
  format1.set_bold(1) # Also turns bold on
3231
3231
  format1.set_bold(0) # Turns bold off
3232
3232
  </pre>
@@ -3275,7 +3275,7 @@ name="FORMAT_METHODS"
3275
3275
  set_right_color
3276
3276
  </pre>
3277
3277
 
3278
- <p>The above methods can also be applied directly as properties. For example <code>format.set_bold</code> is equivalent to <code>workbook.add_format(bold =&#62; 1)</code>.</p>
3278
+ <p>The above methods can also be applied directly as properties. For example <code>format.set_bold</code> is equivalent to <code>workbook.add_format(:bold =&#62; 1)</code>.</p>
3279
3279
 
3280
3280
  <h2><a class='u' href='#___top' title='click to go to top of document'
3281
3281
  name="set_format_properties"
@@ -3285,13 +3285,13 @@ name="set_format_properties"
3285
3285
 
3286
3286
  <pre>
3287
3287
  format = workbook.add_format
3288
- format.set_format_properties(bold =&#62; 1, color =&#62; &#39;red&#39;)
3288
+ format.set_format_properties(:bold =&#62; 1, :color =&#62; &#39;red&#39;)
3289
3289
  </pre>
3290
3290
 
3291
3291
  <p>However, this method is here mainly for legacy reasons. It is preferable to set the properties in the format constructor:</p>
3292
3292
 
3293
3293
  <pre>
3294
- format = workbook.add_format(bold =&#62; 1, color =&#62; &#39;red&#39;)
3294
+ format = workbook.add_format(:bold =&#62; 1, :color =&#62; &#39;red&#39;)
3295
3295
  </pre>
3296
3296
 
3297
3297
  <h2><a class='u' href='#___top' title='click to go to top of document'
@@ -3383,7 +3383,7 @@ name="set_bold"
3383
3383
  <p>Set the bold property of the font:</p>
3384
3384
 
3385
3385
  <pre>
3386
- format.set_bold; # Turn bold on
3386
+ format.set_bold # Turn bold on
3387
3387
  </pre>
3388
3388
 
3389
3389
  <p>[1] Actually, values in the range 100..1000 are also valid. 400 is normal, 700 is bold and 1000 is very bold indeed. It is probably best to set the value to 1 and use normal bold.</p>
@@ -3401,7 +3401,7 @@ name="set_italic"
3401
3401
  <p>Set the italic property of the font:</p>
3402
3402
 
3403
3403
  <pre>
3404
- format.set_italic; # Turn italic on
3404
+ format.set_italic # Turn italic on
3405
3405
  </pre>
3406
3406
 
3407
3407
  <h2><a class='u' href='#___top' title='click to go to top of document'
@@ -3421,7 +3421,7 @@ name="set_underline"
3421
3421
  <p>Set the underline property of the font.</p>
3422
3422
 
3423
3423
  <pre>
3424
- format.set_underline; # Single underline
3424
+ format.set_underline # Single underline
3425
3425
  </pre>
3426
3426
 
3427
3427
  <h2><a class='u' href='#___top' title='click to go to top of document'
@@ -3846,7 +3846,7 @@ name="set_bg_color"
3846
3846
  <pre>
3847
3847
  format = workbook.add_format
3848
3848
 
3849
- format.set_pattern; # This is optional when using a solid fill
3849
+ format.set_pattern # This is optional when using a solid fill
3850
3850
 
3851
3851
  format.set_bg_color(&#39;green&#39;)
3852
3852
  worksheet.write(&#39;A1&#39;, &#39;Ray&#39;, format)
@@ -4142,11 +4142,11 @@ name="Chart_names_and_Unicode"
4142
4142
  <p>You can write Unicode strings as UTF-16BE by adding a <code>name_encoding</code> property:</p>
4143
4143
 
4144
4144
  <pre>
4145
- utf16be_name = pack &#39;n&#39;, 0x263A;
4145
+ utf16be_name = [0x263a].pack('n')
4146
4146
 
4147
4147
  chart.set_title(
4148
- name =&#62; utf16be_name,
4149
- name_encoding =&#62; 1,
4148
+ :name =&#62; utf16be_name,
4149
+ :name_encoding =&#62; 1,
4150
4150
  )
4151
4151
  </pre>
4152
4152
 
@@ -4195,22 +4195,22 @@ name="An_Excel_date_time_is_a_number_plus_a_format"
4195
4195
 
4196
4196
  worksheet.write(&#39;A1&#39;, number) # 39506.5
4197
4197
 
4198
- format2 = workbook.add_format(num_format =&#62; &#39;dd/mm/yy&#39;)
4198
+ format2 = workbook.add_format(:num_format =&#62; &#39;dd/mm/yy&#39;)
4199
4199
  worksheet.write(&#39;A2&#39;, number , format2) # 28/02/08
4200
4200
 
4201
- format3 = workbook.add_format(num_format =&#62; &#39;mm/dd/yy&#39;)
4201
+ format3 = workbook.add_format(:num_format =&#62; &#39;mm/dd/yy&#39;)
4202
4202
  worksheet.write(&#39;A3&#39;, number , format3) # 02/28/08
4203
4203
 
4204
- format4 = workbook.add_format(num_format =&#62; &#39;d-m-yyyy&#39;)
4204
+ format4 = workbook.add_format(:num_format =&#62; &#39;d-m-yyyy&#39;)
4205
4205
  worksheet.write(&#39;A4&#39;, number , format4) # 28-2-2008
4206
4206
 
4207
- format5 = workbook.add_format(num_format =&#62; &#39;dd/mm/yy hh:mm&#39;)
4207
+ format5 = workbook.add_format(:num_format =&#62; &#39;dd/mm/yy hh:mm&#39;)
4208
4208
  worksheet.write(&#39;A5&#39;, number , format5) # 28/02/08 12:00
4209
4209
 
4210
- format6 = workbook.add_format(num_format =&#62; &#39;d mmm yyyy&#39;)
4210
+ format6 = workbook.add_format(:num_format =&#62; &#39;d mmm yyyy&#39;)
4211
4211
  worksheet.write(&#39;A6&#39;, number , format6) # 28 Feb 2008
4212
4212
 
4213
- format7 = workbook.add_format(num_format =&#62; &#39;mmm d yyyy hh:mm AM/PM&#39;)
4213
+ format7 = workbook.add_format(:num_format =&#62; &#39;mmm d yyyy hh:mm AM/PM&#39;)
4214
4214
  worksheet.write(&#39;A7&#39;, number , format7) # Feb 28 2008 12:00 PM
4215
4215
  </pre>
4216
4216
 
@@ -4254,7 +4254,7 @@ name="WriteExcel_doesnt_automatically_convert_date_time_strings"
4254
4254
  worksheet = workbook.add_worksheet
4255
4255
 
4256
4256
  # Set the default format for dates.
4257
- date_format = workbook.add_format(num_format =&#62; &#39;mmm d yyyy&#39;)
4257
+ date_format = workbook.add_format(:num_format =&#62; &#39;mmm d yyyy&#39;)
4258
4258
 
4259
4259
  # Increase column width to improve visibility of data.
4260
4260
  worksheet.set_column(&#39;A:C&#39;, 20)
@@ -4419,7 +4419,7 @@ name="DATA_VALIDATION_IN_EXCEL"
4419
4419
 
4420
4420
  <h2><a class='u' href='#___top' title='click to go to top of document'
4421
4421
  name="data_validation"
4422
- >data_validation(row, col, { parameter =&#62; &#39;value&#39;, ... })</a></h2>
4422
+ >data_validation(row, col, { :parameter =&#62; &#39;value&#39;, ... })</a></h2>
4423
4423
 
4424
4424
  <p>The <code>data_validation</code> method is used to construct an Excel data validation.</p>
4425
4425
 
@@ -5448,12 +5448,12 @@ name="Example_7"
5448
5448
  bold = workbook.add_format( :bold => 1 )
5449
5449
 
5450
5450
  # Add the worksheet data that the charts will refer to.
5451
- headings = [ 'Number', 'Sample 1', 'Sample 2' ];
5451
+ headings = [ 'Number', 'Sample 1', 'Sample 2' ]
5452
5452
  data = [
5453
5453
  [ 2, 3, 4, 5, 6, 7 ],
5454
5454
  [ 1, 4, 5, 2, 1, 5 ],
5455
5455
  [ 3, 6, 7, 5, 4, 3 ],
5456
- ];
5456
+ ]
5457
5457
 
5458
5458
  worksheet.write( 'A1', headings, bold )
5459
5459
  worksheet.write( 'A2', data )
@@ -5508,12 +5508,12 @@ name="Example_8"
5508
5508
  bold = workbook.add_format( :bold => 1 )
5509
5509
 
5510
5510
  # Add the worksheet data that the charts will refer to.
5511
- headings = [ 'Number', 'Sample 1', 'Sample 2' ];
5511
+ headings = [ 'Number', 'Sample 1', 'Sample 2' ]
5512
5512
  data = [
5513
5513
  [ 2, 3, 4, 5, 6, 7 ],
5514
5514
  [ 1, 4, 5, 2, 1, 5 ],
5515
5515
  [ 3, 6, 7, 5, 4, 3 ],
5516
- ];
5516
+ ]
5517
5517
 
5518
5518
  worksheet.write( 'A1', headings, bold )
5519
5519
  worksheet.write( 'A2', data )
@@ -5568,12 +5568,12 @@ name="Example_9"
5568
5568
  bold = workbook.add_format( :bold => 1 )
5569
5569
 
5570
5570
  # Add the worksheet data that the charts will refer to.
5571
- headings = [ 'Number', 'Sample 1', 'Sample 2' ];
5571
+ headings = [ 'Number', 'Sample 1', 'Sample 2' ]
5572
5572
  data = [
5573
5573
  [ 2, 3, 4, 5, 6, 7 ],
5574
5574
  [ 1, 4, 5, 2, 1, 5 ],
5575
5575
  [ 3, 6, 7, 5, 4, 3 ],
5576
- ];
5576
+ ]
5577
5577
 
5578
5578
  worksheet.write( 'A1', headings, bold )
5579
5579
  worksheet.write( 'A2', data )
@@ -5008,12 +5008,12 @@ def sort_pagebreaks(breaks) #:nodoc:
5008
5008
  #
5009
5009
  # Based on the algorithm provided by Daniel Rentz of OpenOffice.
5010
5010
  #
5011
- def encode_password(password) #:nodoc:
5011
+ def encode_password(password)
5012
5012
  i = 0
5013
5013
  chars = password.split(//)
5014
5014
  count = chars.size
5015
5015
 
5016
- chars.each do |char|
5016
+ chars.collect! do |char|
5017
5017
  i += 1
5018
5018
  char = char[0] << i
5019
5019
  low_15 = char & 0x7fff
@@ -1203,6 +1203,42 @@ def test_protection
1203
1203
  compare_file("#{PERL_OUTDIR}/protection.xls", @file)
1204
1204
  end
1205
1205
 
1206
+ def test_password_protection
1207
+ workbook = WriteExcel.new(@file)
1208
+ worksheet = workbook.add_worksheet
1209
+
1210
+ # Create some format objects
1211
+ locked = workbook.add_format(:locked => 1)
1212
+ unlocked = workbook.add_format(:locked => 0)
1213
+ hidden = workbook.add_format(:hidden => 1)
1214
+
1215
+ # Format the columns
1216
+ worksheet.set_column('A:A', 42)
1217
+ worksheet.set_selection('B3:B3')
1218
+
1219
+ # Protect the worksheet
1220
+ worksheet.protect('password')
1221
+
1222
+ # Examples of cell locking and hiding
1223
+ worksheet.write('A1', 'Cell B1 is locked. It cannot be edited.')
1224
+ worksheet.write('B1', '=1+2', locked)
1225
+
1226
+ worksheet.write('A2', 'Cell B2 is unlocked. It can be edited.')
1227
+ worksheet.write('B2', '=1+2', unlocked)
1228
+
1229
+ worksheet.write('A3', "Cell B3 is hidden. The formula isn't visible.")
1230
+ worksheet.write('B3', '=1+2', hidden)
1231
+
1232
+ worksheet.write('A5', 'Use Menu->Tools->Protection->Unprotect Sheet')
1233
+ worksheet.write('A6', 'to remove the worksheet protection. ')
1234
+ worksheet.write('A7', 'The password is "password". ')
1235
+
1236
+ workbook.close
1237
+
1238
+ # do assertion
1239
+ compare_file("#{PERL_OUTDIR}/password_protection.xls", @file)
1240
+ end
1241
+
1206
1242
  def test_date_time
1207
1243
  # Create a new workbook and add a worksheet
1208
1244
  workbook = WriteExcel.new(@file)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{writeexcel}
8
- s.version = "0.6.7"
8
+ s.version = "0.6.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Hideo NAKAMURA"]
12
- s.date = %q{2011-07-03}
12
+ s.date = %q{2011-07-30}
13
13
  s.description = %q{Multiple worksheets can be added to a workbook and formatting can be applied to cells. Text, numbers, formulas, hyperlinks and images can be written to the cells.}
14
14
  s.email = %q{cxn03651@msj.biglobe.ne.jp}
15
15
  s.extra_rdoc_files = [
@@ -68,6 +68,7 @@ Gem::Specification.new do |s|
68
68
  "examples/outline.rb",
69
69
  "examples/outline_collapsed.rb",
70
70
  "examples/panes.rb",
71
+ "examples/password_protection.rb",
71
72
  "examples/properties.rb",
72
73
  "examples/properties_jp.rb",
73
74
  "examples/protection.rb",
@@ -181,6 +182,7 @@ Gem::Specification.new do |s|
181
182
  "test/perl_output/outline.xls",
182
183
  "test/perl_output/outline_collapsed.xls",
183
184
  "test/perl_output/panes.xls",
185
+ "test/perl_output/password_protection.xls",
184
186
  "test/perl_output/protection.xls",
185
187
  "test/perl_output/regions.xls",
186
188
  "test/perl_output/right_to_left.xls",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: writeexcel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-03 00:00:00.000000000 +09:00
12
+ date: 2011-07-30 00:00:00.000000000 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: Multiple worksheets can be added to a workbook and formatting can be
@@ -73,6 +73,7 @@ files:
73
73
  - examples/outline.rb
74
74
  - examples/outline_collapsed.rb
75
75
  - examples/panes.rb
76
+ - examples/password_protection.rb
76
77
  - examples/properties.rb
77
78
  - examples/properties_jp.rb
78
79
  - examples/protection.rb
@@ -186,6 +187,7 @@ files:
186
187
  - test/perl_output/outline.xls
187
188
  - test/perl_output/outline_collapsed.xls
188
189
  - test/perl_output/panes.xls
190
+ - test/perl_output/password_protection.xls
189
191
  - test/perl_output/protection.xls
190
192
  - test/perl_output/regions.xls
191
193
  - test/perl_output/right_to_left.xls