write_xlsx 0.65.0 → 0.65.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +5 -0
  3. data/lib/write_xlsx/chart.rb +1 -1
  4. data/lib/write_xlsx/format.rb +93 -17
  5. data/lib/write_xlsx/package/comments.rb +1 -5
  6. data/lib/write_xlsx/package/styles.rb +2 -58
  7. data/lib/write_xlsx/version.rb +1 -1
  8. data/lib/write_xlsx/workbook.rb +1 -1
  9. data/lib/write_xlsx/worksheet.rb +20 -18
  10. data/lib/write_xlsx/worksheet/page_setup.rb +5 -0
  11. data/test/perl_output/protection.xlsx +0 -0
  12. data/test/regression/test_date_examples01.rb +48 -0
  13. data/test/regression/test_defined_name02.rb +32 -0
  14. data/test/regression/test_defined_name03.rb +32 -0
  15. data/test/regression/test_firstsheet01.rb +48 -0
  16. data/test/regression/test_hide01.rb +30 -0
  17. data/test/regression/test_image08.rb +26 -0
  18. data/test/regression/test_protect01.rb +28 -0
  19. data/test/regression/test_protect02.rb +30 -0
  20. data/test/regression/test_protect03.rb +30 -0
  21. data/test/regression/test_set_print_scale01.rb +36 -0
  22. data/test/regression/test_set_start_page01.rb +36 -0
  23. data/test/regression/test_simple03.rb +39 -0
  24. data/test/regression/test_simple04.rb +29 -0
  25. data/test/regression/test_simple05.rb +40 -0
  26. data/test/regression/test_tutorial01.rb +38 -0
  27. data/test/regression/test_tutorial02.rb +44 -0
  28. data/test/regression/test_tutorial03.rb +49 -0
  29. data/test/regression/xlsx_files/date_examples01.xlsx +0 -0
  30. data/test/regression/xlsx_files/defined_name02.xlsx +0 -0
  31. data/test/regression/xlsx_files/defined_name03.xlsx +0 -0
  32. data/test/regression/xlsx_files/firstsheet01.xlsx +0 -0
  33. data/test/regression/xlsx_files/hide01.xlsx +0 -0
  34. data/test/regression/xlsx_files/image08.xlsx +0 -0
  35. data/test/regression/xlsx_files/protect01.xlsx +0 -0
  36. data/test/regression/xlsx_files/protect02.xlsx +0 -0
  37. data/test/regression/xlsx_files/protect03.xlsx +0 -0
  38. data/test/regression/xlsx_files/set_print_scale01.xlsx +0 -0
  39. data/test/regression/xlsx_files/set_start_page01.xlsx +0 -0
  40. data/test/regression/xlsx_files/simple03.xlsx +0 -0
  41. data/test/regression/xlsx_files/simple04.xlsx +0 -0
  42. data/test/regression/xlsx_files/simple05.xlsx +0 -0
  43. data/test/regression/xlsx_files/tutorial01.xlsx +0 -0
  44. data/test/regression/xlsx_files/tutorial02.xlsx +0 -0
  45. data/test/regression/xlsx_files/tutorial03.xlsx +0 -0
  46. metadata +70 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30c458c96dc291036baa7b64c8099b044c10e18c
4
- data.tar.gz: 589e734bee933c9ab1f0904f59ce69f101251159
3
+ metadata.gz: 2625f80bf9b7f0ba2835f94cd5dd5699a86d1cba
4
+ data.tar.gz: a33f1666db5bd2bad62b7f0e97bb9422f03337fd
5
5
  SHA512:
6
- metadata.gz: 1865380215d25cfa2e16af387be17263669fb62bea666e75f10f1f2719450120eed303aaea7f457ac60514af0d323c8552409bfacdae573ae19b4349cb42c5f7
7
- data.tar.gz: 645cd41d3b387e77448b97494ccd87f2f39a29a49b21202f699b99a776845ef0d159044283556ae57ef0d2b0ff5fcc6a35ab4390a6da205ef8c557d1b46db368
6
+ metadata.gz: f8fb864b91fffd56d02dab919dea687a9a66dd22ed2c2b2a5240e72e830ae835781aa59a873ceb76391d1b8a4624fee72c4be9a5cbf7c4eb95773fd756b11e98
7
+ data.tar.gz: 2913180a8541b9c17293e2d3bc1e4bae00d8b3964726b6c2a30cb7c51b7b52963b8f64d11f7ce4318a70438d740b7932b30944813c368a89947c3ef3c66a38e9
@@ -75,6 +75,11 @@ the first worksheet in an Excel XML spreadsheet called ruby.xlsx:
75
75
  workbook.close
76
76
 
77
77
  == Recent change
78
+ 2013-03-23 v0.65.1
79
+ Bug fix for non-integer image scaling.
80
+ Bug fix in Worksheet#set_first_sheet
81
+ Bug fix in Worksheet#start_page=()
82
+
78
83
  2013-03-23 v0.65.0
79
84
  Added options to format series Gap/Overlap for Bar/Column charts.
80
85
 
@@ -83,7 +83,7 @@ def attributes
83
83
  # Creates a Bar style (transposed histogram) chart. See Writexlsx::Chart::Bar.
84
84
  #
85
85
  # ===column
86
- # Creates a column style (histogram) chart. See Writexlsx::Chart::Column.
86
+ # Creates a Column style (histogram) chart. See Writexlsx::Chart::Column.
87
87
  #
88
88
  # ===line
89
89
  # Creates a Line style chart. See Writexlsx::Chart::Line.
@@ -378,7 +378,7 @@ def inspect
378
378
  # Returns a unique hash key for the Format object.
379
379
  #
380
380
  def get_format_key
381
- [get_font_key, get_border_key, get_fill_key, @num_format, get_alignment_key].join(':')
381
+ [get_font_key, get_border_key, get_fill_key, get_alignment_key, @num_format, @locked, @hidden].join(':')
382
382
  end
383
383
 
384
384
  #
@@ -735,20 +735,37 @@ def [](attr)
735
735
  self.instance_variable_get("@#{attr}")
736
736
  end
737
737
 
738
- def write_font(writer, worksheet) #:nodoc:
739
- writer.tag_elements('rPr') do
740
- writer.empty_tag('b') if bold?
741
- writer.empty_tag('i') if italic?
742
- writer.empty_tag('strike') if strikeout?
743
- writer.empty_tag('outline') if outline?
744
- writer.empty_tag('shadow') if shadow?
738
+ def write_font(writer, worksheet, dxf_format = nil) #:nodoc:
739
+ writer.tag_elements('font') do
740
+ # The condense and extend elements are mainly used in dxf formats.
741
+ write_condense(writer) if ptrue?(@font_condense)
742
+ write_extend(writer) if ptrue?(@font_extend)
745
743
 
746
- # Handle the underline variants.
747
- write_underline(writer, underline) if underline?
744
+ write_font_shapes(writer)
748
745
 
749
- write_vert_align(writer, 'superscript') if font_script == 1
750
- write_vert_align(writer, 'subscript') if font_script == 2
746
+ writer.empty_tag('sz', ['val', size]) unless dxf_format
751
747
 
748
+ if ptrue?(theme)
749
+ write_color(writer, 'theme', theme)
750
+ elsif ptrue?(@color_indexed)
751
+ write_color(writer, 'indexed', @color_indexed)
752
+ elsif ptrue?(@color)
753
+ color = worksheet.get_palette_color(@color)
754
+ write_color(writer, 'rgb', color)
755
+ elsif !ptrue?(dxf_format)
756
+ write_color(writer, 'theme', 1)
757
+ end
758
+
759
+ unless ptrue?(dxf_format)
760
+ writer.empty_tag('name', ['val', @font])
761
+ write_font_family_scheme(writer)
762
+ end
763
+ end
764
+ end
765
+
766
+ def write_font_rpr(writer, worksheet) #:nodoc:
767
+ writer.tag_elements('rPr') do
768
+ write_font_shapes(writer)
752
769
  writer.empty_tag('sz', ['val', size])
753
770
 
754
771
  if ptrue?(theme)
@@ -760,12 +777,57 @@ def write_font(writer, worksheet) #:nodoc:
760
777
  write_color(writer, 'theme', 1)
761
778
  end
762
779
 
763
- writer.empty_tag('rFont', ['val', font])
764
- writer.empty_tag('family', ['val', font_family])
780
+ writer.empty_tag('rFont', ['val', @font])
781
+ write_font_family_scheme(writer)
782
+ end
783
+ end
784
+
785
+ private
765
786
 
766
- if font == 'Calibri' && hyperlink == 0
767
- writer.empty_tag('scheme', ['val', font_scheme])
768
- end
787
+ def write_font_shapes(writer)
788
+ writer.empty_tag('b') if bold?
789
+ writer.empty_tag('i') if italic?
790
+ writer.empty_tag('strike') if strikeout?
791
+ writer.empty_tag('outline') if outline?
792
+ writer.empty_tag('shadow') if shadow?
793
+
794
+ # Handle the underline variants.
795
+ write_underline(writer, underline) if underline?
796
+
797
+ write_vert_align(writer, 'superscript') if font_script == 1
798
+ write_vert_align(writer, 'subscript') if font_script == 2
799
+ end
800
+
801
+ def write_font_family_scheme(writer)
802
+ writer.empty_tag('family', ['val', @font_family])
803
+
804
+ if @font == 'Calibri' && !ptrue?(@hyperlink)
805
+ writer.empty_tag('scheme', ['val', @font_scheme])
806
+ end
807
+ end
808
+
809
+ #
810
+ # Write the underline font element.
811
+ #
812
+ def write_underline(writer, underline)
813
+ writer.empty_tag('u', write_underline_attributes(underline))
814
+ end
815
+
816
+ #
817
+ # Write the underline font element.
818
+ #
819
+ def write_underline_attributes(underline)
820
+ val = 'val'
821
+ # Handle the underline variants.
822
+ case underline
823
+ when 2
824
+ [val, 'double']
825
+ when 33
826
+ [val, 'singleAccounting']
827
+ when 34
828
+ [val, 'doubleAccounting']
829
+ else
830
+ []
769
831
  end
770
832
  end
771
833
 
@@ -775,5 +837,19 @@ def write_font(writer, worksheet) #:nodoc:
775
837
  def write_vert_align(writer, val) #:nodoc:
776
838
  writer.empty_tag('vertAlign', ['val', val])
777
839
  end
840
+
841
+ #
842
+ # Write the <condense> element.
843
+ #
844
+ def write_condense(writer)
845
+ writer.empty_tag('condense', ['val', 0])
846
+ end
847
+
848
+ #
849
+ # Write the <extend> element.
850
+ #
851
+ def write_extend(writer)
852
+ writer.empty_tag('extend', ['val', 0])
853
+ end
778
854
  end
779
855
  end
@@ -419,11 +419,7 @@ def write_sz
419
419
  # Write the <color> element.
420
420
  #
421
421
  def write_color
422
- indexed = 81
423
-
424
- attributes = ['indexed', indexed]
425
-
426
- @writer.empty_tag('color', attributes)
422
+ @writer.empty_tag('color', ['indexed', 81])
427
423
  end
428
424
 
429
425
  #
@@ -172,67 +172,11 @@ def write_num_fmt(num_fmt_id, format_code)
172
172
  def write_fonts
173
173
  write_format_elements('fonts', @font_count) do
174
174
  @xf_formats.each do |format|
175
- write_font(format) if format.has_font?
175
+ format.write_font(@writer, self) if format.has_font?
176
176
  end
177
177
  end
178
178
  end
179
179
 
180
- #
181
- # Write the <font> element.
182
- #
183
- def write_font(format, dxf_format = nil)
184
- @writer.tag_elements('font') do
185
- # The condense and extend elements are mainly used in dxf formats.
186
- write_condense unless format.font_condense == 0
187
- write_extend unless format.font_extend == 0
188
-
189
- @writer.empty_tag('b') if format.bold?
190
- @writer.empty_tag('i') if format.italic?
191
- @writer.empty_tag('strike') if format.strikeout?
192
- @writer.empty_tag('outline') if format.outline?
193
- @writer.empty_tag('shadow') if format.shadow?
194
-
195
- # Handle the underline variants.
196
- write_underline( format.underline ) if format.underline?
197
-
198
- write_vert_align('superscript') if format.font_script == 1
199
- write_vert_align('subscript') if format.font_script == 2
200
-
201
- @writer.empty_tag('sz', ['val', format.size]) if !dxf_format
202
-
203
- theme = format.theme
204
- if theme != 0
205
- write_color('theme', theme)
206
- elsif format.color_indexed != 0
207
- write_color('indexed', format.color_indexed)
208
- elsif format.color != 0
209
- color = get_palette_color(format.color)
210
- write_color('rgb', color)
211
- elsif !dxf_format
212
- write_color('theme', 1)
213
- end
214
-
215
- if !dxf_format
216
- @writer.empty_tag('name', ['val', format.font])
217
- @writer.empty_tag('family', ['val', format.font_family])
218
-
219
- if format.font == 'Calibri' && format.hyperlink == 0
220
- @writer.empty_tag('scheme', ['val', format.font_scheme])
221
- end
222
- end
223
- end
224
- end
225
-
226
- #
227
- # _write_underline()
228
- #
229
- # Write the underline font element.
230
- #
231
- def write_underline(underline)
232
- attributes = underline_attributes(underline)
233
- @writer.empty_tag('u', attributes)
234
- end
235
-
236
180
  #
237
181
  # Write the <color> element.
238
182
  #
@@ -580,7 +524,7 @@ def write_dxfs
580
524
  # Write the font elements for format objects that have them.
581
525
  @dxf_formats.each do |format|
582
526
  @writer.tag_elements('dxf') do
583
- write_font(format, 1) if format.has_dxf_font?
527
+ format.write_font(@writer, self, 1) if format.has_dxf_font?
584
528
 
585
529
  if format.num_format_index != 0
586
530
  write_num_fmt(format.num_format_index, format.num_format)
@@ -1,5 +1,5 @@
1
1
  require 'write_xlsx/workbook'
2
2
 
3
3
  class WriteXLSX < Writexlsx::Workbook
4
- VERSION = "0.65.0"
4
+ VERSION = "0.65.1"
5
5
  end
@@ -1130,7 +1130,7 @@ def write_workbook_view #:nodoc:
1130
1130
  attributes << 'tabRatio' << @tab_ratio
1131
1131
  end
1132
1132
  if @firstsheet > 0
1133
- attributes << 'firstSheet' << @firstsheet
1133
+ attributes << 'firstSheet' << @firstsheet + 1
1134
1134
  end
1135
1135
  if @activesheet > 0
1136
1136
  attributes << 'activeTab' << @activesheet
@@ -78,10 +78,10 @@ module Writexlsx
78
78
  # * set_landscape
79
79
  # * set_portrait
80
80
  # * set_page_view
81
- # * set_paper
81
+ # * {paper=}[#method-i-paper-3D]
82
82
  # * center_horizontally
83
83
  # * center_vertically
84
- # * set_margins
84
+ # * {margins=}[#method-i-margin-3D]
85
85
  # * set_header
86
86
  # * set_footer
87
87
  # * repeat_rows
@@ -91,8 +91,8 @@ module Writexlsx
91
91
  # * print_area
92
92
  # * print_across
93
93
  # * fit_to_pages
94
- # * set_start_page
95
- # * set_print_scale
94
+ # * {start_page=}[#method-i-start_page-3D]
95
+ # * {print_scale=}[#method-i-print_scale-3D]
96
96
  # * set_h_pagebreaks
97
97
  # * set_v_pagebreaks
98
98
  #
@@ -515,7 +515,7 @@ def hidden? # :nodoc:
515
515
  #
516
516
  def set_first_sheet
517
517
  @hidden = false
518
- @workbook.firstsheet = self
518
+ @workbook.firstsheet = @index
519
519
  end
520
520
 
521
521
  #
@@ -1589,20 +1589,22 @@ def print_across(across = true)
1589
1589
  end
1590
1590
 
1591
1591
  #
1592
- # Not implememt yet.
1593
- #--
1594
- # The set_start_page() method is used to set the number of the
1592
+ # The start_page=() method is used to set the number of the
1595
1593
  # starting page when the worksheet is printed out.
1596
1594
  # The default value is 1.
1597
1595
  #
1598
1596
  # worksheet.set_start_page(2)
1599
- #++
1600
1597
  #
1601
- def set_start_page(page_start)
1602
- @page_start = page_start
1598
+ def start_page=(page_start)
1599
+ @page_setup.page_start = page_start
1603
1600
  @custom_start = 1
1604
1601
  end
1605
1602
 
1603
+ def set_start_page(page_start)
1604
+ put_deprecate_message("#{self}.set_start_page")
1605
+ self::start_page = page_start
1606
+ end
1607
+
1606
1608
  #
1607
1609
  # :call-seq:
1608
1610
  # write(row, column [ , token [ , format ] ])
@@ -5822,7 +5824,7 @@ def xml_str_of_rich_string(fragments)
5822
5824
  if token.respond_to?(:xf_index)
5823
5825
  # Write the font run.
5824
5826
  writer.start_tag('r')
5825
- token.write_font(writer, self)
5827
+ token.write_font_rpr(writer, self)
5826
5828
  else
5827
5829
  # Write the string fragment part, with whitespace handling.
5828
5830
  attributes = []
@@ -6055,12 +6057,12 @@ def position_object_emus(col_start, row_start, x1, y1, width, height, is_drawing
6055
6057
  position_object_pixels(col_start, row_start, x1, y1, width, height, is_drawing)
6056
6058
 
6057
6059
  # Convert the pixel values to EMUs. See above.
6058
- x1 *= 9_525
6059
- y1 *= 9_525
6060
- x2 *= 9_525
6061
- y2 *= 9_525
6062
- x_abs *= 9_525
6063
- y_abs *= 9_525
6060
+ x1 = (0.5 + 9_525 * x1).to_i
6061
+ y1 = (0.5 + 9_525 * y1).to_i
6062
+ x2 = (0.5 + 9_525 * x2).to_i
6063
+ y2 = (0.5 + 9_525 * y2).to_i
6064
+ x_abs = (0.5 + 9_525 * x_abs).to_i
6065
+ y_abs = (0.5 + 9_525 * y_abs).to_i
6064
6066
 
6065
6067
  [col_start, row_start, x1, y1, col_end, row_end, x2, y2, x_abs, y_abs]
6066
6068
  end
@@ -3,6 +3,8 @@
3
3
  module Writexlsx
4
4
  class Worksheet
5
5
  class PageSetup # :nodoc:
6
+ include Writexlsx::Utility
7
+
6
8
  attr_accessor :margin_left, :margin_right, :margin_top, :margin_bottom # :nodoc:
7
9
  attr_accessor :margin_header, :margin_footer # :nodoc:
8
10
  attr_accessor :repeat_rows, :repeat_cols, :print_area # :nodoc:
@@ -11,6 +13,7 @@ class PageSetup # :nodoc:
11
13
  attr_writer :across # :nodoc:
12
14
  attr_accessor :orientation, :print_options_changed # :nodoc:
13
15
  attr_accessor :header, :footer, :header_footer_changed
16
+ attr_writer :page_start
14
17
 
15
18
  def initialize # :nodoc:
16
19
  @margin_left = 0.7
@@ -80,6 +83,7 @@ def hide_gridlines(option)
80
83
  # fitToHeight="2"
81
84
  # pageOrder="overThenDown"
82
85
  # orientation="portrait"
86
+ # useFirstPageNumber="1"
83
87
  # blackAndWhite="1"
84
88
  # draft="1"
85
89
  # horizontalDpi="200"
@@ -102,6 +106,7 @@ def write_page_setup(writer) #:nodoc:
102
106
  else
103
107
  attributes << 'landscape'
104
108
  end
109
+ attributes << 'useFirstPageNumber' << @page_start if ptrue?(@page_start)
105
110
 
106
111
  writer.empty_tag('pageSetup', attributes)
107
112
  end
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ class TestDateExamples01 < Test::Unit::TestCase
5
+ def setup
6
+ setup_dir_var
7
+ end
8
+
9
+ def teardown
10
+ File.delete(@xlsx) if File.exist?(@xlsx)
11
+ end
12
+
13
+ def test_date_examples01
14
+ @xlsx = 'date_examples01.xlsx'
15
+ workbook = WriteXLSX.new(@xlsx)
16
+ worksheet = workbook.add_worksheet
17
+
18
+ worksheet.set_column('A:A', 30)
19
+
20
+ number = 41333.5
21
+
22
+ worksheet.write('A1', number) # 413333.5
23
+
24
+ format2 = workbook.add_format(:num_format => 'dd/mm/yy')
25
+ worksheet.write('A2', number, format2) # 28/02/13
26
+
27
+ format3 = workbook.add_format(:num_format => 'mm/dd/yy')
28
+ worksheet.write('A3', number, format3) # 02/28/13
29
+
30
+ format4 = workbook.add_format(:num_format => 'd\\-m\\-yyyy')
31
+ worksheet.write('A4', number, format4) # 28-2-2013
32
+
33
+ format5 = workbook.add_format(:num_format => 'dd/mm/yy\\ hh:mm')
34
+ worksheet.write('A5', number, format5) # 28/02/13 12:00
35
+
36
+ format6 = workbook.add_format(:num_format => 'd\\ mmm\\ yyyy')
37
+ worksheet.write('A6', number, format6) # 28 Feb 2013
38
+
39
+ format7 = workbook.add_format(:num_format => 'mmm\\ d\\ yyyy\\ hh:mm\\ AM/PM')
40
+ worksheet.write('A7', number, format7) # Feb 28 2013 12:00 PM
41
+
42
+ workbook.close
43
+ compare_xlsx_for_regression(File.join(@regression_output, @xlsx), @xlsx,
44
+ ['xl/calcChain.xml', '\[Content_Types\].xml', 'xl/_rels/workbook.xml.rels'],
45
+ {}
46
+ )
47
+ end
48
+ end