write_xlsx 1.08.2 → 1.09.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.
- checksums.yaml +4 -4
- data/Changes +9 -0
- data/README.md +1 -1
- data/examples/background.rb +19 -0
- data/lib/write_xlsx/chart/axis.rb +3 -3
- data/lib/write_xlsx/chart/scatter.rb +0 -15
- data/lib/write_xlsx/chart/series.rb +1 -1
- data/lib/write_xlsx/chart.rb +28 -28
- data/lib/write_xlsx/chartsheet.rb +3 -3
- data/lib/write_xlsx/drawing.rb +39 -39
- data/lib/write_xlsx/format.rb +11 -179
- data/lib/write_xlsx/package/app.rb +2 -2
- data/lib/write_xlsx/package/button.rb +8 -8
- data/lib/write_xlsx/package/comments.rb +8 -8
- data/lib/write_xlsx/package/content_types.rb +18 -9
- data/lib/write_xlsx/package/core.rb +5 -5
- data/lib/write_xlsx/package/custom.rb +2 -2
- data/lib/write_xlsx/package/metadata.rb +159 -0
- data/lib/write_xlsx/package/packager.rb +21 -0
- data/lib/write_xlsx/package/shared_strings.rb +6 -6
- data/lib/write_xlsx/package/styles.rb +11 -11
- data/lib/write_xlsx/package/table.rb +23 -23
- data/lib/write_xlsx/package/theme.rb +1 -1
- data/lib/write_xlsx/package/vml.rb +43 -43
- data/lib/write_xlsx/shape.rb +17 -15
- data/lib/write_xlsx/sparkline.rb +340 -340
- data/lib/write_xlsx/utility.rb +4 -23
- data/lib/write_xlsx/version.rb +1 -1
- data/lib/write_xlsx/workbook.rb +171 -644
- data/lib/write_xlsx/worksheet/cell_data.rb +25 -3
- data/lib/write_xlsx/worksheet/data_validation.rb +20 -20
- data/lib/write_xlsx/worksheet/hyperlink.rb +4 -4
- data/lib/write_xlsx/worksheet/page_setup.rb +12 -12
- data/lib/write_xlsx/worksheet.rb +295 -4184
- data/test/perl_output/background.xlsx +0 -0
- data/test/regression/images/logo.gif +0 -0
- data/test/regression/images/logo.jpg +0 -0
- data/test/regression/images/red.gif +0 -0
- data/test/regression/test_background01.rb +23 -0
- data/test/regression/test_background02.rb +23 -0
- data/test/regression/test_background03.rb +24 -0
- data/test/regression/test_background04.rb +25 -0
- data/test/regression/test_background05.rb +25 -0
- data/test/regression/test_background06.rb +31 -0
- data/test/regression/test_background07.rb +37 -0
- data/test/regression/test_chart_axis47.rb +52 -0
- data/test/regression/test_chart_axis48.rb +53 -0
- data/test/regression/test_dynamic_array01.rb +25 -0
- data/test/regression/test_image56.rb +23 -0
- data/test/regression/test_image57.rb +23 -0
- data/test/regression/test_set_column10.rb +55 -0
- data/test/regression/test_set_column11.rb +48 -0
- data/test/regression/test_set_row01.rb +35 -0
- data/test/regression/test_set_row02.rb +35 -0
- data/test/regression/test_set_row03.rb +35 -0
- data/test/regression/test_set_row04.rb +35 -0
- data/test/regression/xlsx_files/background01.xlsx +0 -0
- data/test/regression/xlsx_files/background02.xlsx +0 -0
- data/test/regression/xlsx_files/background03.xlsx +0 -0
- data/test/regression/xlsx_files/background04.xlsx +0 -0
- data/test/regression/xlsx_files/background05.xlsx +0 -0
- data/test/regression/xlsx_files/background06.xlsx +0 -0
- data/test/regression/xlsx_files/background07.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis47.xlsx +0 -0
- data/test/regression/xlsx_files/chart_axis48.xlsx +0 -0
- data/test/regression/xlsx_files/dynamic_array01.xlsx +0 -0
- data/test/regression/xlsx_files/image56.xlsx +0 -0
- data/test/regression/xlsx_files/image57.xlsx +0 -0
- data/test/regression/xlsx_files/set_row01.xlsx +0 -0
- data/test/regression/xlsx_files/set_row03.xlsx +0 -0
- data/test/test_example_match.rb +12 -0
- data/test/worksheet/test_pixels_to_row_col.rb +46 -0
- metadata +78 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6e34fc6f5c19637ceda0a196039c186fea4e0b6959c1d99d6d13260854cf0fd
|
4
|
+
data.tar.gz: c582b95f3b8e9851015bd8555a8d6b5a1e9d9d9f4cec1e66357ea328963b765e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00a16bb85b40a0e8ca072e1afaac2723f9bd845d28c4ea495c8c9fab0e4bad40c2f2b6cbe2875cdec97fcb8a0ad0a1f53a357c479e838bb873debba49e8de8f5
|
7
|
+
data.tar.gz: ae74b4e1506d658d770c3667f45043e3f999d10bce0700e48a40c0cfcc1d07ce7d40e4a77e8b51ea7b65dbaecc2b131a9793b124e064c9e5448ee50e5c16808e
|
data/Changes
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
Change history of write_xlsx rubygem.
|
2
2
|
|
3
|
+
2021-11-26 v1.09.0
|
4
|
+
|
5
|
+
Added support for background images in worksheets. See set_background().
|
6
|
+
|
7
|
+
Added support for GIF image files (and in Excel 365, animated GIF files).
|
8
|
+
|
9
|
+
Added support for pixel sizing in set_row() and set_column() via new
|
10
|
+
functions called set_row_pixels() and set_column_pixels().
|
11
|
+
|
3
12
|
2021-11-19 v1.08.0
|
4
13
|
|
5
14
|
Added ability to add accessibility options "description" and
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
gem to create a new file in the Excel 2007+ XLSX format, and you can use the
|
7
7
|
same interface as writeexcel gem. write_xlsx is converted from Perl's module
|
8
|
-
[Excel::Writer::XLSX-1.
|
8
|
+
[Excel::Writer::XLSX-1.09](https://github.com/jmcnamara/excel-writer-xlsx/tree/CPAN_1.09)
|
9
9
|
|
10
10
|
## Description
|
11
11
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#######################################################################
|
5
|
+
#
|
6
|
+
# An example of setting a worksheet background image with Excel::Writer::XLSX.
|
7
|
+
#
|
8
|
+
# Copyright 2000-2021, John McNamara, jmcnamara@cpan.org
|
9
|
+
# convert to ruby by Hideo NAKAMURA, nakamura.hideo@gmail.com
|
10
|
+
#
|
11
|
+
|
12
|
+
require 'write_xlsx'
|
13
|
+
|
14
|
+
workbook = WriteXLSX.new('background.xlsx')
|
15
|
+
worksheet = workbook.add_worksheet
|
16
|
+
|
17
|
+
worksheet.set_background('republic.png')
|
18
|
+
|
19
|
+
workbook.close
|
@@ -87,8 +87,8 @@ module Writexlsx
|
|
87
87
|
|
88
88
|
def num_fmt_attributes
|
89
89
|
[
|
90
|
-
|
91
|
-
|
90
|
+
['formatCode', @num_format],
|
91
|
+
['sourceLinked', source_linked]
|
92
92
|
]
|
93
93
|
end
|
94
94
|
|
@@ -175,7 +175,7 @@ module Writexlsx
|
|
175
175
|
if @position_axis == 'on_tick'
|
176
176
|
@position_axis = 'midCat'
|
177
177
|
elsif @position_axis == 'between'
|
178
|
-
|
178
|
+
# Doesn't neet to be modified.
|
179
179
|
else
|
180
180
|
# Otherwise use the default value.
|
181
181
|
@position_axis = nil
|
@@ -17,21 +17,6 @@ require 'write_xlsx/utility'
|
|
17
17
|
|
18
18
|
module Writexlsx
|
19
19
|
class Chart
|
20
|
-
# The Scatter chart module also supports the following sub-types:
|
21
|
-
#
|
22
|
-
# markers_only (the default)
|
23
|
-
# straight_with_markers
|
24
|
-
# straight
|
25
|
-
# smooth_with_markers
|
26
|
-
# smooth
|
27
|
-
# These can be specified at creation time via the add_chart() Worksheet
|
28
|
-
# method:
|
29
|
-
#
|
30
|
-
# chart = workbook.add_chart(
|
31
|
-
# :type => 'scatter',
|
32
|
-
# :subtype => 'straight_with_markers'
|
33
|
-
# )
|
34
|
-
#
|
35
20
|
class Scatter < self
|
36
21
|
include Writexlsx::Utility
|
37
22
|
include Writexlsx::WriteDPtPoint
|
@@ -192,7 +192,7 @@ module Writexlsx
|
|
192
192
|
@values = aref_to_formula(params[:values])
|
193
193
|
@categories = aref_to_formula(params[:categories])
|
194
194
|
@name, @name_formula =
|
195
|
-
|
195
|
+
chart.process_names(params[:name], params[:name_formula])
|
196
196
|
|
197
197
|
set_data_ids(params)
|
198
198
|
|
data/lib/write_xlsx/chart.rb
CHANGED
@@ -165,16 +165,16 @@ module Writexlsx
|
|
165
165
|
include Writexlsx::Utility
|
166
166
|
include Writexlsx::Gradient
|
167
167
|
|
168
|
-
attr_accessor :id, :name
|
169
|
-
attr_writer :index, :palette, :protection
|
170
|
-
attr_reader :embedded, :formula_ids, :formula_data
|
171
|
-
attr_reader :x_scale, :y_scale, :x_offset, :y_offset
|
172
|
-
attr_reader :width, :height
|
168
|
+
attr_accessor :id, :name # :nodoc:
|
169
|
+
attr_writer :index, :palette, :protection # :nodoc:
|
170
|
+
attr_reader :embedded, :formula_ids, :formula_data # :nodoc:
|
171
|
+
attr_reader :x_scale, :y_scale, :x_offset, :y_offset # :nodoc:
|
172
|
+
attr_reader :width, :height # :nodoc:
|
173
173
|
attr_reader :label_positions, :label_position_default, :combined # :nodoc:
|
174
|
-
attr_writer :date_category, :already_inserted
|
175
|
-
attr_writer :series_index
|
176
|
-
attr_writer :writer
|
177
|
-
attr_reader :x2_axis, :y2_axis, :axis2_ids
|
174
|
+
attr_writer :date_category, :already_inserted # :nodoc:
|
175
|
+
attr_writer :series_index # :nodoc:
|
176
|
+
attr_writer :writer # :nodoc:
|
177
|
+
attr_reader :x2_axis, :y2_axis, :axis2_ids # :nodoc:
|
178
178
|
|
179
179
|
#
|
180
180
|
# Factory method for returning chart objects based on their class type.
|
@@ -1057,7 +1057,7 @@ module Writexlsx
|
|
1057
1057
|
end
|
1058
1058
|
|
1059
1059
|
def write_val_base(formula, data_id, tag) # :nodoc:
|
1060
|
-
data
|
1060
|
+
data = @formula_data[data_id]
|
1061
1061
|
|
1062
1062
|
@writer.tag_elements(tag) do
|
1063
1063
|
# Unlike Cat axes data should only be numeric.
|
@@ -1408,11 +1408,11 @@ module Writexlsx
|
|
1408
1408
|
|
1409
1409
|
def write_scaling_with_param(param)
|
1410
1410
|
write_scaling(
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1411
|
+
param.reverse,
|
1412
|
+
param.min,
|
1413
|
+
param.max,
|
1414
|
+
param.log_base
|
1415
|
+
)
|
1416
1416
|
end
|
1417
1417
|
#
|
1418
1418
|
# Write the <c:scaling> element.
|
@@ -1443,7 +1443,7 @@ module Writexlsx
|
|
1443
1443
|
# Write the <c:orientation> element.
|
1444
1444
|
#
|
1445
1445
|
def write_orientation(reverse = nil) # :nodoc:
|
1446
|
-
val
|
1446
|
+
val = ptrue?(reverse) ? 'maxMin' : 'minMax'
|
1447
1447
|
|
1448
1448
|
@writer.empty_tag('c:orientation', [ ['val', val] ])
|
1449
1449
|
end
|
@@ -1499,9 +1499,9 @@ module Writexlsx
|
|
1499
1499
|
source_linked = 0
|
1500
1500
|
|
1501
1501
|
attributes = [
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1502
|
+
['formatCode', format_code],
|
1503
|
+
['sourceLinked', source_linked]
|
1504
|
+
]
|
1505
1505
|
|
1506
1506
|
@writer.empty_tag('c:numFmt', attributes)
|
1507
1507
|
end
|
@@ -1778,13 +1778,13 @@ module Writexlsx
|
|
1778
1778
|
footer = 0.3
|
1779
1779
|
|
1780
1780
|
attributes = [
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1781
|
+
['b', b],
|
1782
|
+
['l', l],
|
1783
|
+
['r', r],
|
1784
|
+
['t', t],
|
1785
|
+
['header', header],
|
1786
|
+
['footer', footer]
|
1787
|
+
]
|
1788
1788
|
|
1789
1789
|
@writer.empty_tag('c:pageMargins', attributes)
|
1790
1790
|
end
|
@@ -2272,7 +2272,7 @@ module Writexlsx
|
|
2272
2272
|
data.each_with_index do |token, i|
|
2273
2273
|
# Write non-numeric data as 0.
|
2274
2274
|
if token &&
|
2275
|
-
|
2275
|
+
!(token.to_s =~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/)
|
2276
2276
|
token = 0
|
2277
2277
|
end
|
2278
2278
|
|
@@ -2703,7 +2703,7 @@ module Writexlsx
|
|
2703
2703
|
end
|
2704
2704
|
|
2705
2705
|
def write_num_ref_or_lit(values, data)
|
2706
|
-
if values.to_s =~ /^=/
|
2706
|
+
if values.to_s =~ /^=/ # '=Sheet1!$A$1:$A$5'
|
2707
2707
|
write_num_ref(values, data, 'num')
|
2708
2708
|
else # [1, 2, 3]
|
2709
2709
|
write_num_lit(values)
|
@@ -204,9 +204,9 @@ module Writexlsx
|
|
204
204
|
mc_preserve_attributes = 'mv:*'
|
205
205
|
|
206
206
|
attributes = [
|
207
|
-
|
208
|
-
|
209
|
-
|
207
|
+
['xmlns', xmlns],
|
208
|
+
['xmlns:r', xmlns_r]
|
209
|
+
]
|
210
210
|
|
211
211
|
@writer.tag_elements('chartsheet', attributes) do
|
212
212
|
yield
|
data/lib/write_xlsx/drawing.rb
CHANGED
@@ -9,7 +9,7 @@ module Writexlsx
|
|
9
9
|
|
10
10
|
def initialize(type, dimensions, width, height, description, shape, anchor, rel_index = nil, url_rel_index = nil, tip = nil, decorative = nil)
|
11
11
|
@type, @dimensions, @width, @height, @description, @shape, @anchor, @rel_index, @url_rel_index, @tip, @decorative =
|
12
|
-
|
12
|
+
type, dimensions, width, height, description, shape, anchor, rel_index, url_rel_index, tip, decorative
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -70,8 +70,8 @@ module Writexlsx
|
|
70
70
|
def write_drawing_workspace
|
71
71
|
schema = 'http://schemas.openxmlformats.org/drawingml/'
|
72
72
|
attributes = [
|
73
|
-
|
74
|
-
|
73
|
+
['xmlns:xdr', "#{schema}2006/spreadsheetDrawing"],
|
74
|
+
['xmlns:a', "#{schema}2006/main"]
|
75
75
|
]
|
76
76
|
|
77
77
|
@writer.tag_elements('xdr:wsDr', attributes) { yield }
|
@@ -166,7 +166,7 @@ module Writexlsx
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
-
|
169
|
+
#
|
170
170
|
# Write the <xdr:from> element.
|
171
171
|
#
|
172
172
|
def write_from(col, row, col_offset, row_offset)
|
@@ -487,9 +487,9 @@ module Writexlsx
|
|
487
487
|
|
488
488
|
|
489
489
|
attributes = [
|
490
|
-
|
491
|
-
|
492
|
-
|
490
|
+
['xmlns:c', xmlns_c],
|
491
|
+
['xmlns:r', xmlns_r]
|
492
|
+
]
|
493
493
|
attributes << r_id_attributes(id)
|
494
494
|
|
495
495
|
@writer.empty_tag('c:chart', attributes)
|
@@ -519,9 +519,9 @@ module Writexlsx
|
|
519
519
|
else
|
520
520
|
# Add attribute for shapes.
|
521
521
|
attributes = [
|
522
|
-
|
523
|
-
|
524
|
-
|
522
|
+
[:macro, ''],
|
523
|
+
[:textlink, '']
|
524
|
+
]
|
525
525
|
@writer.tag_elements('xdr:sp', attributes) do
|
526
526
|
|
527
527
|
# Write the xdr:nvSpPr element.
|
@@ -554,17 +554,17 @@ module Writexlsx
|
|
554
554
|
|
555
555
|
if shape.start
|
556
556
|
attributes = [
|
557
|
-
|
558
|
-
|
559
|
-
|
557
|
+
['id', shape.start],
|
558
|
+
['idx', shape.start_index]
|
559
|
+
]
|
560
560
|
@writer.empty_tag('a:stCxn', attributes)
|
561
561
|
end
|
562
562
|
|
563
563
|
if shape.end
|
564
564
|
attributes = [
|
565
|
-
|
566
|
-
|
567
|
-
|
565
|
+
['id', shape.end],
|
566
|
+
['idx', shape.end_index]
|
567
|
+
]
|
568
568
|
@writer.empty_tag('a:endCxn', attributes)
|
569
569
|
end
|
570
570
|
end
|
@@ -808,9 +808,9 @@ module Writexlsx
|
|
808
808
|
adj_int = (adj * 1000).to_i
|
809
809
|
|
810
810
|
attributes = [
|
811
|
-
|
812
|
-
|
813
|
-
|
811
|
+
[:name, "adj#{suffix}"],
|
812
|
+
[:fmla, "val #{adj_int}"]
|
813
|
+
]
|
814
814
|
@writer.empty_tag('a:gd', attributes)
|
815
815
|
end
|
816
816
|
end
|
@@ -867,15 +867,15 @@ module Writexlsx
|
|
867
867
|
#
|
868
868
|
def write_tx_body(shape)
|
869
869
|
attributes = [
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
870
|
+
[:vertOverflow, "clip"],
|
871
|
+
[:wrap, "square"],
|
872
|
+
[:lIns, "27432"],
|
873
|
+
[:tIns, "22860"],
|
874
|
+
[:rIns, "27432"],
|
875
|
+
[:bIns, "22860"],
|
876
|
+
[:anchor, shape.valign],
|
877
|
+
[:upright, "1"]
|
878
|
+
]
|
879
879
|
@writer.tag_elements('xdr:txBody') do
|
880
880
|
@writer.empty_tag('a:bodyPr', attributes)
|
881
881
|
@writer.empty_tag('a:lstStyle')
|
@@ -885,9 +885,9 @@ module Writexlsx
|
|
885
885
|
rotation *= 60000
|
886
886
|
|
887
887
|
attributes = [
|
888
|
-
|
889
|
-
|
890
|
-
|
888
|
+
[:algn, shape.align],
|
889
|
+
[:rtl, rotation]
|
890
|
+
]
|
891
891
|
@writer.tag_elements('a:pPr', attributes) do
|
892
892
|
attributes = [ [:sz, "1000"] ]
|
893
893
|
@writer.empty_tag('a:defRPr', attributes)
|
@@ -903,14 +903,14 @@ module Writexlsx
|
|
903
903
|
strike = ptrue?(shape.format[:font_strikeout]) ? 'Strike' : 'noStrike'
|
904
904
|
|
905
905
|
attributes = [
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
906
|
+
[:lang, "en-US"],
|
907
|
+
[:sz, size],
|
908
|
+
[:b, bold],
|
909
|
+
[:i, italic],
|
910
|
+
[:u, underline],
|
911
|
+
[:strike, strike],
|
912
|
+
[:baseline, 0]
|
913
|
+
]
|
914
914
|
@writer.tag_elements('a:rPr', attributes) do
|
915
915
|
color = shape.format[:color]
|
916
916
|
if color
|
data/lib/write_xlsx/format.rb
CHANGED
@@ -2,177 +2,20 @@
|
|
2
2
|
require 'write_xlsx/utility'
|
3
3
|
|
4
4
|
module Writexlsx
|
5
|
-
# ==CELL FORMATTING
|
6
|
-
#
|
7
|
-
# This section describes the methods and properties that are available
|
8
|
-
# for formatting cells in Excel. The properties of a cell that can be
|
9
|
-
# formatted include: fonts, colours, patterns, borders, alignment and
|
10
|
-
# number formatting.
|
11
|
-
#
|
12
|
-
# ===Creating and using a Format object
|
13
|
-
#
|
14
|
-
# Cell formatting is defined through a Format object. Format objects
|
15
|
-
# are created by calling the workbook add_format() method as follows:
|
16
|
-
#
|
17
|
-
# format1 = workbook.add_format # Set properties later
|
18
|
-
# format2 = workbook.add_format(props_hash) # Set at creation
|
19
|
-
#
|
20
|
-
# The format object holds all the formatting properties that can be applied
|
21
|
-
# to a cell, a row or a column. The process of setting these properties is
|
22
|
-
# discussed in the next section.
|
23
|
-
#
|
24
|
-
# Once a Format object has been constructed and its properties have been
|
25
|
-
# set it can be passed as an argument to the worksheet write methods as
|
26
|
-
# follows:
|
27
|
-
#
|
28
|
-
# worksheet.write( 0, 0, 'One', format )
|
29
|
-
# worksheet.write_string( 1, 0, 'Two', format )
|
30
|
-
# worksheet.write_number( 2, 0, 3, format )
|
31
|
-
# worksheet.write_blank( 3, 0, format )
|
32
|
-
#
|
33
|
-
# Formats can also be passed to the worksheet set_row() and set_column()
|
34
|
-
# methods to define the default property for a row or column.
|
35
|
-
#
|
36
|
-
# worksheet.set_row( 0, 15, format )
|
37
|
-
# worksheet.set_column( 0, 0, 15, format )
|
38
|
-
#
|
39
|
-
# ===Format methods and Format properties
|
40
|
-
#
|
41
|
-
# The following table shows the Excel format categories, the formatting
|
42
|
-
# properties that can be applied and the equivalent object method:
|
43
|
-
#
|
44
|
-
# Category Description Property Method Name
|
45
|
-
# -------- ----------- -------- -----------
|
46
|
-
# Font Font type font set_font()
|
47
|
-
# Font size size set_size()
|
48
|
-
# Font color color set_color()
|
49
|
-
# Bold bold set_bold()
|
50
|
-
# Italic italic set_italic()
|
51
|
-
# Underline underline set_underline()
|
52
|
-
# Strikeout font_strikeout set_font_strikeout()
|
53
|
-
# Super/Subscript font_script set_font_script()
|
54
|
-
# Outline font_outline set_font_outline()
|
55
|
-
# Shadow font_shadow set_font_shadow()
|
56
|
-
#
|
57
|
-
# Number Numeric format num_format set_num_format()
|
58
|
-
#
|
59
|
-
# Protection Lock cells locked set_locked()
|
60
|
-
# Hide formulas hidden set_hidden()
|
61
|
-
#
|
62
|
-
# Alignment Horizontal align align set_align()
|
63
|
-
# Vertical align valign set_align()
|
64
|
-
# Rotation rotation set_rotation()
|
65
|
-
# Text wrap text_wrap set_text_wrap()
|
66
|
-
# Justify last text_justlast set_text_justlast()
|
67
|
-
# Center across center_across set_center_across()
|
68
|
-
# Indentation indent set_indent()
|
69
|
-
# Shrink to fit shrink set_shrink()
|
70
|
-
#
|
71
|
-
# Pattern Cell pattern pattern set_pattern()
|
72
|
-
# Background color bg_color set_bg_color()
|
73
|
-
# Foreground color fg_color set_fg_color()
|
74
|
-
#
|
75
|
-
# Border Cell border border set_border()
|
76
|
-
# Bottom border bottom set_bottom()
|
77
|
-
# Top border top set_top()
|
78
|
-
# Left border left set_left()
|
79
|
-
# Right border right set_right()
|
80
|
-
# Border color border_color set_border_color()
|
81
|
-
# Bottom color bottom_color set_bottom_color()
|
82
|
-
# Top color top_color set_top_color()
|
83
|
-
# Left color left_color set_left_color()
|
84
|
-
# Right color right_color set_right_color()
|
85
|
-
#
|
86
|
-
# There are two ways of setting Format properties: by using the object
|
87
|
-
# method interface or by setting the property directly. For example,
|
88
|
-
# a typical use of the method interface would be as follows:
|
89
|
-
#
|
90
|
-
# format = workbook.add_format
|
91
|
-
# format.set_bold
|
92
|
-
# format.set_color( 'red' )
|
93
|
-
#
|
94
|
-
# By comparison the properties can be set directly by passing a hash
|
95
|
-
# of properties to the Format constructor:
|
96
|
-
#
|
97
|
-
# format = workbook.add_format( :bold => 1, :color => 'red' )
|
98
|
-
#
|
99
|
-
# or after the Format has been constructed by means of the
|
100
|
-
# set_format_properties() method as follows:
|
101
|
-
#
|
102
|
-
# format = workbook.add_format
|
103
|
-
# format.set_format_properties( :bold => 1, :color => 'red' )
|
104
|
-
#
|
105
|
-
# You can also store the properties in one or more named hashes and pass
|
106
|
-
# them to the required method:
|
107
|
-
#
|
108
|
-
# font = {
|
109
|
-
# :font => 'Arial',
|
110
|
-
# :size => 12,
|
111
|
-
# :color => 'blue',
|
112
|
-
# :bold => 1
|
113
|
-
# }
|
114
|
-
#
|
115
|
-
# shading = {
|
116
|
-
# :bg_color => 'green',
|
117
|
-
# :pattern => 1
|
118
|
-
# }
|
119
|
-
#
|
120
|
-
# format1 = workbook.add_format( font ) # Font only
|
121
|
-
# format2 = workbook.add_format( font, shading ) # Font and shading
|
122
|
-
#
|
123
|
-
# The provision of two ways of setting properties might lead you to wonder
|
124
|
-
# which is the best way. The method mechanism may be better is you prefer
|
125
|
-
# setting properties via method calls (which the author did when the code
|
126
|
-
# was first written) otherwise passing properties to the constructor has
|
127
|
-
# proved to be a little more flexible and self documenting in practice.
|
128
|
-
# An additional advantage of working with property hashes is that it allows
|
129
|
-
# you to share formatting between workbook objects as shown in the example
|
130
|
-
# above.
|
131
|
-
#
|
132
|
-
# ===Working with formats
|
133
|
-
#
|
134
|
-
# The default format is Arial 10 with all other properties off.
|
135
|
-
#
|
136
|
-
# Each unique format in WriteXLSX must have a corresponding Format
|
137
|
-
# object. It isn't possible to use a Format with a write() method and then
|
138
|
-
# redefine the Format for use at a later stage. This is because a Format
|
139
|
-
# is applied to a cell not in its current state but in its final state.
|
140
|
-
# Consider the following example:
|
141
|
-
#
|
142
|
-
# format = workbook.add_format
|
143
|
-
# format.set_bold
|
144
|
-
# format.set_color( 'red' )
|
145
|
-
# worksheet.write( 'A1', 'Cell A1', format )
|
146
|
-
# format.set_color( 'green' )
|
147
|
-
# worksheet.write( 'B1', 'Cell B1', format )
|
148
|
-
#
|
149
|
-
# Cell A1 is assigned the Format format which is initially set to the colour
|
150
|
-
# red. However, the colour is subsequently set to green. When Excel displays
|
151
|
-
# Cell A1 it will display the final state of the Format which in this case
|
152
|
-
# will be the colour green.
|
153
|
-
#
|
154
|
-
# In general a method call without an argument will turn a property on,
|
155
|
-
# for example:
|
156
|
-
#
|
157
|
-
# format1 = workbook.add_format
|
158
|
-
# format1.set_bold # Turns bold on
|
159
|
-
# format1.set_bold( 1 ) # Also turns bold on
|
160
|
-
# format1.set_bold( 0 ) # Turns bold off
|
161
|
-
#
|
162
5
|
class Format
|
163
6
|
include Writexlsx::Utility
|
164
7
|
|
165
|
-
attr_reader :xf_index, :dxf_index, :num_format
|
8
|
+
attr_reader :xf_index, :dxf_index, :num_format # :nodoc:
|
166
9
|
attr_reader :underline, :font_script, :size, :theme, :font, :font_family, :hyperlink, :xf_id # :nodoc:
|
167
|
-
attr_reader :diag_type, :diag_color, :font_only, :color, :color_indexed
|
168
|
-
attr_reader :left, :left_color, :right, :right_color, :top, :top_color, :bottom, :bottom_color
|
169
|
-
attr_reader :font_scheme
|
170
|
-
attr_accessor :num_format_index, :border_index, :font_index
|
171
|
-
attr_accessor :fill_index, :font_condense, :font_extend, :diag_border
|
172
|
-
attr_accessor :bg_color, :fg_color, :pattern
|
10
|
+
attr_reader :diag_type, :diag_color, :font_only, :color, :color_indexed # :nodoc:
|
11
|
+
attr_reader :left, :left_color, :right, :right_color, :top, :top_color, :bottom, :bottom_color # :nodoc:
|
12
|
+
attr_reader :font_scheme # :nodoc:
|
13
|
+
attr_accessor :num_format_index, :border_index, :font_index # :nodoc:
|
14
|
+
attr_accessor :fill_index, :font_condense, :font_extend, :diag_border # :nodoc:
|
15
|
+
attr_accessor :bg_color, :fg_color, :pattern # :nodoc:
|
173
16
|
|
174
|
-
attr_accessor :dxf_bg_color, :dxf_fg_color
|
175
|
-
attr_reader :rotation, :bold, :italic, :font_strikeout
|
17
|
+
attr_accessor :dxf_bg_color, :dxf_fg_color # :nodoc:
|
18
|
+
attr_reader :rotation, :bold, :italic, :font_strikeout # :nodoc:
|
176
19
|
|
177
20
|
def initialize(formats, params = {}) # :nodoc:
|
178
21
|
@formats = formats
|
@@ -268,17 +111,6 @@ module Writexlsx
|
|
268
111
|
#
|
269
112
|
# Convert hashes of properties to method calls.
|
270
113
|
#
|
271
|
-
# The properties of an existing Format object can be also be set by means
|
272
|
-
# of set_format_properties():
|
273
|
-
#
|
274
|
-
# format = workbook.add_format
|
275
|
-
# format.set_format_properties(:bold => 1, :color => 'red');
|
276
|
-
#
|
277
|
-
# However, this method is here mainly for legacy reasons. It is preferable
|
278
|
-
# to set the properties in the format constructor:
|
279
|
-
#
|
280
|
-
# format = workbook.add_format(:bold => 1, :color => 'red');
|
281
|
-
#
|
282
114
|
def set_format_properties(*properties) # :nodoc:
|
283
115
|
return if properties.empty?
|
284
116
|
properties.each do |property|
|
@@ -747,7 +579,7 @@ module Writexlsx
|
|
747
579
|
writer.empty_tag('sz', [ ['val', size] ]) unless dxf_format
|
748
580
|
|
749
581
|
if theme == -1
|
750
|
-
|
582
|
+
# Ignore for excel2003_style
|
751
583
|
elsif ptrue?(theme)
|
752
584
|
write_color(writer, 'theme', theme)
|
753
585
|
elsif ptrue?(@color_indexed)
|
@@ -845,7 +677,7 @@ module Writexlsx
|
|
845
677
|
|
846
678
|
def write_font_family_scheme(writer)
|
847
679
|
if ptrue?(@font_family)
|
848
|
-
|
680
|
+
writer.empty_tag('family', [ ['val', @font_family] ])
|
849
681
|
end
|
850
682
|
|
851
683
|
if ptrue?(@font_charset)
|
@@ -105,8 +105,8 @@ module Writexlsx
|
|
105
105
|
|
106
106
|
schema = 'http://schemas.openxmlformats.org/officeDocument/2006/'
|
107
107
|
attributes = [
|
108
|
-
|
109
|
-
|
108
|
+
['xmlns', "#{schema}extended-properties"],
|
109
|
+
['xmlns:vt', "#{schema}docPropsVTypes"]
|
110
110
|
]
|
111
111
|
|
112
112
|
@writer.tag_elements('Properties', attributes) { yield }
|
@@ -50,8 +50,8 @@ module Writexlsx
|
|
50
50
|
# attributes for <v:fill> element.
|
51
51
|
def fill_attributes
|
52
52
|
[
|
53
|
-
|
54
|
-
|
53
|
+
['color2', 'buttonFace [67]'],
|
54
|
+
['o:detectmouseclick', 't']
|
55
55
|
]
|
56
56
|
end
|
57
57
|
|
@@ -60,9 +60,9 @@ module Writexlsx
|
|
60
60
|
#
|
61
61
|
def write_rotation_lock
|
62
62
|
attributes = [
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
['v:ext', 'edit'],
|
64
|
+
['rotation', 't']
|
65
|
+
]
|
66
66
|
@writer.empty_tag('o:lock', attributes)
|
67
67
|
end
|
68
68
|
|
@@ -71,9 +71,9 @@ module Writexlsx
|
|
71
71
|
#
|
72
72
|
def write_textbox
|
73
73
|
attributes = [
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
['style', 'mso-direction-alt:auto'],
|
75
|
+
['o:singleclick', 'f']
|
76
|
+
]
|
77
77
|
|
78
78
|
@writer.tag_elements('v:textbox', attributes) do
|
79
79
|
# Write the div element.
|