write_xlsx 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/README.rdoc +3 -0
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/examples/formats.rb +498 -0
  5. data/lib/write_xlsx/chart.rb +15 -15
  6. data/lib/write_xlsx/chartsheet.rb +1 -1
  7. data/lib/write_xlsx/format.rb +10 -3
  8. data/lib/write_xlsx/package/comments.rb +171 -27
  9. data/lib/write_xlsx/package/packager.rb +8 -17
  10. data/lib/write_xlsx/package/shared_strings.rb +36 -15
  11. data/lib/write_xlsx/package/styles.rb +2 -12
  12. data/lib/write_xlsx/package/vml.rb +14 -22
  13. data/lib/write_xlsx/utility.rb +53 -4
  14. data/lib/write_xlsx/workbook.rb +21 -37
  15. data/lib/write_xlsx/worksheet.rb +533 -765
  16. data/test/helper.rb +10 -3
  17. data/test/package/comments/test_write_text_t.rb +1 -1
  18. data/test/package/shared_strings/test_shared_strings01.rb +3 -3
  19. data/test/package/shared_strings/test_shared_strings02.rb +3 -3
  20. data/test/package/shared_strings/test_write_sst.rb +3 -2
  21. data/test/package/vml/test_write_anchor.rb +1 -1
  22. data/test/package/vml/test_write_auto_fill.rb +1 -1
  23. data/test/package/vml/test_write_column.rb +1 -1
  24. data/test/package/vml/test_write_div.rb +1 -1
  25. data/test/package/vml/test_write_fill.rb +1 -1
  26. data/test/package/vml/test_write_idmap.rb +1 -1
  27. data/test/package/vml/test_write_move_with_cells.rb +1 -1
  28. data/test/package/vml/test_write_path.rb +2 -2
  29. data/test/package/vml/test_write_row.rb +1 -1
  30. data/test/package/vml/test_write_shadow.rb +1 -1
  31. data/test/package/vml/test_write_shapelayout.rb +1 -1
  32. data/test/package/vml/test_write_shapetype.rb +1 -1
  33. data/test/package/vml/test_write_size_with_cells.rb +1 -1
  34. data/test/package/vml/test_write_stroke.rb +1 -1
  35. data/test/package/vml/test_write_textbox.rb +1 -1
  36. data/test/perl_output/formats.xlsx +0 -0
  37. data/test/perl_output/indent.xlsx +0 -0
  38. data/test/perl_output/merge4.xlsx +0 -0
  39. data/test/perl_output/merge5.xlsx +0 -0
  40. data/test/test_example_match.rb +482 -0
  41. data/test/worksheet/test_repeat_formula.rb +5 -5
  42. data/test/worksheet/test_write_cell.rb +10 -5
  43. data/test/worksheet/test_write_legacy_drawing.rb +1 -1
  44. data/write_xlsx.gemspec +5 -5
  45. metadata +15 -15
  46. data/test/package/comments/test_comments01.rb +0 -36
  47. data/test/package/vml/test_vml_01.rb +0 -42
@@ -15,13 +15,13 @@ module Writexlsx
15
15
 
16
16
  include Writexlsx::Utility
17
17
 
18
- attr_accessor :str_total, :str_unique
19
18
  attr_writer :firstsheet
20
19
  attr_reader :palette
21
20
  attr_reader :font_count, :num_format_count, :border_count, :fill_count, :custom_colors
22
21
  attr_reader :worksheets, :sheetnames, :charts, :drawings, :num_comment_files, :named_ranges
23
- attr_reader :str_array, :doc_properties
22
+ attr_reader :doc_properties
24
23
  attr_reader :image_types, :images
24
+ attr_reader :shared_strings
25
25
 
26
26
  #
27
27
  # A new Excel workbook is created using the new() constructor which accepts either a filename
@@ -101,10 +101,7 @@ module Writexlsx
101
101
  @images = []
102
102
 
103
103
  # Structures for the shared strings data.
104
- @str_total = 0
105
- @str_unique = 0
106
- @str_table = {}
107
- @str_array = []
104
+ @shared_strings = Package::SharedStrings.new
108
105
 
109
106
  add_format(default_formats.merge(:xf_index => 0))
110
107
  set_color_palette
@@ -209,7 +206,7 @@ module Writexlsx
209
206
  def assemble_xml_file #:nodoc:
210
207
  return unless @writer
211
208
 
212
- # Prepare format object for passing to Style.pm.
209
+ # Prepare format object for passing to Style.rb.
213
210
  prepare_format_properties
214
211
 
215
212
  write_xml_declaration
@@ -634,14 +631,15 @@ module Writexlsx
634
631
  # return the string index.
635
632
  #
636
633
  def shared_string_index(str) #:nodoc:
637
- # Add the string to the shared string table.
638
- unless @str_table[str]
639
- @str_table[str] = @str_unique
640
- @str_unique += 1
641
- end
634
+ @shared_strings.index(str)
635
+ end
636
+
637
+ def str_unique
638
+ @shared_strings.unique_count
639
+ end
642
640
 
643
- @str_total += 1
644
- @str_table[str]
641
+ def shared_strings_empty?
642
+ @shared_strings.empty?
645
643
  end
646
644
 
647
645
  def xf_formats # :nodoc:
@@ -755,7 +753,7 @@ module Writexlsx
755
753
  end
756
754
 
757
755
  # Check that sheet name is <= 31. Excel limit.
758
- raise "Sheetname #{name} must be <= 31 chars" if name.bytesize > 31
756
+ raise "Sheetname #{name} must be <= #{SHEETNAME_MAX} chars" if name.length > SHEETNAME_MAX
759
757
 
760
758
  # Check that sheetname doesn't contain any invalid characters
761
759
  if name =~ invalid_char
@@ -869,7 +867,7 @@ module Writexlsx
869
867
  str = @writer.start_tag('sheets')
870
868
  id_num = 1
871
869
  @worksheets.each do |sheet|
872
- str << write_sheet(sheet.name, id_num, sheet.hidden)
870
+ str << write_sheet(sheet.name, id_num, sheet.hidden?)
873
871
  id_num += 1
874
872
  end
875
873
  str << @writer.end_tag('sheets')
@@ -962,9 +960,6 @@ module Writexlsx
962
960
  # Set the active sheet.
963
961
  @worksheets.each { |sheet| sheet.activate if sheet.index == @activesheet }
964
962
 
965
- # Convert the SST strings data structure.
966
- prepare_sst_string_data
967
-
968
963
  # Prepare the worksheet cell comments.
969
964
  prepare_comments
970
965
 
@@ -992,20 +987,7 @@ module Writexlsx
992
987
  end
993
988
 
994
989
  #
995
- # Convert the SST string data from a hash to an array.
996
- #
997
- def prepare_sst_string_data #:nodoc:
998
- strings = []
999
-
1000
- @str_table.each_key { |key| strings[@str_table[key]] = key }
1001
-
1002
- # The SST data could be very large, free some memory (maybe).
1003
- @str_table = nil
1004
- @str_array = strings
1005
- end
1006
-
1007
- #
1008
- # Prepare all of the format properties prior to passing them to Styles.pm.
990
+ # Prepare all of the format properties prior to passing them to Styles.rb.
1009
991
  #
1010
992
  def prepare_format_properties #:nodoc:
1011
993
  # Separate format objects into XF and DXF formats.
@@ -1271,11 +1253,13 @@ module Writexlsx
1271
1253
  next unless sheet.has_comments?
1272
1254
 
1273
1255
  comment_id += 1
1274
- count = sheet.prepare_comments( vml_data_id, vml_shape_id, comment_id)
1256
+ sheet.set_external_comment_links(comment_id)
1257
+ sheet.set_vml_data_id(vml_data_id)
1258
+ sheet.vml_shape_id = vml_shape_id
1275
1259
 
1276
1260
  # Each VML file should start with a shape id incremented by 1024.
1277
- vml_data_id += 1 * ( ( 1024 + count ) / 1024.0 ).to_i
1278
- vml_shape_id += 1024 * ( ( 1024 + count ) / 1024.0 ).to_i
1261
+ vml_data_id += 1 * ( ( 1024 + sheet.comments_count ) / 1024.0 ).to_i
1262
+ vml_shape_id += 1024 * ( ( 1024 + sheet.comments_count ) / 1024.0 ).to_i
1279
1263
  end
1280
1264
 
1281
1265
  @num_comment_files = comment_id
@@ -1343,7 +1327,7 @@ module Writexlsx
1343
1327
  # Convert shared string indexes to strings.
1344
1328
  data.collect! do |token|
1345
1329
  if token.kind_of?(Hash)
1346
- token = @str_array[token[:sst_id]]
1330
+ token = @shared_strings.string(token[:sst_id])
1347
1331
 
1348
1332
  # Ignore rich strings for now. Deparse later if necessary.
1349
1333
  token = '' if token =~ %r!^<r>! && token =~ %r!</r>$!