xlsxrb 0.1.18 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +163 -0
  3. data/README.md +34 -11
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +410 -80
  5. data/lib/xlsxrb/chart_builder.rb +251 -386
  6. data/lib/xlsxrb/dsl_helpers.rb +120 -67
  7. data/lib/xlsxrb/elements/cell.rb +37 -157
  8. data/lib/xlsxrb/elements/column.rb +11 -19
  9. data/lib/xlsxrb/elements/coordinate_access.rb +15 -86
  10. data/lib/xlsxrb/elements/image.rb +5 -72
  11. data/lib/xlsxrb/elements/metadata.rb +463 -817
  12. data/lib/xlsxrb/elements/row.rb +27 -145
  13. data/lib/xlsxrb/elements/styles.rb +30 -88
  14. data/lib/xlsxrb/elements/types.rb +6 -99
  15. data/lib/xlsxrb/elements/workbook.rb +19 -126
  16. data/lib/xlsxrb/elements/worksheet.rb +43 -314
  17. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +4 -1
  18. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -7
  19. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +32 -17
  20. data/lib/xlsxrb/ooxml/reader.rb +49 -51
  21. data/lib/xlsxrb/ooxml/styles_parser.rb +26 -2
  22. data/lib/xlsxrb/ooxml/utils.rb +2 -2
  23. data/lib/xlsxrb/ooxml/workbook_parser.rb +0 -1
  24. data/lib/xlsxrb/ooxml/workbook_writer.rb +172 -93
  25. data/lib/xlsxrb/ooxml/worksheet_parser.rb +61 -29
  26. data/lib/xlsxrb/ooxml/worksheet_writer.rb +65 -47
  27. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +28 -11
  28. data/lib/xlsxrb/ooxml/writer/features_xml.rb +53 -14
  29. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +1 -1
  30. data/lib/xlsxrb/ooxml/writer.rb +105 -41
  31. data/lib/xlsxrb/ooxml/xml_parser.rb +78 -5
  32. data/lib/xlsxrb/ooxml/zip_reader.rb +65 -15
  33. data/lib/xlsxrb/ooxml/zip_writer.rb +119 -30
  34. data/lib/xlsxrb/stream_row.rb +12 -116
  35. data/lib/xlsxrb/stream_sheet.rb +14 -261
  36. data/lib/xlsxrb/stream_writer.rb +623 -1476
  37. data/lib/xlsxrb/style_builder.rb +376 -593
  38. data/lib/xlsxrb/version.rb +1 -1
  39. data/lib/xlsxrb/workbook_builder.rb +192 -226
  40. data/lib/xlsxrb/worksheet_builder.rb +456 -1324
  41. data/lib/xlsxrb.rb +266 -1083
  42. data/sig/generated/xlsxrb/chart_builder.rbs +202 -205
  43. data/sig/generated/xlsxrb/dsl_helpers.rbs +64 -16
  44. data/sig/generated/xlsxrb/elements/cell.rbs +12 -76
  45. data/sig/generated/xlsxrb/elements/column.rbs +0 -7
  46. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +5 -41
  47. data/sig/generated/xlsxrb/elements/image.rbs +3 -29
  48. data/sig/generated/xlsxrb/elements/metadata.rbs +138 -151
  49. data/sig/generated/xlsxrb/elements/row.rbs +10 -53
  50. data/sig/generated/xlsxrb/elements/styles.rbs +1 -39
  51. data/sig/generated/xlsxrb/elements/workbook.rbs +14 -78
  52. data/sig/generated/xlsxrb/elements/worksheet.rbs +5 -121
  53. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +0 -4
  54. data/sig/generated/xlsxrb/ooxml/reader.rbs +0 -3
  55. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +1 -1
  56. data/sig/generated/xlsxrb/ooxml/utils.rbs +3 -3
  57. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +12 -0
  58. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +16 -0
  59. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +5 -3
  60. data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +7 -0
  61. data/sig/generated/xlsxrb/ooxml/writer.rbs +20 -14
  62. data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +70 -0
  63. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +22 -7
  64. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +26 -1
  65. data/sig/generated/xlsxrb/stream_row.rbs +7 -42
  66. data/sig/generated/xlsxrb/stream_sheet.rbs +1 -158
  67. data/sig/generated/xlsxrb/stream_writer.rbs +457 -976
  68. data/sig/generated/xlsxrb/style_builder.rbs +206 -242
  69. data/sig/generated/xlsxrb/workbook_builder.rbs +84 -132
  70. data/sig/generated/xlsxrb/worksheet_builder.rbs +309 -685
  71. data/sig/generated/xlsxrb.rbs +43 -190
  72. data/sig/rexml.rbs +8 -0
  73. metadata +3 -5
  74. data/lib/xlsxrb/utils.rb +0 -251
  75. data/sig/generated/xlsxrb/utils.rbs +0 -200
@@ -148,9 +148,9 @@ module Xlsxrb
148
148
  hl_tag = xml.byteslice(hl_start, hl_tag_end - hl_start)
149
149
  ref = tag_attr(hl_tag, ' ref="')
150
150
  rid = tag_attr(hl_tag, ' r:id="') || tag_attr(hl_tag, ' id="') || hl_tag[/(?:[a-zA-Z0-9_]+:)?id="([^"]+)"/, 1]
151
- display = tag_attr(hl_tag, ' display="')
152
- tooltip = tag_attr(hl_tag, ' tooltip="')
153
- location = tag_attr(hl_tag, ' location="')
151
+ display = decoded_attr(hl_tag, ' display="')
152
+ tooltip = decoded_attr(hl_tag, ' tooltip="')
153
+ location = decoded_attr(hl_tag, ' location="')
154
154
 
155
155
  if ref
156
156
  entry = { ref: ref }
@@ -315,6 +315,14 @@ module Xlsxrb
315
315
 
316
316
  private_class_method :tag_attr
317
317
 
318
+ # Like tag_attr, with entity references such as & and " decoded.
319
+ def self.decoded_attr(tag, prefix)
320
+ value = tag_attr(tag, prefix)
321
+ value&.include?("&") ? REXML::Text.unnormalize(value) : value
322
+ end
323
+
324
+ private_class_method :decoded_attr
325
+
318
326
  def self.fast_scan_cells_events(xml, from, to, shared_strings, row_source, prefix = "", shared_masters = {}, &block)
319
327
  pos = from
320
328
  c_start_pattern = "<#{prefix}c"
@@ -516,6 +524,23 @@ module Xlsxrb
516
524
  STRICT_NUMERIC_RE = /\A[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\z/
517
525
  private_constant :STRICT_NUMERIC_RE
518
526
 
527
+ # Returns str without leading and trailing whitespace, allocating a new String only
528
+ # when there is whitespace to remove (cell values rarely have any).
529
+ #: (String str) -> String
530
+ def self.strip_ws(str)
531
+ first = str.getbyte(0)
532
+ return str if first.nil? || (first > 32 && str.getbyte(-1) > 32)
533
+
534
+ str.strip
535
+ end
536
+
537
+ # Retags a String captured from the binary scan buffer as UTF-8 in place, without
538
+ # copying. Only for Strings the caller has just created (e.g. regex captures).
539
+ #: (String? str) -> String?
540
+ def self.utf8!(str)
541
+ str&.force_encoding(Encoding::UTF_8)
542
+ end
543
+
519
544
  # Resolves a cell value from its type attribute and parsed XML content (<v> or <is>).
520
545
  # Consolidates parsing across fast-scan direct, row values, events, and listener paths.
521
546
  #: (String? type, String? raw_value, String? is_xml, Array[String | Elements::RichText | untyped] shared_strings) -> untyped
@@ -525,7 +550,7 @@ module Xlsxrb
525
550
  raw_value ? (shared_strings[raw_value.to_i] || "") : nil
526
551
  when "b"
527
552
  if raw_value
528
- v = raw_value.strip
553
+ v = strip_ws(raw_value)
529
554
  v == "1" || v.casecmp?("true")
530
555
  end
531
556
  when "inlineStr", "str", "e"
@@ -540,7 +565,7 @@ module Xlsxrb
540
565
  raw_value ? numeric_cell_value(raw_value) : nil
541
566
  else
542
567
  if raw_value
543
- text = raw_value.strip
568
+ text = strip_ws(raw_value)
544
569
  return nil if text.empty?
545
570
 
546
571
  if text.match?(STRICT_NUMERIC_RE)
@@ -566,7 +591,7 @@ module Xlsxrb
566
591
  # instead of silently becoming 0.
567
592
  #: (String raw) -> (Integer | Float)?
568
593
  def self.numeric_cell_value(raw)
569
- text = raw.strip
594
+ text = strip_ws(raw)
570
595
  return nil if text.empty?
571
596
 
572
597
  raise(ParseError, "invalid numeric cell value: #{text.inspect}") unless text.match?(STRICT_NUMERIC_RE)
@@ -775,7 +800,7 @@ module Xlsxrb
775
800
  return if in_sheet_data == :closed
776
801
  return if chunk.nil? || chunk.empty?
777
802
 
778
- buffer << chunk.b
803
+ buffer << (chunk.encoding == Encoding::BINARY ? chunk : chunk.b)
779
804
 
780
805
  unless in_sheet_data
781
806
  sd_term = buffer.index("sheetData")
@@ -979,7 +1004,10 @@ module Xlsxrb
979
1004
  [COL_LETTERS[idx], idx]
980
1005
  end.freeze
981
1006
 
982
- CELL_FAST_RE = %r{<(?:[a-zA-Z0-9_]+:)?c\b([^>]*(?<!/))>\s*(?:<(?:[a-zA-Z0-9_]+:)?f\b[^>]*?(?:/>|>([^<]*)</(?:[a-zA-Z0-9_]+:)?f>)\s*)?(?:<(?:[a-zA-Z0-9_]+:)?v>([^<]*)</(?:[a-zA-Z0-9_]+:)?v>\s*)?(?:<(?:[a-zA-Z0-9_]+:)?is>(.*?)</(?:[a-zA-Z0-9_]+:)?is>\s*)?.*?</(?:[a-zA-Z0-9_]+:)?c>|<(?:[a-zA-Z0-9_]+:)?c\b([^>]*)/?>}m
1007
+ # Captures r, s, and t directly when they appear in the order Excel and xlsxrb write them
1008
+ # (groups 1 to 3). Any other attribute set or order falls back to capturing the raw
1009
+ # attribute string (group 4, or group 8 for a self-closing cell) for ATTR_* lookups.
1010
+ CELL_FAST_RE = %r{<(?:[a-zA-Z0-9_]+:)?c(?:\s+r="([A-Za-z0-9]+)"(?:\s+s="(\d+)")?(?:\s+t="([a-zA-Z]+)")?\s*|\b([^>]*(?<!/)))>\s*(?:<(?:[a-zA-Z0-9_]+:)?f\b[^>]*?(?:/>|>([^<]*)</(?:[a-zA-Z0-9_]+:)?f>)\s*)?(?:<(?:[a-zA-Z0-9_]+:)?v>([^<]*)</(?:[a-zA-Z0-9_]+:)?v>\s*)?(?:<(?:[a-zA-Z0-9_]+:)?is>(.*?)</(?:[a-zA-Z0-9_]+:)?is>\s*)?.*?</(?:[a-zA-Z0-9_]+:)?c>|<(?:[a-zA-Z0-9_]+:)?c\b([^>]*)/?>}m
983
1011
  CELL_GENERIC_RE = %r{<(?:[a-zA-Z0-9_]+:)?c\b([^>]*?)(?:>\s*(?:<(?:[a-zA-Z0-9_]+:)?f\b[^>]*?(?:/>|>([^<]*)</(?:[a-zA-Z0-9_]+:)?f>)\s*)?(?:<(?:[a-zA-Z0-9_]+:)?v>([^<]*)</(?:[a-zA-Z0-9_]+:)?v>\s*)?(?:<(?:[a-zA-Z0-9_]+:)?is>(.*?)</(?:[a-zA-Z0-9_]+:)?is>\s*)?.*?</(?:[a-zA-Z0-9_]+:)?c>|/>)}m
984
1012
  ATTR_R = /\br="([A-Za-z0-9]+)"/
985
1013
  ATTR_T = /\bt="([a-zA-Z]+)"/
@@ -992,24 +1020,26 @@ module Xlsxrb
992
1020
  end
993
1021
 
994
1022
  # rubocop:disable Style/OptionalBooleanParameter
995
- def self.fast_scan_cells_direct(xml, from, to, shared_strings, row_source, _prefix = "", styles = nil, date1904 = false, &block)
1023
+ def self.fast_scan_cells_direct(xml, from, to, shared_strings, row_source, _prefix = "", styles = nil, date1904 = false, &)
996
1024
  # rubocop:enable Style/OptionalBooleanParameter
997
1025
  chunk = xml.byteslice(from, to - from)
998
1026
  row_idx = row_source.is_a?(Hash) ? row_source[:row] : row_source
999
1027
  col_idx = 0
1000
1028
  matched_any = false
1001
1029
 
1002
- chunk.scan(CELL_FAST_RE) do |attrs_str, f, v, is, self_attrs|
1030
+ chunk.scan(CELL_FAST_RE) do |r, s, t, attrs_str, f, v, is, self_attrs|
1003
1031
  matched_any = true
1004
- raw_attrs = attrs_str || self_attrs || ""
1005
- r = raw_attrs[ATTR_R, 1]
1006
- s = raw_attrs.include?('s="') ? raw_attrs[ATTR_S, 1] : nil
1007
- t = raw_attrs.include?('t="') ? raw_attrs[ATTR_T, 1] : nil
1032
+ unless r
1033
+ raw_attrs = attrs_str || self_attrs || ""
1034
+ r = raw_attrs[ATTR_R, 1]
1035
+ s = raw_attrs.include?('s="') ? raw_attrs[ATTR_S, 1] : nil
1036
+ t = raw_attrs.include?('t="') ? raw_attrs[ATTR_T, 1] : nil
1037
+ end
1008
1038
  style_idx = s&.to_i
1009
1039
  ref = r
1010
1040
  c_idx = if ref
1011
1041
  expected_letter = COL_LETTERS[col_idx]
1012
- if expected_letter && ref.start_with?(expected_letter) && ref.getbyte(expected_letter.bytesize)&.between?(48, 57)
1042
+ if expected_letter && ref.start_with?(expected_letter) && (digit = ref.getbyte(expected_letter.bytesize)) && digit >= 48 && digit <= 57
1013
1043
  col_idx
1014
1044
  else
1015
1045
  c_len = 0
@@ -1021,8 +1051,8 @@ module Xlsxrb
1021
1051
  col_idx
1022
1052
  end
1023
1053
  col_idx = c_idx + 1
1024
- v = v.strip if v
1025
- f = f.strip if f
1054
+ v = utf8!(strip_ws(v)) if v
1055
+ f = utf8!(strip_ws(f)) if f
1026
1056
 
1027
1057
  val = resolve_cell_value(t, v, is, shared_strings)
1028
1058
 
@@ -1036,7 +1066,7 @@ module Xlsxrb
1036
1066
  formula_expr = nil if formula_expr && formula_expr.empty?
1037
1067
  fmt_code = NumberFormatter.format_code_for(style_idx, styles) if styles && style_idx
1038
1068
  cell = Elements::Cell.fast_create(row_idx, c_idx, val, style_idx, formula_expr, raw_val, fmt_code, date1904)
1039
- block.call(cell)
1069
+ yield cell
1040
1070
  end
1041
1071
 
1042
1072
  return if matched_any || (!chunk.include?("<c") && !chunk.include?(":c"))
@@ -1049,7 +1079,7 @@ module Xlsxrb
1049
1079
 
1050
1080
  c_idx = if r
1051
1081
  expected_letter = COL_LETTERS[col_idx]
1052
- if expected_letter && r.start_with?(expected_letter) && r.getbyte(expected_letter.bytesize)&.between?(48, 57)
1082
+ if expected_letter && r.start_with?(expected_letter) && (digit = r.getbyte(expected_letter.bytesize)) && digit >= 48 && digit <= 57
1053
1083
  col_idx
1054
1084
  else
1055
1085
  c_len = 0
@@ -1061,8 +1091,8 @@ module Xlsxrb
1061
1091
  col_idx
1062
1092
  end
1063
1093
  col_idx = c_idx + 1
1064
- v = v.strip if v
1065
- f = f.strip if f
1094
+ v = utf8!(strip_ws(v)) if v
1095
+ f = utf8!(strip_ws(f)) if f
1066
1096
 
1067
1097
  val = resolve_cell_value(t, v, is, shared_strings)
1068
1098
 
@@ -1077,7 +1107,7 @@ module Xlsxrb
1077
1107
  formula_expr = nil if formula_expr && formula_expr.empty?
1078
1108
  fmt_code = NumberFormatter.format_code_for(style_idx, styles) if styles && style_idx
1079
1109
  cell = Elements::Cell.fast_create(row_idx, c_idx, val, style_idx, formula_expr, raw_val, fmt_code, date1904)
1080
- block.call(cell)
1110
+ yield cell
1081
1111
  end
1082
1112
  end
1083
1113
 
@@ -1092,16 +1122,18 @@ module Xlsxrb
1092
1122
  matched_any = false
1093
1123
  row_values = []
1094
1124
 
1095
- chunk.scan(CELL_FAST_RE) do |attrs_str, _f, v, is, self_attrs|
1125
+ chunk.scan(CELL_FAST_RE) do |r, s_val, t, attrs_str, _f, v, is, self_attrs|
1096
1126
  matched_any = true
1097
- raw_attrs = attrs_str || self_attrs || ""
1098
- r = raw_attrs[ATTR_R, 1]
1099
- s_val = raw_attrs.include?('s="') ? raw_attrs[ATTR_S, 1] : nil
1100
- t = raw_attrs.include?('t="') ? raw_attrs[ATTR_T, 1] : nil
1127
+ unless r
1128
+ raw_attrs = attrs_str || self_attrs || ""
1129
+ r = raw_attrs[ATTR_R, 1]
1130
+ s_val = raw_attrs.include?('s="') ? raw_attrs[ATTR_S, 1] : nil
1131
+ t = raw_attrs.include?('t="') ? raw_attrs[ATTR_T, 1] : nil
1132
+ end
1101
1133
  ref = r
1102
1134
  c_idx = if ref
1103
1135
  expected_letter = COL_LETTERS[col_idx]
1104
- if expected_letter && ref.start_with?(expected_letter) && ref.getbyte(expected_letter.bytesize)&.between?(48, 57)
1136
+ if expected_letter && ref.start_with?(expected_letter) && (digit = ref.getbyte(expected_letter.bytesize)) && digit >= 48 && digit <= 57
1105
1137
  col_idx
1106
1138
  else
1107
1139
  c_len = 0
@@ -1144,7 +1176,7 @@ module Xlsxrb
1144
1176
 
1145
1177
  c_idx = if r
1146
1178
  expected_letter = COL_LETTERS[col_idx]
1147
- if expected_letter && r.start_with?(expected_letter) && r.getbyte(expected_letter.bytesize)&.between?(48, 57)
1179
+ if expected_letter && r.start_with?(expected_letter) && (digit = r.getbyte(expected_letter.bytesize)) && digit >= 48 && digit <= 57
1148
1180
  col_idx
1149
1181
  else
1150
1182
  c_len = 0
@@ -26,12 +26,9 @@ module Xlsxrb
26
26
 
27
27
  INTEGER_STRINGS = (0..65_535).map { |n| -n.to_s }.freeze
28
28
 
29
- attr_accessor :escape_formulas
30
-
31
- def initialize(io, date1904: false, escape_formulas: false)
29
+ def initialize(io, date1904: false)
32
30
  @io = io
33
31
  @date1904 = date1904 ? true : false
34
- @escape_formulas = escape_formulas ? true : false
35
32
  @builder = XmlBuilder.new(@io)
36
33
  @row_buffer = String.new(capacity: 65_536)
37
34
  @started = false
@@ -167,6 +164,10 @@ module Xlsxrb
167
164
  when nil
168
165
  buf << '<c r="' << col_ref << '"/>'
169
166
  next
167
+ when DateTime
168
+ serial = Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)
169
+ buf << '<c r="' << col_ref << '"><v>' << serial.to_s << "</v></c>"
170
+ next
170
171
  when Date
171
172
  serial = Xlsxrb::Ooxml::Utils.date_to_serial(value, date1904: @date1904)
172
173
  buf << '<c r="' << col_ref << '"><v>' << serial.to_s << "</v></c>"
@@ -192,7 +193,7 @@ module Xlsxrb
192
193
  if formula
193
194
  if formula.is_a?(Xlsxrb::Elements::Formula)
194
195
  formula_expr = formula.expression
195
- formula_ca = formula.calculate_always
196
+ formula_ca = formula.calculate_always?
196
197
  formula_type = formula.type
197
198
  formula_ref = formula.ref
198
199
  formula_si = formula.shared_index
@@ -254,10 +255,10 @@ module Xlsxrb
254
255
  when false
255
256
  xml_val = "0"
256
257
  type = "b"
258
+ when Time, DateTime
259
+ xml_val = Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)
257
260
  when Date
258
261
  xml_val = Xlsxrb::Ooxml::Utils.date_to_serial(value, date1904: @date1904)
259
- when Time
260
- xml_val = Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)
261
262
  when BigDecimal
262
263
  xml_val = value.to_s("F")
263
264
  when Xlsxrb::Elements::CellError
@@ -363,6 +364,13 @@ module Xlsxrb
363
364
  buf << '<c r="' << col_ref << row_num_str << '" t="b"><v>1</v></c>'
364
365
  when false
365
366
  buf << '<c r="' << col_ref << row_num_str << '" t="b"><v>0</v></c>'
367
+ when Time, DateTime
368
+ time_style_id = style_map ? style_map["__xlsxrb_time"] : nil
369
+ buf << if time_style_id
370
+ "<c r=\"#{col_ref}#{row_num_str}\" s=\"#{time_style_id}\"><v>#{Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)}</v></c>"
371
+ else
372
+ "<c r=\"#{col_ref}#{row_num_str}\"><v>#{Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)}</v></c>"
373
+ end
366
374
  when Date
367
375
  date_style_id = style_map ? style_map["__xlsxrb_date"] : nil
368
376
  buf << if date_style_id
@@ -370,13 +378,6 @@ module Xlsxrb
370
378
  else
371
379
  "<c r=\"#{col_ref}#{row_num_str}\"><v>#{Xlsxrb::Ooxml::Utils.date_to_serial(value, date1904: @date1904)}</v></c>"
372
380
  end
373
- when Time
374
- time_style_id = style_map ? style_map["__xlsxrb_time"] : nil
375
- buf << if time_style_id
376
- "<c r=\"#{col_ref}#{row_num_str}\" s=\"#{time_style_id}\"><v>#{Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)}</v></c>"
377
- else
378
- "<c r=\"#{col_ref}#{row_num_str}\"><v>#{Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)}</v></c>"
379
- end
380
381
  when Xlsxrb::Elements::Formula
381
382
  raise ArgumentError, "Non-finite Float #{value.cached_value} is not supported in XLSX" if value.cached_value.is_a?(Float) && !value.cached_value.finite?
382
383
 
@@ -394,7 +395,7 @@ module Xlsxrb
394
395
  f_attrs << %( ref="#{value.ref}") if value.ref
395
396
  end
396
397
  end
397
- f_attrs << ' ca="1"' if value.calculate_always
398
+ f_attrs << ' ca="1"' if value.calculate_always?
398
399
  c_type = ""
399
400
  case value.cached_value
400
401
  when true
@@ -586,12 +587,12 @@ module Xlsxrb
586
587
  buf << '<c r="' << col_ref << row_num_str << '" t="b"><v>0</v></c>'
587
588
  col_index += 1
588
589
  next
589
- when Date
590
- buf << '<c r="' << col_ref << row_num_str << '"><v>' << Xlsxrb::Ooxml::Utils.date_to_serial(value, date1904: @date1904).to_s << "</v></c>"
590
+ when Time, DateTime
591
+ buf << '<c r="' << col_ref << row_num_str << '"><v>' << Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904).to_s << "</v></c>"
591
592
  col_index += 1
592
593
  next
593
- when Time
594
- buf << '<c r="' << col_ref << row_num_str << '"><v>' << Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904).to_s << "</v></c>"
594
+ when Date
595
+ buf << '<c r="' << col_ref << row_num_str << '"><v>' << Xlsxrb::Ooxml::Utils.date_to_serial(value, date1904: @date1904).to_s << "</v></c>"
595
596
  col_index += 1
596
597
  next
597
598
  end
@@ -609,7 +610,7 @@ module Xlsxrb
609
610
  case value
610
611
  when Xlsxrb::Elements::Formula
611
612
  formula_expr = value.expression
612
- formula_ca = value.calculate_always
613
+ formula_ca = value.calculate_always?
613
614
  formula_type = value.type
614
615
  formula_ref = value.ref
615
616
  formula_si = value.shared_index
@@ -673,10 +674,10 @@ module Xlsxrb
673
674
  when false
674
675
  xml_val = "0"
675
676
  type = "b"
677
+ when Time, DateTime
678
+ xml_val = Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)
676
679
  when Date
677
680
  xml_val = Xlsxrb::Ooxml::Utils.date_to_serial(value, date1904: @date1904)
678
- when Time
679
- xml_val = Xlsxrb::Ooxml::Utils.datetime_to_serial(value, date1904: @date1904)
680
681
  when BigDecimal
681
682
  xml_val = value.to_s("F")
682
683
  when Xlsxrb::Elements::CellError
@@ -819,7 +820,7 @@ module Xlsxrb
819
820
  apply_styles = props.fetch(:apply_styles, outline_props[:apply_styles])
820
821
  summary_below = props.fetch(:summary_below, props.fetch(:outline_below, outline_props[:summary_below]))
821
822
  summary_right = props.fetch(:summary_right, props.fetch(:outline_right, outline_props[:summary_right]))
822
- show_outline_symbols = props.fetch(:show_outline_symbols, props.fetch(:show_symbols, outline_props[:show_outline_symbols]))
823
+ show_outline_symbols = props.fetch(:show_outline_symbols, outline_props[:show_outline_symbols])
823
824
  has_outline = !apply_styles.nil? || !summary_below.nil? || !summary_right.nil? || !show_outline_symbols.nil?
824
825
 
825
826
  has_children = tc_attrs || !props[:fit_to_page].nil? || has_outline
@@ -836,8 +837,11 @@ module Xlsxrb
836
837
  @builder.empty_tag("outlinePr", outline_attrs) unless outline_attrs.empty?
837
838
  end
838
839
 
839
- unless props[:fit_to_page].nil?
840
- @builder.empty_tag("pageSetUpPr", { fitToPage: props[:fit_to_page] ? "1" : "0" })
840
+ psp = props[:page_setup_properties] || props[:page_setup_pr]
841
+ fit_to_page = props[:fit_to_page]
842
+ fit_to_page = psp[:fit_to_page] if fit_to_page.nil? && psp.is_a?(Hash)
843
+ unless fit_to_page.nil?
844
+ @builder.empty_tag("pageSetUpPr", { fitToPage: fit_to_page ? "1" : "0" })
841
845
  end
842
846
 
843
847
  @builder.close_tag("sheetPr")
@@ -857,7 +861,7 @@ module Xlsxrb
857
861
  attrs[:tint] = tc[:tint].to_s if tc[:tint]
858
862
  attrs.empty? ? nil : attrs
859
863
  elsif tc.is_a?(String) || tc.is_a?(Symbol)
860
- { rgb: tc.to_s.delete_prefix("#") }
864
+ { rgb: tab_color_rgb(tc) }
861
865
  elsif props[:tab_color_theme]
862
866
  attrs = { theme: props[:tab_color_theme].to_s }
863
867
  attrs[:tint] = props[:tab_color_tint].to_s if props[:tab_color_tint]
@@ -869,6 +873,18 @@ module Xlsxrb
869
873
  end
870
874
  end
871
875
 
876
+ # Writes a hex tab color as given (without "#") and resolves a color name such as :red to
877
+ # aRGB hex, as for cell styles.
878
+ def tab_color_rgb(color)
879
+ hex = color.to_s.delete_prefix("#")
880
+ return hex if hex.match?(/\A(\h{6}|\h{8})\z/)
881
+
882
+ rgb = StyleBuilder.resolve_color(color.is_a?(Symbol) ? color : color.to_s.to_sym).to_s
883
+ raise ArgumentError, "unknown tab color: #{color.inspect}" unless rgb.match?(/\A\h{8}\z/)
884
+
885
+ rgb
886
+ end
887
+
872
888
  def write_sheet_views(freeze_pane: nil, split_pane: nil, selection: nil, sheet_view: nil)
873
889
  @builder.open_tag("sheetViews")
874
890
  sv_attrs = { workbookViewId: "0" }
@@ -895,16 +911,18 @@ module Xlsxrb
895
911
  @builder.open_tag("sheetView", sv_attrs)
896
912
  if freeze_pane
897
913
  pane_attrs = {}
898
- pane_attrs[:xSplit] = freeze_pane[:col].to_s if freeze_pane[:col]&.positive?
899
- pane_attrs[:ySplit] = freeze_pane[:row].to_s if freeze_pane[:row]&.positive?
900
- top_left_col = column_letter(freeze_pane[:col] || 0)
901
- top_left_row = (freeze_pane[:row] || 0) + 1
914
+ col_val = freeze_pane[:column] || freeze_pane[:col]
915
+ row_val = freeze_pane[:row]
916
+ pane_attrs[:xSplit] = col_val.to_s if col_val&.positive?
917
+ pane_attrs[:ySplit] = row_val.to_s if row_val&.positive?
918
+ top_left_col = column_letter(col_val || 0)
919
+ top_left_row = (row_val || 0) + 1
902
920
  pane_attrs[:topLeftCell] = freeze_pane[:top_left_cell] || "#{top_left_col}#{top_left_row}"
903
921
  pane_attrs[:state] = "frozen"
904
922
  # Determine active pane
905
- pane_attrs[:activePane] = freeze_pane[:active_pane] || if (freeze_pane[:col] || 0).positive? && (freeze_pane[:row] || 0).positive?
923
+ pane_attrs[:activePane] = freeze_pane[:active_pane] || if (col_val || 0).positive? && (row_val || 0).positive?
906
924
  "bottomRight"
907
- elsif (freeze_pane[:col] || 0).positive?
925
+ elsif (col_val || 0).positive?
908
926
  "topRight"
909
927
  else
910
928
  "bottomLeft"
@@ -1359,6 +1377,8 @@ module Xlsxrb
1359
1377
  attrs[:pageOrder] = opts[:page_order].to_s if opts[:page_order]
1360
1378
  attrs[:blackAndWhite] = "1" if opts[:black_and_white]
1361
1379
  attrs[:draft] = "1" if opts[:draft]
1380
+ attrs[:horizontalDpi] = opts[:horizontal_dpi].to_s if opts[:horizontal_dpi].to_i.positive?
1381
+ attrs[:verticalDpi] = opts[:vertical_dpi].to_s if opts[:vertical_dpi].to_i.positive?
1362
1382
  @builder.empty_tag("pageSetup", attrs) unless attrs.empty?
1363
1383
  end
1364
1384
 
@@ -1474,7 +1494,8 @@ module Xlsxrb
1474
1494
  group = group.to_h if group.is_a?(Elements::MetadataRecord)
1475
1495
  sg_attrs = {}
1476
1496
  sg_attrs[:type] = group[:type] if group[:type]
1477
- sg_attrs[:displayEmptyCellsAs] = group[:display_empty] if group[:display_empty]
1497
+ disp_empty = group[:display_empty_cells_as] || group[:display_empty]
1498
+ sg_attrs[:displayEmptyCellsAs] = disp_empty if disp_empty
1478
1499
  sg_attrs[:markers] = "1" if group[:markers]
1479
1500
  sg_attrs[:high] = "1" if group[:high]
1480
1501
  sg_attrs[:low] = "1" if group[:low]
@@ -1504,10 +1525,10 @@ module Xlsxrb
1504
1525
  sp = sp.to_h if sp.is_a?(Elements::MetadataRecord)
1505
1526
  @builder.open_tag("x14:sparkline")
1506
1527
  @builder.open_tag("xm:f")
1507
- @builder.text(sp[:data_ref] || sp[:formula] || sp[:f])
1528
+ @builder.text(sp[:formula] || sp[:data_ref] || sp[:f])
1508
1529
  @builder.close_tag("xm:f")
1509
1530
  @builder.open_tag("xm:sqref")
1510
- @builder.text(sp[:location_ref] || sp[:sqref] || sp[:location])
1531
+ @builder.text(sp[:sqref] || sp[:location_ref] || sp[:location])
1511
1532
  @builder.close_tag("xm:sqref")
1512
1533
  @builder.close_tag("x14:sparkline")
1513
1534
  end
@@ -1535,10 +1556,7 @@ module Xlsxrb
1535
1556
  # --- Columns ---
1536
1557
 
1537
1558
  def write_columns(columns)
1538
- default_width = if @sheet_format
1539
- @sheet_format[:default_column_width] || @sheet_format[:default_col_width] ||
1540
- @sheet_format["default_column_width"] || @sheet_format["default_col_width"]
1541
- end
1559
+ default_width = @sheet_format.to_h[:default_column_width]
1542
1560
  @builder.open_tag("cols")
1543
1561
  columns.each do |col|
1544
1562
  if col.is_a?(Elements::Column)
@@ -1546,11 +1564,11 @@ module Xlsxrb
1546
1564
  max = col.unmapped_data[:max] || (col.index + 1)
1547
1565
  style_id = col.style_index
1548
1566
  width = col.width || (style_id ? default_width : nil)
1549
- hidden = col.hidden
1550
- custom_width = col.custom_width || !width.nil?
1567
+ hidden = col.hidden?
1568
+ custom_width = col.custom_width? || !width.nil?
1551
1569
  outline_level = col.outline_level
1552
- collapsed = col.unmapped_data[:collapsed]
1553
- best_fit = (col.respond_to?(:best_fit) && col.best_fit) || col.unmapped_data[:best_fit]
1570
+ collapsed = col.collapsed? || col.unmapped_data[:collapsed]
1571
+ best_fit = col.best_fit? || col.unmapped_data[:best_fit]
1554
1572
  else
1555
1573
  min = col[:min] || ((col[:index] || 0) + 1)
1556
1574
  max = col[:max] || ((col[:index] || 0) + 1)
@@ -1619,7 +1637,7 @@ module Xlsxrb
1619
1637
  f_attrs[:t] = formula.type.to_s if formula.type
1620
1638
  f_attrs[:ref] = formula.ref if formula.ref
1621
1639
  f_attrs[:si] = formula.shared_index.to_s if formula.shared_index
1622
- f_attrs[:ca] = "1" if formula.calculate_always
1640
+ f_attrs[:ca] = "1" if formula.calculate_always?
1623
1641
  else
1624
1642
  formula_text = formula_text[1..] if formula_text.is_a?(String) && formula_text.start_with?("=")
1625
1643
  f_type = cell[:formula_type] || cell[:type]
@@ -1673,8 +1691,8 @@ module Xlsxrb
1673
1691
  def write_inline_rich_text(buf, rich_text)
1674
1692
  buf << "><is>"
1675
1693
  rich_text.runs.each do |run|
1676
- font = run.is_a?(Hash) ? run[:font] : run.font
1677
- run_text = run.is_a?(Hash) ? run[:text] : run.text
1694
+ font = run.respond_to?(:font) ? run.font : run[:font]
1695
+ text = run.respond_to?(:text) ? run.text : run[:text]
1678
1696
  if font && !font.empty?
1679
1697
  buf << "<r><rPr>"
1680
1698
  buf << "<b/>" if font[:bold]
@@ -1732,7 +1750,7 @@ module Xlsxrb
1732
1750
  else
1733
1751
  buf << "<r><t>"
1734
1752
  end
1735
- buf << escape_xml(run_text.to_s) << "</t></r>"
1753
+ buf << escape_xml(text.to_s) << "</t></r>"
1736
1754
  end
1737
1755
  buf << "</is></c>"
1738
1756
  end
@@ -22,8 +22,8 @@ module Xlsxrb
22
22
  ea = img[:edit_as] || "oneCell"
23
23
  img_pub_attr = img[:published] ? ' fPublished="1"' : ""
24
24
  parts << %(<xdr:twoCellAnchor editAs="#{xml_escape(ea)}"#{img_pub_attr}>)
25
- parts << anchor_xml("from", img[:from_col], img[:from_row], col_off: img[:from_col_off] || 0, row_off: img[:from_row_off] || 0)
26
- parts << anchor_xml("to", img[:to_col], img[:to_row], col_off: img[:to_col_off] || 0, row_off: img[:to_row_off] || 0)
25
+ parts << anchor_xml("from", img[:from_column] || img[:from_col], img[:from_row], col_off: img[:from_col_off] || 0, row_off: img[:from_row_off] || 0)
26
+ parts << anchor_xml("to", img[:to_column] || img[:to_col], img[:to_row], col_off: img[:to_col_off] || 0, row_off: img[:to_row_off] || 0)
27
27
  macro_attr = img[:macro] ? %( macro="#{xml_escape(img[:macro])}") : ""
28
28
  parts << "<xdr:pic#{macro_attr}>"
29
29
  descr_attr = img[:description] ? %( descr="#{xml_escape(img[:description])}") : ""
@@ -68,8 +68,8 @@ module Xlsxrb
68
68
  chart_ea_attr = chart[:edit_as] ? %( editAs="#{xml_escape(chart[:edit_as])}") : ""
69
69
  chart_pub_attr = chart[:published] ? ' fPublished="1"' : ""
70
70
  parts << "<xdr:twoCellAnchor#{chart_ea_attr}#{chart_pub_attr}>"
71
- parts << anchor_xml("from", chart[:from_col], chart[:from_row], col_off: chart[:from_col_off] || 0, row_off: chart[:from_row_off] || 0)
72
- parts << anchor_xml("to", chart[:to_col], chart[:to_row], col_off: chart[:to_col_off] || 0, row_off: chart[:to_row_off] || 0)
71
+ parts << anchor_xml("from", chart[:from_column] || chart[:from_col], chart[:from_row], col_off: chart[:from_col_off] || 0, row_off: chart[:from_row_off] || 0)
72
+ parts << anchor_xml("to", chart[:to_column] || chart[:to_col], chart[:to_row], col_off: chart[:to_col_off] || 0, row_off: chart[:to_row_off] || 0)
73
73
  gf_macro = chart[:frame_macro] ? xml_escape(chart[:frame_macro]) : ""
74
74
  parts << %(<xdr:graphicFrame macro="#{gf_macro}">)
75
75
  chart_frame_name = chart[:name] || chart[:title] || "Chart"
@@ -93,8 +93,8 @@ module Xlsxrb
93
93
  shape_ea_attr = shape[:edit_as] ? %( editAs="#{xml_escape(shape[:edit_as])}") : ""
94
94
  shape_pub_attr = shape[:published] ? ' fPublished="1"' : ""
95
95
  parts << "<xdr:twoCellAnchor#{shape_ea_attr}#{shape_pub_attr}>"
96
- parts << anchor_xml("from", shape[:from_col], shape[:from_row], col_off: shape[:from_col_off] || 0, row_off: shape[:from_row_off] || 0)
97
- parts << anchor_xml("to", shape[:to_col], shape[:to_row], col_off: shape[:to_col_off] || 0, row_off: shape[:to_row_off] || 0)
96
+ parts << anchor_xml("from", shape[:from_column] || shape[:from_col], shape[:from_row], col_off: shape[:from_col_off] || 0, row_off: shape[:from_row_off] || 0)
97
+ parts << anchor_xml("to", shape[:to_column] || shape[:to_col], shape[:to_row], col_off: shape[:to_col_off] || 0, row_off: shape[:to_row_off] || 0)
98
98
  sp_macro_attr = shape[:macro] ? %( macro="#{xml_escape(shape[:macro])}") : ""
99
99
  sp_textlink_attr = shape[:textlink] ? %( textlink="#{xml_escape(shape[:textlink])}") : ""
100
100
  parts << "<xdr:sp#{sp_macro_attr}#{sp_textlink_attr}>"
@@ -891,7 +891,8 @@ module Xlsxrb
891
891
 
892
892
  # : (untyped chart) -> untyped
893
893
  def generate_chart_xml(chart)
894
- chart_type = CHART_TYPE_MAP[chart[:type]] || "barChart"
894
+ # Charts read from files carry the element name ("lineChart") as their type.
895
+ chart_type = CHART_TYPE_MAP[chart[:type]] || CHART_TYPE_MAP.values.find { |element| element == chart[:type].to_s } || "barChart"
895
896
  parts = [
896
897
  XML_HEADER,
897
898
  %(<c:chartSpace xmlns:c="#{C_NS}" xmlns:a="#{A_NS}" xmlns:r="#{DOC_REL_NS}">)
@@ -1037,9 +1038,11 @@ module Xlsxrb
1037
1038
  ser_order = ser[:order] || idx
1038
1039
  parts << "<c:ser><c:idx val=\"#{idx}\"/><c:order val=\"#{ser_order}\"/>"
1039
1040
  parts << "<c:tx><c:strRef><c:f>#{xml_escape(ser[:name])}</c:f>#{str_cache_xml(ser[:name])}</c:strRef></c:tx>" if ser[:name]
1041
+ head_end = parts.size
1040
1042
  iin = ser[:invert_if_negative]
1041
1043
  parts << %(<c:invertIfNegative val="#{iin ? 1 : 0}"/>) unless iin.nil?
1042
1044
  parts << %(<c:explosion val="#{ser[:explosion]}"/>) if ser[:explosion]
1045
+ options_end = parts.size
1043
1046
  ser[:data_points]&.each do |dp|
1044
1047
  parts << "<c:dPt><c:idx val=\"#{dp[:idx]}\"/>"
1045
1048
  dp_iin = dp[:invert_if_negative]
@@ -1081,6 +1084,7 @@ module Xlsxrb
1081
1084
  parts << "<c:spPr>#{dp_sp_children}</c:spPr>" unless dp_sp_children.empty?
1082
1085
  parts << "</c:dPt>"
1083
1086
  end
1087
+ data_points_end = parts.size
1084
1088
  if ser[:fill_color] || ser[:no_fill] || ser[:line_color] || ser[:no_line] || ser[:line_width] || ser[:line_cap] || ser[:line_join] || ser[:line_dash]
1085
1089
  parts << "<c:spPr>"
1086
1090
  parts << %(<a:solidFill>#{color_xml(ser[:fill_color])}</a:solidFill>) if ser[:fill_color]
@@ -1102,6 +1106,7 @@ module Xlsxrb
1102
1106
  end
1103
1107
  parts << "</c:spPr>"
1104
1108
  end
1109
+ shape_end = parts.size
1105
1110
  if ser[:marker_symbol] || ser[:marker_size] || ser[:marker_fill] || ser[:marker_no_fill] || ser[:marker_line_color] || ser[:marker_line_dash] || ser[:marker_no_line]
1106
1111
  parts << "<c:marker>"
1107
1112
  parts << %(<c:symbol val="#{xml_escape(ser[:marker_symbol])}"/>) if ser[:marker_symbol]
@@ -1122,6 +1127,13 @@ module Xlsxrb
1122
1127
  end
1123
1128
  parts << "</c:marker>"
1124
1129
  end
1130
+ # The series schemas order these children spPr, then invertIfNegative, marker, or
1131
+ # explosion (by chart type), then dPt.
1132
+ options = parts[head_end...options_end]
1133
+ data_points = parts[options_end...data_points_end]
1134
+ shape = parts[data_points_end...shape_end]
1135
+ marker = parts[shape_end..]
1136
+ parts[head_end..] = shape + options + marker + data_points
1125
1137
  if (dl = ser[:data_labels] || chart[:data_labels])
1126
1138
  parts << "<c:dLbls>"
1127
1139
  dl[:labels]&.each do |lbl|
@@ -1333,8 +1345,11 @@ module Xlsxrb
1333
1345
  snb = chart[:show_neg_bubbles]
1334
1346
  parts << %(<c:showNegBubbles val="#{snb ? 1 : 0}"/>) unless snb.nil?
1335
1347
  parts << %(<c:sizeRepresents val="#{chart[:size_represents]}"/>) if chart[:size_represents]
1336
- parts << %(<c:firstSliceAng val="#{chart[:first_slice_ang]}"/>) if chart[:first_slice_ang]
1337
- parts << %(<c:holeSize val="#{chart[:hole_size]}"/>) if chart[:hole_size]
1348
+ # Doughnut charts carry both; Excel's defaults are 0 and 50.
1349
+ first_slice_ang = chart[:first_slice_ang] || (0 if g_type == "doughnutChart")
1350
+ hole_size = chart[:hole_size] || (50 if g_type == "doughnutChart")
1351
+ parts << %(<c:firstSliceAng val="#{first_slice_ang}"/>) if first_slice_ang
1352
+ parts << %(<c:holeSize val="#{hole_size}"/>) if hole_size
1338
1353
  if chart[:ser_lines]
1339
1354
  sl_spec = chart[:ser_lines]
1340
1355
  if sl_spec.is_a?(Hash)
@@ -1653,17 +1668,19 @@ module Xlsxrb
1653
1668
  sheet_comments.each_with_index do |c, idx|
1654
1669
  col, row = cell_to_col_row(c[:ref])
1655
1670
  shape_id = 1025 + idx
1656
- parts << %(<v:shape id="_x0000_s#{shape_id}" type="#_x0000_t202" style="position:absolute;margin-left:59.25pt;margin-top:1.5pt;width:108pt;height:59.25pt;z-index:#{idx + 1};visibility:hidden" fillcolor="#ffffe1" o:insetmode="auto">)
1671
+ parts << %(<v:shape id="_x0000_s#{shape_id}" type="#_x0000_t202" style="position:absolute;margin-left:59.25pt;margin-top:1.5pt;width:108pt;height:59.25pt;z-index:#{idx + 1};visibility:#{c[:visible] ? "visible" : "hidden"}" fillcolor="#ffffe1" o:insetmode="auto">)
1657
1672
  parts << '<v:fill color2="#ffffe1"/>'
1658
1673
  parts << '<v:shadow on="t" color="black" obscured="t"/>'
1659
1674
  parts << '<v:path o:connecttype="none"/>'
1660
1675
  parts << '<v:textbox style="mso-direction-alt:auto"><div style="text-align:left"></div></v:textbox>'
1661
1676
  parts << '<x:ClientData ObjectType="Note">'
1662
1677
  parts << "<x:MoveWithCells/><x:SizeWithCells/>"
1663
- parts << "<x:Anchor>#{col + 1}, 15, #{row}, 10, #{col + 3}, 15, #{row + 4}, 4</x:Anchor>"
1678
+ anchor = c[:anchor] || Xlsxrb::Elements::Comment.default_anchor(col, row)
1679
+ parts << "<x:Anchor>#{anchor.join(", ")}</x:Anchor>"
1664
1680
  parts << "<x:AutoFill>False</x:AutoFill>"
1665
1681
  parts << "<x:Row>#{row}</x:Row>"
1666
1682
  parts << "<x:Column>#{col}</x:Column>"
1683
+ parts << "<x:Visible/>" if c[:visible]
1667
1684
  parts << "</x:ClientData></v:shape>"
1668
1685
  end
1669
1686
  parts << "</xml>"