write_xlsx 1.10.2 → 1.11.1
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -1
- data/Changes +18 -0
- data/examples/autofit.rb +37 -0
- data/examples/chart_radar.rb +3 -9
- data/lib/write_xlsx/chart/area.rb +1 -0
- data/lib/write_xlsx/chart/axis.rb +1 -0
- data/lib/write_xlsx/chart/bar.rb +1 -0
- data/lib/write_xlsx/chart/caption.rb +1 -0
- data/lib/write_xlsx/chart/column.rb +1 -0
- data/lib/write_xlsx/chart/doughnut.rb +1 -0
- data/lib/write_xlsx/chart/legend.rb +1 -0
- data/lib/write_xlsx/chart/line.rb +1 -0
- data/lib/write_xlsx/chart/pie.rb +1 -0
- data/lib/write_xlsx/chart/radar.rb +1 -0
- data/lib/write_xlsx/chart/scatter.rb +1 -0
- data/lib/write_xlsx/chart/series.rb +8 -4
- data/lib/write_xlsx/chart/stock.rb +1 -0
- data/lib/write_xlsx/chart.rb +45 -14
- data/lib/write_xlsx/colors.rb +20 -19
- data/lib/write_xlsx/format.rb +13 -9
- data/lib/write_xlsx/package/comments.rb +2 -1
- data/lib/write_xlsx/package/conditional_format.rb +4 -4
- data/lib/write_xlsx/package/shared_strings.rb +5 -3
- data/lib/write_xlsx/package/styles.rb +27 -30
- data/lib/write_xlsx/package/table.rb +9 -0
- data/lib/write_xlsx/utility.rb +40 -7
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +20 -11
- data/lib/write_xlsx/worksheet/cell_data.rb +11 -4
- data/lib/write_xlsx/worksheet.rb +264 -81
- metadata +4 -3
@@ -51,6 +51,7 @@ module Writexlsx
|
|
51
51
|
|
52
52
|
add_the_table_columns
|
53
53
|
write_the_cell_data_if_supplied
|
54
|
+
store_filter_cell_positions
|
54
55
|
end
|
55
56
|
|
56
57
|
def set_xml_writer(filename)
|
@@ -155,6 +156,14 @@ module Writexlsx
|
|
155
156
|
end
|
156
157
|
end
|
157
158
|
|
159
|
+
def store_filter_cell_positions
|
160
|
+
if ptrue?(@param[:autofilter])
|
161
|
+
(@col1..@col2).each do |col|
|
162
|
+
@worksheet.filter_cells["#{@row1}:#{col}"] = 1
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
158
167
|
def prepare(id)
|
159
168
|
@id = id
|
160
169
|
@name ||= "Table#{id}"
|
data/lib/write_xlsx/utility.rb
CHANGED
@@ -5,10 +5,28 @@ require 'write_xlsx/col_name'
|
|
5
5
|
|
6
6
|
module Writexlsx
|
7
7
|
module Utility
|
8
|
-
ROW_MAX
|
9
|
-
COL_MAX
|
10
|
-
STR_MAX
|
8
|
+
ROW_MAX = 1048576 # :nodoc:
|
9
|
+
COL_MAX = 16384 # :nodoc:
|
10
|
+
STR_MAX = 32767 # :nodoc:
|
11
11
|
SHEETNAME_MAX = 31 # :nodoc:
|
12
|
+
CHAR_WIDTHS = {
|
13
|
+
' ' => 3, '!' => 5, '"' => 6, '#' => 7, '$' => 7, '%' => 11,
|
14
|
+
'&' => 10, "'" => 3, '(' => 5, ')' => 5, '*' => 7, '+' => 7,
|
15
|
+
',' => 4, '-' => 5, '.' => 4, '/' => 6, '0' => 7, '1' => 7,
|
16
|
+
'2' => 7, '3' => 7, '4' => 7, '5' => 7, '6' => 7, '7' => 7,
|
17
|
+
'8' => 7, '9' => 7, ':' => 4, ';' => 4, '<' => 7, '=' => 7,
|
18
|
+
'>' => 7, '?' => 7, '@' => 13, 'A' => 9, 'B' => 8, 'C' => 8,
|
19
|
+
'D' => 9, 'E' => 7, 'F' => 7, 'G' => 9, 'H' => 9, 'I' => 4,
|
20
|
+
'J' => 5, 'K' => 8, 'L' => 6, 'M' => 12, 'N' => 10, 'O' => 10,
|
21
|
+
'P' => 8, 'Q' => 10, 'R' => 8, 'S' => 7, 'T' => 7, 'U' => 9,
|
22
|
+
'V' => 9, 'W' => 13, 'X' => 8, 'Y' => 7, 'Z' => 7, '[' => 5,
|
23
|
+
'\\' => 6, ']' => 5, '^' => 7, '_' => 7, '`' => 4, 'a' => 7,
|
24
|
+
'b' => 8, 'c' => 6, 'd' => 8, 'e' => 8, 'f' => 5, 'g' => 7,
|
25
|
+
'h' => 8, 'i' => 4, 'j' => 4, 'k' => 7, 'l' => 4, 'm' => 12,
|
26
|
+
'n' => 8, 'o' => 8, 'p' => 8, 'q' => 8, 'r' => 5, 's' => 6,
|
27
|
+
't' => 5, 'u' => 8, 'v' => 7, 'w' => 11, 'x' => 7, 'y' => 7,
|
28
|
+
'z' => 6, '{' => 5, '|' => 7, '}' => 5, '~' => 7
|
29
|
+
}.freeze
|
12
30
|
|
13
31
|
#
|
14
32
|
# xl_rowcol_to_cell($row, col, row_absolute, col_absolute)
|
@@ -84,6 +102,21 @@ module Writexlsx
|
|
84
102
|
"=#{sheetname}!#{range1}:#{range2}"
|
85
103
|
end
|
86
104
|
|
105
|
+
#
|
106
|
+
# xl_string_pixel_width($string)
|
107
|
+
#
|
108
|
+
# Get the pixel width of a string based on individual character widths taken
|
109
|
+
# from Excel. UTF8 characters are given a default width of 8.
|
110
|
+
#
|
111
|
+
# Note, Excel adds an additional 7 pixels padding to a cell.
|
112
|
+
#
|
113
|
+
def xl_string_pixel_width(string)
|
114
|
+
length = 0
|
115
|
+
string.to_s.split(//).each { |char| length += CHAR_WIDTHS[char] || 8 }
|
116
|
+
|
117
|
+
length
|
118
|
+
end
|
119
|
+
|
87
120
|
#
|
88
121
|
# Sheetnames used in references should be quoted if they contain any spaces,
|
89
122
|
# special characters or if the look like something that isn't a sheet name.
|
@@ -258,7 +291,7 @@ module Writexlsx
|
|
258
291
|
|
259
292
|
# Check for a cell reference in A1 notation and substitute row and column
|
260
293
|
def row_col_notation(row_or_a1) # :nodoc:
|
261
|
-
substitute_cellref(row_or_a1) if row_or_a1.to_s =~ /^\D/
|
294
|
+
substitute_cellref(row_or_a1) if row_or_a1.respond_to?(:match) && row_or_a1.to_s =~ /^\D/
|
262
295
|
end
|
263
296
|
|
264
297
|
#
|
@@ -308,7 +341,7 @@ module Writexlsx
|
|
308
341
|
#
|
309
342
|
# Write the <color> element.
|
310
343
|
#
|
311
|
-
def write_color(
|
344
|
+
def write_color(name, value, writer = @writer) # :nodoc:
|
312
345
|
attributes = [[name, value]]
|
313
346
|
|
314
347
|
writer.empty_tag('color', attributes)
|
@@ -718,8 +751,8 @@ module Writexlsx
|
|
718
751
|
# Adjust the colour index.
|
719
752
|
idx = index - 8
|
720
753
|
|
721
|
-
|
722
|
-
sprintf("%02X%02X%02X",
|
754
|
+
r, g, b = @palette[idx]
|
755
|
+
sprintf("%02X%02X%02X", r, g, b)
|
723
756
|
end
|
724
757
|
|
725
758
|
#
|
data/lib/write_xlsx/version.rb
CHANGED
data/lib/write_xlsx/workbook.rb
CHANGED
@@ -58,7 +58,7 @@ module Writexlsx
|
|
58
58
|
@xf_formats = []
|
59
59
|
@dxf_formats = []
|
60
60
|
@font_count = 0
|
61
|
-
@
|
61
|
+
@num_formats = []
|
62
62
|
@defined_names = []
|
63
63
|
@named_ranges = []
|
64
64
|
@custom_colors = []
|
@@ -560,7 +560,7 @@ module Writexlsx
|
|
560
560
|
@xf_formats,
|
561
561
|
@palette,
|
562
562
|
@font_count,
|
563
|
-
@
|
563
|
+
@num_formats,
|
564
564
|
@border_count,
|
565
565
|
@fill_count,
|
566
566
|
@custom_colors,
|
@@ -869,6 +869,9 @@ module Writexlsx
|
|
869
869
|
@activesheet = @worksheets.visible_first.index if @activesheet == 0
|
870
870
|
@worksheets[@activesheet].activate
|
871
871
|
|
872
|
+
# Convert the SST strings data structure.
|
873
|
+
prepare_sst_string_data
|
874
|
+
|
872
875
|
# Prepare the worksheet VML elements such as comments and buttons.
|
873
876
|
prepare_vml_objects
|
874
877
|
# Set the defined names for the worksheets such as Print Titles.
|
@@ -917,6 +920,11 @@ module Writexlsx
|
|
917
920
|
Dir.glob(File.join(tempdir, "**", "*"), File::FNM_DOTMATCH).select { |f| File.file?(f) }
|
918
921
|
end
|
919
922
|
|
923
|
+
#
|
924
|
+
# prepare_sst_string_data
|
925
|
+
#
|
926
|
+
def prepare_sst_string_data; end
|
927
|
+
|
920
928
|
#
|
921
929
|
# Prepare all of the format properties prior to passing them to Styles.rb.
|
922
930
|
#
|
@@ -977,9 +985,9 @@ module Writexlsx
|
|
977
985
|
# User defined records start from index 0xA4.
|
978
986
|
#
|
979
987
|
def prepare_num_formats # :nodoc:
|
980
|
-
num_formats
|
981
|
-
|
982
|
-
|
988
|
+
num_formats = []
|
989
|
+
unique_num_formats = {}
|
990
|
+
index = 164
|
983
991
|
|
984
992
|
(@xf_formats + @dxf_formats).each do |format|
|
985
993
|
num_format = format.num_format
|
@@ -1000,21 +1008,22 @@ module Writexlsx
|
|
1000
1008
|
next
|
1001
1009
|
end
|
1002
1010
|
|
1003
|
-
if
|
1011
|
+
if unique_num_formats[num_format]
|
1004
1012
|
# Number format has already been used.
|
1005
|
-
format.num_format_index =
|
1013
|
+
format.num_format_index = unique_num_formats[num_format]
|
1006
1014
|
else
|
1007
1015
|
# Add a new number format.
|
1008
|
-
|
1016
|
+
unique_num_formats[num_format] = index
|
1009
1017
|
format.num_format_index = index
|
1010
1018
|
index += 1
|
1011
1019
|
|
1012
|
-
# Only increase
|
1013
|
-
|
1020
|
+
# Only store/increase number format count for XF formats
|
1021
|
+
# (not for DXF formats).
|
1022
|
+
num_formats << num_format if ptrue?(format.xf_index)
|
1014
1023
|
end
|
1015
1024
|
end
|
1016
1025
|
|
1017
|
-
@
|
1026
|
+
@num_formats = num_formats
|
1018
1027
|
end
|
1019
1028
|
|
1020
1029
|
#
|
@@ -24,8 +24,8 @@ module Writexlsx
|
|
24
24
|
elsif worksheet.set_rows[row] && worksheet.set_rows[row][1]
|
25
25
|
row_xf = worksheet.set_rows[row][1]
|
26
26
|
attributes << ['s', row_xf.get_xf_index]
|
27
|
-
elsif worksheet.
|
28
|
-
col_xf = worksheet.
|
27
|
+
elsif worksheet.col_info[col] && worksheet.col_info[col].format
|
28
|
+
col_xf = worksheet.col_info[col].format
|
29
29
|
attributes << ['s', col_xf.get_xf_index]
|
30
30
|
end
|
31
31
|
attributes
|
@@ -56,11 +56,12 @@ module Writexlsx
|
|
56
56
|
end
|
57
57
|
|
58
58
|
class StringCellData < CellData # :nodoc:
|
59
|
-
attr_reader :token
|
59
|
+
attr_reader :token, :raw_string
|
60
60
|
|
61
|
-
def initialize(index, xf)
|
61
|
+
def initialize(index, xf, raw_string)
|
62
62
|
@token = index
|
63
63
|
@xf = xf
|
64
|
+
@raw_string = raw_string
|
64
65
|
end
|
65
66
|
|
66
67
|
def data
|
@@ -81,6 +82,12 @@ module Writexlsx
|
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
85
|
+
class RichStringCellData < StringCellData # :nodoc:
|
86
|
+
end
|
87
|
+
|
88
|
+
class DateTimeCellData < NumberCellData # :nodoc:
|
89
|
+
end
|
90
|
+
|
84
91
|
class FormulaCellData < CellData # :nodoc:
|
85
92
|
attr_reader :token, :result, :range, :link_type, :url
|
86
93
|
|