write_xlsx 0.0.2 → 0.0.3
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.
- data/README.rdoc +3 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/formats.rb +498 -0
- data/lib/write_xlsx/chart.rb +15 -15
- data/lib/write_xlsx/chartsheet.rb +1 -1
- data/lib/write_xlsx/format.rb +10 -3
- data/lib/write_xlsx/package/comments.rb +171 -27
- data/lib/write_xlsx/package/packager.rb +8 -17
- data/lib/write_xlsx/package/shared_strings.rb +36 -15
- data/lib/write_xlsx/package/styles.rb +2 -12
- data/lib/write_xlsx/package/vml.rb +14 -22
- data/lib/write_xlsx/utility.rb +53 -4
- data/lib/write_xlsx/workbook.rb +21 -37
- data/lib/write_xlsx/worksheet.rb +533 -765
- data/test/helper.rb +10 -3
- data/test/package/comments/test_write_text_t.rb +1 -1
- data/test/package/shared_strings/test_shared_strings01.rb +3 -3
- data/test/package/shared_strings/test_shared_strings02.rb +3 -3
- data/test/package/shared_strings/test_write_sst.rb +3 -2
- data/test/package/vml/test_write_anchor.rb +1 -1
- data/test/package/vml/test_write_auto_fill.rb +1 -1
- data/test/package/vml/test_write_column.rb +1 -1
- data/test/package/vml/test_write_div.rb +1 -1
- data/test/package/vml/test_write_fill.rb +1 -1
- data/test/package/vml/test_write_idmap.rb +1 -1
- data/test/package/vml/test_write_move_with_cells.rb +1 -1
- data/test/package/vml/test_write_path.rb +2 -2
- data/test/package/vml/test_write_row.rb +1 -1
- data/test/package/vml/test_write_shadow.rb +1 -1
- data/test/package/vml/test_write_shapelayout.rb +1 -1
- data/test/package/vml/test_write_shapetype.rb +1 -1
- data/test/package/vml/test_write_size_with_cells.rb +1 -1
- data/test/package/vml/test_write_stroke.rb +1 -1
- data/test/package/vml/test_write_textbox.rb +1 -1
- data/test/perl_output/formats.xlsx +0 -0
- data/test/perl_output/indent.xlsx +0 -0
- data/test/perl_output/merge4.xlsx +0 -0
- data/test/perl_output/merge5.xlsx +0 -0
- data/test/test_example_match.rb +482 -0
- data/test/worksheet/test_repeat_formula.rb +5 -5
- data/test/worksheet/test_write_cell.rb +10 -5
- data/test/worksheet/test_write_legacy_drawing.rb +1 -1
- data/write_xlsx.gemspec +5 -5
- metadata +15 -15
- data/test/package/comments/test_comments01.rb +0 -36
- data/test/package/vml/test_vml_01.rb +0 -42
data/test/test_example_match.rb
CHANGED
@@ -925,6 +925,488 @@ class TestExampleMatch < Test::Unit::TestCase
|
|
925
925
|
compare_xlsx(@expected_dir, @result_dir, xlsx)
|
926
926
|
end
|
927
927
|
|
928
|
+
def test_formats
|
929
|
+
xlsx = 'formats.xlsx'
|
930
|
+
workbook = WriteXLSX.new(xlsx)
|
931
|
+
|
932
|
+
# Some common formats
|
933
|
+
center = workbook.add_format(:align => 'center')
|
934
|
+
heading = workbook.add_format(:align => 'center', :bold => 1)
|
935
|
+
|
936
|
+
# The named colors
|
937
|
+
colors = {
|
938
|
+
0x08 => 'black',
|
939
|
+
0x0C => 'blue',
|
940
|
+
0x10 => 'brown',
|
941
|
+
0x0F => 'cyan',
|
942
|
+
0x17 => 'gray',
|
943
|
+
0x11 => 'green',
|
944
|
+
0x0B => 'lime',
|
945
|
+
0x0E => 'magenta',
|
946
|
+
0x12 => 'navy',
|
947
|
+
0x35 => 'orange',
|
948
|
+
0x21 => 'pink',
|
949
|
+
0x14 => 'purple',
|
950
|
+
0x0A => 'red',
|
951
|
+
0x16 => 'silver',
|
952
|
+
0x09 => 'white',
|
953
|
+
0x0D => 'yellow'
|
954
|
+
}
|
955
|
+
|
956
|
+
######################################################################
|
957
|
+
#
|
958
|
+
# Intro.
|
959
|
+
#
|
960
|
+
def intro(workbook, center, heading, colors)
|
961
|
+
worksheet = workbook.add_worksheet('Introduction')
|
962
|
+
|
963
|
+
worksheet.set_column(0, 0, 60)
|
964
|
+
|
965
|
+
format = workbook.add_format
|
966
|
+
format.set_bold
|
967
|
+
format.set_size(14)
|
968
|
+
format.set_color('blue')
|
969
|
+
format.set_align('center')
|
970
|
+
|
971
|
+
format2 = workbook.add_format
|
972
|
+
format2.set_bold
|
973
|
+
format2.set_color('blue')
|
974
|
+
|
975
|
+
format3 = workbook.add_format(
|
976
|
+
:color => 'blue',
|
977
|
+
:underline => 1
|
978
|
+
)
|
979
|
+
|
980
|
+
worksheet.write(2, 0, 'This workbook demonstrates some of', format)
|
981
|
+
worksheet.write(3, 0, 'the formatting options provided by', format)
|
982
|
+
worksheet.write(4, 0, 'the Excel::Writer::XLSX module.', format)
|
983
|
+
worksheet.write('A7', 'Sections:', format2)
|
984
|
+
|
985
|
+
worksheet.write('A8', "internal:Fonts!A1", 'Fonts', format3)
|
986
|
+
|
987
|
+
worksheet.write('A9', "internal:'Named colors'!A1",
|
988
|
+
'Named colors', format3)
|
989
|
+
|
990
|
+
worksheet.write(
|
991
|
+
'A10',
|
992
|
+
"internal:'Standard colors'!A1",
|
993
|
+
'Standard colors', format3
|
994
|
+
)
|
995
|
+
|
996
|
+
worksheet.write(
|
997
|
+
'A11',
|
998
|
+
"internal:'Numeric formats'!A1",
|
999
|
+
'Numeric formats', format3
|
1000
|
+
)
|
1001
|
+
|
1002
|
+
worksheet.write('A12', "internal:Borders!A1", 'Borders', format3)
|
1003
|
+
worksheet.write('A13', "internal:Patterns!A1", 'Patterns', format3)
|
1004
|
+
worksheet.write('A14', "internal:Alignment!A1", 'Alignment', format3)
|
1005
|
+
worksheet.write('A15', "internal:Miscellaneous!A1", 'Miscellaneous',
|
1006
|
+
format3)
|
1007
|
+
|
1008
|
+
end
|
1009
|
+
|
1010
|
+
######################################################################
|
1011
|
+
#
|
1012
|
+
# Demonstrate the named colors.
|
1013
|
+
#
|
1014
|
+
def named_colors(workbook, center, heading, colors)
|
1015
|
+
|
1016
|
+
worksheet = workbook.add_worksheet('Named colors')
|
1017
|
+
|
1018
|
+
worksheet.set_column(0, 3, 15)
|
1019
|
+
|
1020
|
+
worksheet.write(0, 0, "Index", heading)
|
1021
|
+
worksheet.write(0, 1, "Index", heading)
|
1022
|
+
worksheet.write(0, 2, "Name", heading)
|
1023
|
+
worksheet.write(0, 3, "Color", heading)
|
1024
|
+
|
1025
|
+
i = 1
|
1026
|
+
|
1027
|
+
[33, 11, 53, 17, 22, 18, 13, 16, 23, 9, 12, 15, 14, 20, 8, 10].each do |index|
|
1028
|
+
color = colors[index]
|
1029
|
+
format = workbook.add_format(
|
1030
|
+
:bg_color => color,
|
1031
|
+
:pattern => 1,
|
1032
|
+
:border => 1
|
1033
|
+
)
|
1034
|
+
|
1035
|
+
worksheet.write(i + 1, 0, index, center)
|
1036
|
+
worksheet.write(i + 1, 1, sprintf("0x%02X", index), center)
|
1037
|
+
worksheet.write(i + 1, 2, color, center)
|
1038
|
+
worksheet.write(i + 1, 3, '', format)
|
1039
|
+
i += 1
|
1040
|
+
end
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
######################################################################
|
1044
|
+
#
|
1045
|
+
# Demonstrate the standard Excel colors in the range 8..63.
|
1046
|
+
#
|
1047
|
+
def standard_colors(workbook, center, heading, colors)
|
1048
|
+
|
1049
|
+
worksheet = workbook.add_worksheet('Standard colors')
|
1050
|
+
|
1051
|
+
worksheet.set_column(0, 3, 15)
|
1052
|
+
|
1053
|
+
worksheet.write(0, 0, "Index", heading)
|
1054
|
+
worksheet.write(0, 1, "Index", heading)
|
1055
|
+
worksheet.write(0, 2, "Color", heading)
|
1056
|
+
worksheet.write(0, 3, "Name", heading)
|
1057
|
+
|
1058
|
+
(8 .. 63).each do |i|
|
1059
|
+
format = workbook.add_format(
|
1060
|
+
:bg_color => i,
|
1061
|
+
:pattern => 1,
|
1062
|
+
:border => 1
|
1063
|
+
)
|
1064
|
+
|
1065
|
+
worksheet.write((i - 7), 0, i, center)
|
1066
|
+
worksheet.write((i - 7), 1, sprintf("0x%02X", i), center)
|
1067
|
+
worksheet.write((i - 7), 2, '', format)
|
1068
|
+
|
1069
|
+
# Add the color names
|
1070
|
+
if colors[i]
|
1071
|
+
worksheet.write((i - 7), 3, colors[i], center)
|
1072
|
+
end
|
1073
|
+
end
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
######################################################################
|
1077
|
+
#
|
1078
|
+
# Demonstrate the standard numeric formats.
|
1079
|
+
#
|
1080
|
+
def numeric_formats(workbook, center, heading, colors)
|
1081
|
+
|
1082
|
+
worksheet = workbook.add_worksheet('Numeric formats')
|
1083
|
+
|
1084
|
+
worksheet.set_column(0, 4, 15)
|
1085
|
+
worksheet.set_column(5, 5, 45)
|
1086
|
+
|
1087
|
+
worksheet.write(0, 0, "Index", heading)
|
1088
|
+
worksheet.write(0, 1, "Index", heading)
|
1089
|
+
worksheet.write(0, 2, "Unformatted", heading)
|
1090
|
+
worksheet.write(0, 3, "Formatted", heading)
|
1091
|
+
worksheet.write(0, 4, "Negative", heading)
|
1092
|
+
worksheet.write(0, 5, "Format", heading)
|
1093
|
+
|
1094
|
+
formats = []
|
1095
|
+
formats << [ 0x00, 1234.567, 0, 'General' ]
|
1096
|
+
formats << [ 0x01, 1234.567, 0, '0' ]
|
1097
|
+
formats << [ 0x02, 1234.567, 0, '0.00' ]
|
1098
|
+
formats << [ 0x03, 1234.567, 0, '#,##0' ]
|
1099
|
+
formats << [ 0x04, 1234.567, 0, '#,##0.00' ]
|
1100
|
+
formats << [ 0x05, 1234.567, -1234.567, '($#,##0_);($#,##0)' ]
|
1101
|
+
formats << [ 0x06, 1234.567, -1234.567, '($#,##0_);[Red]($#,##0)' ]
|
1102
|
+
formats << [ 0x07, 1234.567, -1234.567, '($#,##0.00_);($#,##0.00)' ]
|
1103
|
+
formats << [ 0x08, 1234.567, -1234.567, '($#,##0.00_);[Red]($#,##0.00)' ]
|
1104
|
+
formats << [ 0x09, 0.567, 0, '0%' ]
|
1105
|
+
formats << [ 0x0a, 0.567, 0, '0.00%' ]
|
1106
|
+
formats << [ 0x0b, 1234.567, 0, '0.00E+00' ]
|
1107
|
+
formats << [ 0x0c, 0.75, 0, '# ?/?' ]
|
1108
|
+
formats << [ 0x0d, 0.3125, 0, '# ??/??' ]
|
1109
|
+
formats << [ 0x0e, 36892.521, 0, 'm/d/yy' ]
|
1110
|
+
formats << [ 0x0f, 36892.521, 0, 'd-mmm-yy' ]
|
1111
|
+
formats << [ 0x10, 36892.521, 0, 'd-mmm' ]
|
1112
|
+
formats << [ 0x11, 36892.521, 0, 'mmm-yy' ]
|
1113
|
+
formats << [ 0x12, 36892.521, 0, 'h:mm AM/PM' ]
|
1114
|
+
formats << [ 0x13, 36892.521, 0, 'h:mm:ss AM/PM' ]
|
1115
|
+
formats << [ 0x14, 36892.521, 0, 'h:mm' ]
|
1116
|
+
formats << [ 0x15, 36892.521, 0, 'h:mm:ss' ]
|
1117
|
+
formats << [ 0x16, 36892.521, 0, 'm/d/yy h:mm' ]
|
1118
|
+
formats << [ 0x25, 1234.567, -1234.567, '(#,##0_);(#,##0)' ]
|
1119
|
+
formats << [ 0x26, 1234.567, -1234.567, '(#,##0_);[Red](#,##0)' ]
|
1120
|
+
formats << [ 0x27, 1234.567, -1234.567, '(#,##0.00_);(#,##0.00)' ]
|
1121
|
+
formats << [ 0x28, 1234.567, -1234.567, '(#,##0.00_);[Red](#,##0.00)' ]
|
1122
|
+
formats << [ 0x29, 1234.567, -1234.567, '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)' ]
|
1123
|
+
formats << [ 0x2a, 1234.567, -1234.567, '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)' ]
|
1124
|
+
formats << [ 0x2b, 1234.567, -1234.567, '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)' ]
|
1125
|
+
formats << [ 0x2c, 1234.567, -1234.567, '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)' ]
|
1126
|
+
formats << [ 0x2d, 36892.521, 0, 'mm:ss' ]
|
1127
|
+
formats << [ 0x2e, 3.0153, 0, '[h]:mm:ss' ]
|
1128
|
+
formats << [ 0x2f, 36892.521, 0, 'mm:ss.0' ]
|
1129
|
+
formats << [ 0x30, 1234.567, 0, '##0.0E+0' ]
|
1130
|
+
formats << [ 0x31, 1234.567, 0, '@' ]
|
1131
|
+
|
1132
|
+
i = 0
|
1133
|
+
formats.each do |format|
|
1134
|
+
style = workbook.add_format
|
1135
|
+
style.set_num_format(format[0])
|
1136
|
+
|
1137
|
+
i += 1
|
1138
|
+
worksheet.write(i, 0, format[0], center)
|
1139
|
+
worksheet.write(i, 1, sprintf("0x%02X", format[0]), center)
|
1140
|
+
worksheet.write(i, 2, format[1], center)
|
1141
|
+
worksheet.write(i, 3, format[1], style)
|
1142
|
+
|
1143
|
+
if format[2] != 0
|
1144
|
+
worksheet.write(i, 4, format[2], style)
|
1145
|
+
end
|
1146
|
+
|
1147
|
+
worksheet.write_string(i, 5, format[3])
|
1148
|
+
end
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
######################################################################
|
1152
|
+
#
|
1153
|
+
# Demonstrate the font options.
|
1154
|
+
#
|
1155
|
+
def fonts(workbook, center, heading, colors)
|
1156
|
+
|
1157
|
+
worksheet = workbook.add_worksheet('Fonts')
|
1158
|
+
|
1159
|
+
worksheet.set_column(0, 0, 30)
|
1160
|
+
worksheet.set_column(1, 1, 10)
|
1161
|
+
|
1162
|
+
worksheet.write(0, 0, "Font name", heading)
|
1163
|
+
worksheet.write(0, 1, "Font size", heading)
|
1164
|
+
|
1165
|
+
fonts = []
|
1166
|
+
fonts << [ 10, 'Arial' ]
|
1167
|
+
fonts << [ 12, 'Arial' ]
|
1168
|
+
fonts << [ 14, 'Arial' ]
|
1169
|
+
fonts << [ 12, 'Arial Black' ]
|
1170
|
+
fonts << [ 12, 'Arial Narrow' ]
|
1171
|
+
fonts << [ 12, 'Century Schoolbook' ]
|
1172
|
+
fonts << [ 12, 'Courier' ]
|
1173
|
+
fonts << [ 12, 'Courier New' ]
|
1174
|
+
fonts << [ 12, 'Garamond' ]
|
1175
|
+
fonts << [ 12, 'Impact' ]
|
1176
|
+
fonts << [ 12, 'Lucida Handwriting' ]
|
1177
|
+
fonts << [ 12, 'Times New Roman' ]
|
1178
|
+
fonts << [ 12, 'Symbol' ]
|
1179
|
+
fonts << [ 12, 'Wingdings' ]
|
1180
|
+
fonts << [ 12, 'A font that doesn\'t exist' ]
|
1181
|
+
|
1182
|
+
i = 0
|
1183
|
+
fonts.each do |font|
|
1184
|
+
format = workbook.add_format
|
1185
|
+
|
1186
|
+
format.set_size(font[0])
|
1187
|
+
format.set_font(font[1])
|
1188
|
+
|
1189
|
+
i += 1
|
1190
|
+
worksheet.write(i, 0, font[1], format)
|
1191
|
+
worksheet.write(i, 1, font[0], format)
|
1192
|
+
end
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
######################################################################
|
1196
|
+
#
|
1197
|
+
# Demonstrate the standard Excel border styles.
|
1198
|
+
#
|
1199
|
+
def borders(workbook, center, heading, colors)
|
1200
|
+
worksheet = workbook.add_worksheet('Borders')
|
1201
|
+
|
1202
|
+
worksheet.set_column(0, 4, 10)
|
1203
|
+
worksheet.set_column(5, 5, 40)
|
1204
|
+
|
1205
|
+
worksheet.write(0, 0, "Index", heading)
|
1206
|
+
worksheet.write(0, 1, "Index", heading)
|
1207
|
+
worksheet.write(0, 3, "Style", heading)
|
1208
|
+
worksheet.write(0, 5, "The style is highlighted in red for ", heading)
|
1209
|
+
worksheet.write(1, 5, "emphasis, the default color is black.",
|
1210
|
+
heading)
|
1211
|
+
|
1212
|
+
(0 .. 13).each do |i|
|
1213
|
+
|
1214
|
+
format = workbook.add_format
|
1215
|
+
format.set_border(i)
|
1216
|
+
format.set_border_color('red')
|
1217
|
+
format.set_align('center')
|
1218
|
+
|
1219
|
+
worksheet.write((2 * (i + 1)), 0, i, center)
|
1220
|
+
worksheet.write((2 * (i + 1)),
|
1221
|
+
1, sprintf("0x%02X", i), center)
|
1222
|
+
|
1223
|
+
worksheet.write((2 * (i + 1)), 3, "Border", format)
|
1224
|
+
end
|
1225
|
+
|
1226
|
+
worksheet.write(30, 0, "Diag type", heading)
|
1227
|
+
worksheet.write(30, 1, "Index", heading)
|
1228
|
+
worksheet.write(30, 3, "Style", heading)
|
1229
|
+
worksheet.write(30, 5, "Diagonal Boder styles", heading)
|
1230
|
+
|
1231
|
+
(1 .. 3).each do |i|
|
1232
|
+
format = workbook.add_format
|
1233
|
+
format.set_diag_type(i)
|
1234
|
+
format.set_diag_border(1)
|
1235
|
+
format.set_diag_color('red')
|
1236
|
+
format.set_align('center')
|
1237
|
+
|
1238
|
+
worksheet.write((2 * (i + 15)), 0, i, center)
|
1239
|
+
worksheet.write((2 * (i + 15)),
|
1240
|
+
1, sprintf("0x%02X", i), center)
|
1241
|
+
|
1242
|
+
worksheet.write((2 * (i + 15)), 3, "Border", format)
|
1243
|
+
end
|
1244
|
+
end
|
1245
|
+
|
1246
|
+
######################################################################
|
1247
|
+
#
|
1248
|
+
# Demonstrate the standard Excel cell patterns.
|
1249
|
+
#
|
1250
|
+
def patterns(workbook, center, heading, colors)
|
1251
|
+
worksheet = workbook.add_worksheet('Patterns')
|
1252
|
+
|
1253
|
+
worksheet.set_column(0, 4, 10)
|
1254
|
+
worksheet.set_column(5, 5, 50)
|
1255
|
+
|
1256
|
+
worksheet.write(0, 0, "Index", heading)
|
1257
|
+
worksheet.write(0, 1, "Index", heading)
|
1258
|
+
worksheet.write(0, 3, "Pattern", heading)
|
1259
|
+
|
1260
|
+
worksheet.write(0, 5, "The background colour has been set to silver.",
|
1261
|
+
heading)
|
1262
|
+
worksheet.write(1, 5, "The foreground colour has been set to green.",
|
1263
|
+
heading)
|
1264
|
+
|
1265
|
+
(0 .. 18).each do |i|
|
1266
|
+
format = workbook.add_format
|
1267
|
+
|
1268
|
+
format.set_pattern(i)
|
1269
|
+
format.set_bg_color('silver')
|
1270
|
+
format.set_fg_color('green')
|
1271
|
+
format.set_align('center')
|
1272
|
+
|
1273
|
+
worksheet.write((2 * (i + 1)), 0, i, center)
|
1274
|
+
worksheet.write((2 * (i + 1)),
|
1275
|
+
1, sprintf("0x%02X", i), center)
|
1276
|
+
|
1277
|
+
worksheet.write((2 * (i + 1)), 3, "Pattern", format)
|
1278
|
+
|
1279
|
+
if i == 1
|
1280
|
+
worksheet.write((2 * (i + 1)),
|
1281
|
+
5, "This is solid colour, the most useful pattern.", heading)
|
1282
|
+
end
|
1283
|
+
end
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
######################################################################
|
1287
|
+
#
|
1288
|
+
# Demonstrate the standard Excel cell alignments.
|
1289
|
+
#
|
1290
|
+
def alignment(workbook, center, heading, colors)
|
1291
|
+
worksheet = workbook.add_worksheet('Alignment')
|
1292
|
+
|
1293
|
+
worksheet.set_column(0, 7, 12)
|
1294
|
+
worksheet.set_row(0, 40)
|
1295
|
+
worksheet.set_selection(7, 0)
|
1296
|
+
|
1297
|
+
format01 = workbook.add_format
|
1298
|
+
format02 = workbook.add_format
|
1299
|
+
format03 = workbook.add_format
|
1300
|
+
format04 = workbook.add_format
|
1301
|
+
format05 = workbook.add_format
|
1302
|
+
format06 = workbook.add_format
|
1303
|
+
format07 = workbook.add_format
|
1304
|
+
format08 = workbook.add_format
|
1305
|
+
format09 = workbook.add_format
|
1306
|
+
format10 = workbook.add_format
|
1307
|
+
format11 = workbook.add_format
|
1308
|
+
format12 = workbook.add_format
|
1309
|
+
format13 = workbook.add_format
|
1310
|
+
format14 = workbook.add_format
|
1311
|
+
format15 = workbook.add_format
|
1312
|
+
format16 = workbook.add_format
|
1313
|
+
format17 = workbook.add_format
|
1314
|
+
|
1315
|
+
format02.set_align('top')
|
1316
|
+
format03.set_align('bottom')
|
1317
|
+
format04.set_align('vcenter')
|
1318
|
+
format05.set_align('vjustify')
|
1319
|
+
format06.set_text_wrap
|
1320
|
+
|
1321
|
+
format07.set_align('left')
|
1322
|
+
format08.set_align('right')
|
1323
|
+
format09.set_align('center')
|
1324
|
+
format10.set_align('fill')
|
1325
|
+
format11.set_align('justify')
|
1326
|
+
format12.set_merge
|
1327
|
+
|
1328
|
+
format13.set_rotation(45)
|
1329
|
+
format14.set_rotation(-45)
|
1330
|
+
format15.set_rotation(270)
|
1331
|
+
|
1332
|
+
format16.set_shrink
|
1333
|
+
format17.set_indent(1)
|
1334
|
+
|
1335
|
+
worksheet.write(0, 0, 'Vertical', heading)
|
1336
|
+
worksheet.write(0, 1, 'top', format02)
|
1337
|
+
worksheet.write(0, 2, 'bottom', format03)
|
1338
|
+
worksheet.write(0, 3, 'vcenter', format04)
|
1339
|
+
worksheet.write(0, 4, 'vjustify', format05)
|
1340
|
+
worksheet.write(0, 5, "text\nwrap", format06)
|
1341
|
+
|
1342
|
+
worksheet.write(2, 0, 'Horizontal', heading)
|
1343
|
+
worksheet.write(2, 1, 'left', format07)
|
1344
|
+
worksheet.write(2, 2, 'right', format08)
|
1345
|
+
worksheet.write(2, 3, 'center', format09)
|
1346
|
+
worksheet.write(2, 4, 'fill', format10)
|
1347
|
+
worksheet.write(2, 5, 'justify', format11)
|
1348
|
+
|
1349
|
+
worksheet.write(3, 1, 'merge', format12)
|
1350
|
+
worksheet.write(3, 2, '', format12)
|
1351
|
+
|
1352
|
+
worksheet.write(3, 3, 'Shrink ' * 3, format16)
|
1353
|
+
worksheet.write(3, 4, 'Indent', format17)
|
1354
|
+
|
1355
|
+
|
1356
|
+
worksheet.write(5, 0, 'Rotation', heading)
|
1357
|
+
worksheet.write(5, 1, 'Rotate 45', format13)
|
1358
|
+
worksheet.write(6, 1, 'Rotate -45', format14)
|
1359
|
+
worksheet.write(7, 1, 'Rotate 270', format15)
|
1360
|
+
end
|
1361
|
+
|
1362
|
+
######################################################################
|
1363
|
+
#
|
1364
|
+
# Demonstrate other miscellaneous features.
|
1365
|
+
#
|
1366
|
+
def misc(workbook, center, heading, colors)
|
1367
|
+
worksheet = workbook.add_worksheet('Miscellaneous')
|
1368
|
+
|
1369
|
+
worksheet.set_column(2, 2, 25)
|
1370
|
+
|
1371
|
+
format01 = workbook.add_format
|
1372
|
+
format02 = workbook.add_format
|
1373
|
+
format03 = workbook.add_format
|
1374
|
+
format04 = workbook.add_format
|
1375
|
+
format05 = workbook.add_format
|
1376
|
+
format06 = workbook.add_format
|
1377
|
+
format07 = workbook.add_format
|
1378
|
+
|
1379
|
+
format01.set_underline(0x01)
|
1380
|
+
format02.set_underline(0x02)
|
1381
|
+
format03.set_underline(0x21)
|
1382
|
+
format04.set_underline(0x22)
|
1383
|
+
format05.set_font_strikeout
|
1384
|
+
format06.set_font_outline
|
1385
|
+
format07.set_font_shadow
|
1386
|
+
|
1387
|
+
worksheet.write(1, 2, 'Underline 0x01', format01)
|
1388
|
+
worksheet.write(3, 2, 'Underline 0x02', format02)
|
1389
|
+
worksheet.write(5, 2, 'Underline 0x21', format03)
|
1390
|
+
worksheet.write(7, 2, 'Underline 0x22', format04)
|
1391
|
+
worksheet.write(9, 2, 'Strikeout', format05)
|
1392
|
+
worksheet.write(11, 2, 'Outline (Macintosh only)', format06)
|
1393
|
+
worksheet.write(13, 2, 'Shadow (Macintosh only)', format07)
|
1394
|
+
end
|
1395
|
+
|
1396
|
+
# Call these subroutines to demonstrate different formatting options
|
1397
|
+
intro(workbook, center, heading, colors)
|
1398
|
+
fonts(workbook, center, heading, colors)
|
1399
|
+
named_colors(workbook, center, heading, colors)
|
1400
|
+
standard_colors(workbook, center, heading, colors)
|
1401
|
+
numeric_formats(workbook, center, heading, colors)
|
1402
|
+
borders(workbook, center, heading, colors)
|
1403
|
+
patterns(workbook, center, heading, colors)
|
1404
|
+
alignment(workbook, center, heading, colors)
|
1405
|
+
misc(workbook, center, heading, colors)
|
1406
|
+
workbook.close
|
1407
|
+
compare_xlsx(@expected_dir, @result_dir, xlsx)
|
1408
|
+
end
|
1409
|
+
|
928
1410
|
def test_headers
|
929
1411
|
xlsx = 'headers.xlsx'
|
930
1412
|
workbook = WriteXLSX.new(xlsx)
|
@@ -17,7 +17,7 @@ class TestRepeatFormula < Test::Unit::TestCase
|
|
17
17
|
col = 0
|
18
18
|
formula = @worksheet.store_formula('=SUM(A1:A10)')
|
19
19
|
@worksheet.repeat_formula(row, col, formula, format)
|
20
|
-
result = @worksheet.instance_variable_get(:@
|
20
|
+
result = @worksheet.instance_variable_get(:@cell_data_table)[row][col].token
|
21
21
|
assert_equal(expected, result)
|
22
22
|
|
23
23
|
expected = 'SUM(A2:A10)'
|
@@ -25,7 +25,7 @@ class TestRepeatFormula < Test::Unit::TestCase
|
|
25
25
|
col = 0
|
26
26
|
formula = @worksheet.store_formula('=SUM(A1:A10)')
|
27
27
|
@worksheet.repeat_formula(row, col, formula, format, 'A1', 'A2')
|
28
|
-
result = @worksheet.instance_variable_get(:@
|
28
|
+
result = @worksheet.instance_variable_get(:@cell_data_table)[row][col].token
|
29
29
|
assert_equal(expected, result)
|
30
30
|
|
31
31
|
expected = 'SUM(A2:A10)'
|
@@ -33,7 +33,7 @@ class TestRepeatFormula < Test::Unit::TestCase
|
|
33
33
|
col = 0
|
34
34
|
formula = @worksheet.store_formula('=SUM(A1:A10)')
|
35
35
|
@worksheet.repeat_formula(row, col, formula, format, /^A1$/, 'A2')
|
36
|
-
result = @worksheet.instance_variable_get(:@
|
36
|
+
result = @worksheet.instance_variable_get(:@cell_data_table)[row][col].token
|
37
37
|
assert_equal(expected, result)
|
38
38
|
|
39
39
|
expected = 'A2+A2'
|
@@ -41,7 +41,7 @@ class TestRepeatFormula < Test::Unit::TestCase
|
|
41
41
|
col = 0
|
42
42
|
formula = @worksheet.store_formula('A1+A1')
|
43
43
|
@worksheet.repeat_formula(row, col, formula, format, 'A1', 'A2', 'A1', 'A2')
|
44
|
-
result = @worksheet.instance_variable_get(:@
|
44
|
+
result = @worksheet.instance_variable_get(:@cell_data_table)[row][col].token
|
45
45
|
assert_equal(expected, result)
|
46
46
|
|
47
47
|
expected = 'A10 + SIN(A10)'
|
@@ -49,7 +49,7 @@ class TestRepeatFormula < Test::Unit::TestCase
|
|
49
49
|
col = 0
|
50
50
|
formula = @worksheet.store_formula('A1 + SIN(A1)')
|
51
51
|
@worksheet.repeat_formula(row, col, formula, format, /^A1$/, 'A10', /^A1$/, 'A10')
|
52
|
-
result = @worksheet.instance_variable_get(:@
|
52
|
+
result = @worksheet.instance_variable_get(:@cell_data_table)[row][col].token
|
53
53
|
assert_equal(expected, result)
|
54
54
|
end
|
55
55
|
end
|
@@ -10,14 +10,16 @@ class TestWriteCell < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_write_cell_0_0_n_1
|
13
|
-
|
13
|
+
cell_data = Writexlsx::Worksheet::NumberCellData.new(0, 0, 1, nil)
|
14
|
+
cell_data.write_cell(@worksheet)
|
14
15
|
result = @worksheet.instance_variable_get(:@writer).string
|
15
16
|
expected = '<c r="A1"><v>1</v></c>'
|
16
17
|
assert_equal(expected, result)
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_write_cell_3_1_s_0
|
20
|
-
|
21
|
+
cell_data = Writexlsx::Worksheet::StringCellData.new(3, 1, 0, nil)
|
22
|
+
cell_data.write_cell(@worksheet)
|
21
23
|
result = @worksheet.instance_variable_get(:@writer).string
|
22
24
|
expected = '<c r="B4" t="s"><v>0</v></c>'
|
23
25
|
assert_equal(expected, result)
|
@@ -25,7 +27,8 @@ class TestWriteCell < Test::Unit::TestCase
|
|
25
27
|
|
26
28
|
def test_write_cell_1_2_f_formula_nil_0
|
27
29
|
format = nil
|
28
|
-
|
30
|
+
cell_data = Writexlsx::Worksheet::FormulaCellData.new(1, 2, 'A3+A5', format, 0)
|
31
|
+
cell_data.write_cell(@worksheet)
|
29
32
|
result = @worksheet.instance_variable_get(:@writer).string
|
30
33
|
expected = '<c r="C2"><f>A3+A5</f><v>0</v></c>'
|
31
34
|
assert_equal(expected, result)
|
@@ -33,7 +36,8 @@ class TestWriteCell < Test::Unit::TestCase
|
|
33
36
|
|
34
37
|
def test_write_cell_1_2_f_formula
|
35
38
|
format = nil
|
36
|
-
|
39
|
+
cell_data = Writexlsx::Worksheet::FormulaCellData.new(1, 2, 'A3+A5', nil, nil)
|
40
|
+
cell_data.write_cell(@worksheet)
|
37
41
|
result = @worksheet.instance_variable_get(:@writer).string
|
38
42
|
expected = '<c r="C2"><f>A3+A5</f><v>0</v></c>'
|
39
43
|
assert_equal(expected, result)
|
@@ -41,7 +45,8 @@ class TestWriteCell < Test::Unit::TestCase
|
|
41
45
|
|
42
46
|
def test_write_cell_0_0_a_formula_nil_a1_9500
|
43
47
|
format = nil
|
44
|
-
|
48
|
+
cell_data = Writexlsx::Worksheet::FormulaArrayCellData.new(0, 0, 'SUM(B1:C1*B2:C2)', format, 'A1', 9500)
|
49
|
+
cell_data.write_cell(@worksheet)
|
45
50
|
result = @worksheet.instance_variable_get(:@writer).string
|
46
51
|
expected = '<c r="A1"><f t="array" ref="A1">SUM(B1:C1*B2:C2)</f><v>9500</v></c>'
|
47
52
|
assert_equal(expected, result)
|
@@ -10,7 +10,7 @@ class TestWriteLegacyDrawing < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_write_legacy_drawing
|
13
|
-
@worksheet.
|
13
|
+
@worksheet.write_comment('A1', 'comment')
|
14
14
|
@worksheet.__send__('write_legacy_drawing')
|
15
15
|
result = @worksheet.instance_variable_get(:@writer).string
|
16
16
|
expected = '<legacyDrawing r:id="rId1" />'
|
data/write_xlsx.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "write_xlsx"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Hideo NAKAMURA"]
|
12
|
-
s.date = "2012-01-
|
13
|
-
s.description = "write_xlsx s a gem to create a new file in the Excel 2007+ XLSX format, and you can use the same interface as writeexcel gem.\nThe WriteXLSX supports the following features:\n * Multiple worksheets\n * Strings and numbers\n * Unicode text\n * Rich string formats\n * Formulas (including array formats)\n * cell formatting\n * Embedded images\n * Charts\n * Autofilters\n * Data validation\n * Hyperlinks\n * Defined names\n * Grouping/Outlines\n * Cell comments\n * Panes\n * Page set-up and printing options\n\nwrite_xlsx uses the same interface as writeexcel gem.\n\ndocumentation is not completed, but writeexcel\u{2019}s documentation will help you. See writeexcel.web.fc2.com/\n\nAnd you can find many examples in this gem.\n"
|
12
|
+
s.date = "2012-01-25"
|
13
|
+
s.description = "write_xlsx s a gem to create a new file in the Excel 2007+ XLSX format, and you can use the same interface as writeexcel gem.\nThe WriteXLSX supports the following features:\n * Multiple worksheets\n * Strings and numbers\n * Unicode text\n * Rich string formats\n * Formulas (including array formats)\n * cell formatting\n * Embedded images\n * Charts\n * Autofilters\n * Data validation\n * Hyperlinks\n * Defined names\n * Grouping/Outlines\n * Cell comments\n * Panes\n * Page set-up and printing options\n\nwrite_xlsx uses the same interface as writeexcel gem.\n\ndocumentation is not completed, but writeexcel\u{2019}s documentation will help you. See http://writeexcel.web.fc2.com/\n\nAnd you can find many examples in this gem.\n"
|
14
14
|
s.email = "cxn03651@msj.biglobe.ne.jp"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
"examples/defined_name.rb",
|
43
43
|
"examples/demo.rb",
|
44
44
|
"examples/diag_border.rb",
|
45
|
+
"examples/formats.rb",
|
45
46
|
"examples/headers.rb",
|
46
47
|
"examples/hide_sheet.rb",
|
47
48
|
"examples/hyperlink1.rb",
|
@@ -128,7 +129,6 @@ Gem::Specification.new do |s|
|
|
128
129
|
"test/package/app/test_app01.rb",
|
129
130
|
"test/package/app/test_app02.rb",
|
130
131
|
"test/package/app/test_app03.rb",
|
131
|
-
"test/package/comments/test_comments01.rb",
|
132
132
|
"test/package/comments/test_write_text_t.rb",
|
133
133
|
"test/package/content_types/test_content_types.rb",
|
134
134
|
"test/package/content_types/test_write_default.rb",
|
@@ -150,7 +150,6 @@ Gem::Specification.new do |s|
|
|
150
150
|
"test/package/styles/test_styles_07.rb",
|
151
151
|
"test/package/styles/test_styles_08.rb",
|
152
152
|
"test/package/styles/test_styles_09.rb",
|
153
|
-
"test/package/vml/test_vml_01.rb",
|
154
153
|
"test/package/vml/test_write_anchor.rb",
|
155
154
|
"test/package/vml/test_write_auto_fill.rb",
|
156
155
|
"test/package/vml/test_write_column.rb",
|
@@ -184,6 +183,7 @@ Gem::Specification.new do |s|
|
|
184
183
|
"test/perl_output/demo.xlsx",
|
185
184
|
"test/perl_output/diag_border.xlsx",
|
186
185
|
"test/perl_output/fit_to_pages.xlsx",
|
186
|
+
"test/perl_output/formats.xlsx",
|
187
187
|
"test/perl_output/headers.xlsx",
|
188
188
|
"test/perl_output/hide_sheet.xlsx",
|
189
189
|
"test/perl_output/hyperlink.xlsx",
|