writeexcel 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +0 -0
- data/.gitattributes +0 -0
- data/README.rdoc +9 -35
- data/Rakefile +0 -0
- data/VERSION +1 -1
- data/charts/chartex.rb +0 -0
- data/charts/demo1.rb +0 -0
- data/charts/demo101.bin +0 -0
- data/charts/demo2.rb +0 -0
- data/charts/demo201.bin +0 -0
- data/charts/demo3.rb +0 -0
- data/charts/demo301.bin +0 -0
- data/charts/demo4.rb +0 -0
- data/charts/demo401.bin +0 -0
- data/charts/demo5.rb +0 -0
- data/charts/demo501.bin +0 -0
- data/examples/a_simple.rb +0 -0
- data/examples/autofilter.rb +0 -0
- data/examples/bigfile.rb +0 -0
- data/examples/chart_area.rb +0 -0
- data/examples/chart_bar.rb +0 -0
- data/examples/chart_column.rb +0 -0
- data/examples/chart_line.rb +0 -0
- data/examples/chart_pie.rb +0 -0
- data/examples/chart_scatter.rb +0 -0
- data/examples/chart_stock.rb +0 -0
- data/examples/chess.rb +0 -0
- data/examples/colors.rb +0 -0
- data/examples/comments1.rb +0 -0
- data/examples/comments2.rb +0 -0
- data/examples/copyformat.rb +0 -0
- data/examples/data_validate.rb +0 -0
- data/examples/date_time.rb +0 -0
- data/examples/defined_name.rb +0 -0
- data/examples/demo.rb +0 -0
- data/examples/diag_border.rb +0 -0
- data/examples/formats.rb +0 -0
- data/examples/formula_result.rb +0 -0
- data/examples/header.rb +0 -0
- data/examples/hide_sheet.rb +0 -0
- data/examples/hyperlink.rb +0 -0
- data/examples/images.rb +0 -0
- data/examples/indent.rb +0 -0
- data/examples/merge1.rb +0 -0
- data/examples/merge2.rb +0 -0
- data/examples/merge3.rb +0 -0
- data/examples/merge4.rb +0 -0
- data/examples/merge5.rb +0 -0
- data/examples/merge6.rb +0 -0
- data/examples/outline.rb +0 -0
- data/examples/outline_collapsed.rb +0 -0
- data/examples/panes.rb +0 -0
- data/examples/properties.rb +0 -0
- data/examples/properties_jp.rb +0 -0
- data/examples/protection.rb +0 -0
- data/examples/regions.rb +0 -0
- data/examples/repeat.rb +0 -0
- data/examples/republic.png +0 -0
- data/examples/right_to_left.rb +0 -0
- data/examples/row_wrap.rb +0 -0
- data/examples/set_first_sheet.rb +14 -0
- data/examples/stats.rb +0 -0
- data/examples/stocks.rb +0 -0
- data/examples/tab_colors.rb +0 -0
- data/examples/utf8.rb +0 -0
- data/examples/write_arrays.rb +0 -0
- data/html/en/doc_en.html +5941 -0
- data/html/images/a_simple.jpg +0 -0
- data/html/images/area1.jpg +0 -0
- data/html/images/bar1.jpg +0 -0
- data/html/images/chart_area.xls +0 -0
- data/html/images/column1.jpg +0 -0
- data/html/images/data_validation.jpg +0 -0
- data/html/images/line1.jpg +0 -0
- data/html/images/pie1.jpg +0 -0
- data/html/images/regions.jpg +0 -0
- data/html/images/scatter1.jpg +0 -0
- data/html/images/stats.jpg +0 -0
- data/html/images/stock1.jpg +0 -0
- data/html/images/stocks.jpg +0 -0
- data/html/index.html +16 -0
- data/html/style.css +433 -0
- data/lib/writeexcel/biffwriter.rb +5 -0
- data/lib/writeexcel/caller_info.rb +0 -0
- data/lib/writeexcel/chart.rb +8 -219
- data/lib/writeexcel/charts/area.rb +0 -0
- data/lib/writeexcel/charts/bar.rb +0 -0
- data/lib/writeexcel/charts/column.rb +0 -0
- data/lib/writeexcel/charts/external.rb +0 -0
- data/lib/writeexcel/charts/line.rb +0 -0
- data/lib/writeexcel/charts/pie.rb +0 -0
- data/lib/writeexcel/charts/scatter.rb +0 -0
- data/lib/writeexcel/charts/stock.rb +0 -0
- data/lib/writeexcel/colors.rb +4 -0
- data/lib/writeexcel/compatibility.rb +0 -0
- data/lib/writeexcel/debug_info.rb +0 -0
- data/lib/writeexcel/excelformula.y +0 -0
- data/lib/writeexcel/excelformulaparser.rb +0 -0
- data/lib/writeexcel/format.rb +2 -28
- data/lib/writeexcel/formula.rb +4 -70
- data/lib/writeexcel/helper.rb +0 -0
- data/lib/writeexcel/image.rb +158 -0
- data/lib/writeexcel/olewriter.rb +0 -0
- data/lib/writeexcel/properties.rb +0 -0
- data/lib/writeexcel/storage_lite.rb +0 -0
- data/lib/writeexcel/workbook.rb +434 -824
- data/lib/writeexcel/worksheet.rb +4194 -4718
- data/lib/writeexcel/write_file.rb +0 -0
- data/lib/writeexcel.rb +0 -0
- data/test/excelfile/Chart1.xls +0 -0
- data/test/excelfile/Chart2.xls +0 -0
- data/test/excelfile/Chart3.xls +0 -0
- data/test/excelfile/Chart4.xls +0 -0
- data/test/excelfile/Chart5.xls +0 -0
- data/test/helper.rb +0 -0
- data/test/perl_output/Chart1.xls.data +0 -0
- data/test/perl_output/Chart2.xls.data +0 -0
- data/test/perl_output/Chart3.xls.data +0 -0
- data/test/perl_output/Chart4.xls.data +0 -0
- data/test/perl_output/Chart5.xls.data +0 -0
- data/test/perl_output/README +0 -0
- data/test/perl_output/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +0 -0
- data/test/perl_output/biff_add_continue_testdata +0 -0
- data/test/perl_output/chart_area.xls +0 -0
- data/test/perl_output/chart_bar.xls +0 -0
- data/test/perl_output/chart_column.xls +0 -0
- data/test/perl_output/chart_line.xls +0 -0
- data/test/perl_output/chess.xls +0 -0
- data/test/perl_output/colors.xls +0 -0
- data/test/perl_output/comments1.xls +0 -0
- data/test/perl_output/comments2.xls +0 -0
- data/test/perl_output/data_validate.xls +0 -0
- data/test/perl_output/date_time.xls +0 -0
- data/test/perl_output/defined_name.xls +0 -0
- data/test/perl_output/demo.xls +0 -0
- data/test/perl_output/demo101.bin +0 -0
- data/test/perl_output/demo201.bin +0 -0
- data/test/perl_output/demo301.bin +0 -0
- data/test/perl_output/demo401.bin +0 -0
- data/test/perl_output/demo501.bin +0 -0
- data/test/perl_output/diag_border.xls +0 -0
- data/test/perl_output/f_font_biff +0 -0
- data/test/perl_output/f_font_key +0 -0
- data/test/perl_output/f_xf_biff +0 -0
- data/test/perl_output/file_font_biff +0 -0
- data/test/perl_output/file_font_key +0 -0
- data/test/perl_output/file_xf_biff +0 -0
- data/test/perl_output/formula_result.xls +0 -0
- data/test/perl_output/headers.xls +0 -0
- data/test/perl_output/hidden.xls +0 -0
- data/test/perl_output/hide_zero.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.xls +0 -0
- data/test/perl_output/indent.xls +0 -0
- data/test/perl_output/merge1.xls +0 -0
- data/test/perl_output/merge2.xls +0 -0
- data/test/perl_output/merge3.xls +0 -0
- data/test/perl_output/merge4.xls +0 -0
- data/test/perl_output/merge5.xls +0 -0
- data/test/perl_output/merge6.xls +0 -0
- data/test/perl_output/ole_write_header +0 -0
- data/test/perl_output/outline.xls +0 -0
- data/test/perl_output/outline_collapsed.xls +0 -0
- data/test/perl_output/panes.xls +0 -0
- data/test/perl_output/protection.xls +0 -0
- data/test/perl_output/regions.xls +0 -0
- data/test/perl_output/right_to_left.xls +0 -0
- data/test/perl_output/set_first_sheet.xls +0 -0
- data/test/perl_output/stats.xls +0 -0
- data/test/perl_output/stocks.xls +0 -0
- data/test/perl_output/tab_colors.xls +0 -0
- data/test/perl_output/unicode_cyrillic.xls +0 -0
- data/test/perl_output/utf8.xls +0 -0
- data/test/perl_output/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/perl_output/ws_colinfo +0 -0
- data/test/perl_output/ws_store_colinfo +0 -0
- data/test/perl_output/ws_store_dimensions +0 -0
- data/test/perl_output/ws_store_filtermode +0 -0
- data/test/perl_output/ws_store_filtermode_off +0 -0
- data/test/perl_output/ws_store_filtermode_on +0 -0
- data/test/perl_output/ws_store_selection +0 -0
- data/test/perl_output/ws_store_window2 +0 -0
- data/test/republic.png +0 -0
- data/test/test_00_IEEE_double.rb +0 -0
- data/test/test_01_add_worksheet.rb +0 -0
- data/test/test_02_merge_formats.rb +0 -0
- data/test/test_04_dimensions.rb +27 -27
- data/test/test_05_rows.rb +0 -0
- data/test/test_06_extsst.rb +1 -1
- data/test/test_11_date_time.rb +3 -3
- data/test/test_12_date_only.rb +7 -14
- data/test/test_13_date_seconds.rb +5 -5
- data/test/test_21_escher.rb +138 -138
- data/test/test_22_mso_drawing_group.rb +0 -0
- data/test/test_23_note.rb +4 -4
- data/test/test_24_txo.rb +3 -3
- data/test/test_25_position_object.rb +1 -1
- data/test/test_26_autofilter.rb +3 -3
- data/test/test_27_autofilter.rb +1 -1
- data/test/test_28_autofilter.rb +2 -2
- data/test/test_29_process_jpg.rb +16 -29
- data/test/test_30_validation_dval.rb +3 -3
- data/test/test_31_validation_dv_strings.rb +6 -6
- data/test/test_32_validation_dv_formula.rb +12 -12
- data/test/test_40_property_types.rb +0 -0
- data/test/test_41_properties.rb +0 -0
- data/test/test_42_set_properties.rb +0 -0
- data/test/test_50_name_stored.rb +8 -8
- data/test/test_51_name_print_area.rb +18 -18
- data/test/test_52_name_print_titles.rb +27 -27
- data/test/test_53_autofilter.rb +6 -6
- data/test/test_60_chart_generic.rb +1 -1
- data/test/test_61_chart_subclasses.rb +7 -14
- data/test/test_62_chart_formats.rb +0 -0
- data/test/test_63_chart_area_formats.rb +0 -0
- data/test/test_biff.rb +0 -0
- data/test/test_compatibility.rb +0 -0
- data/test/test_example_match.rb +31 -0
- data/test/test_format.rb +0 -0
- data/test/test_formula.rb +0 -0
- data/test/test_ole.rb +0 -0
- data/test/test_storage_lite.rb +0 -0
- data/test/test_workbook.rb +6 -0
- data/test/test_worksheet.rb +5 -5
- data/utils/add_magic_comment.rb +0 -0
- data/writeexcel.gemspec +263 -243
- data/writeexcel.rdoc +3 -3
- metadata +42 -39
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/writeexcel/colors.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/writeexcel/format.rb
CHANGED
@@ -25,14 +25,12 @@ module Writeexcel
|
|
25
25
|
class Format < Colors
|
26
26
|
require 'writeexcel/helper'
|
27
27
|
|
28
|
-
###############################################################################
|
29
28
|
#
|
30
|
-
#
|
29
|
+
# Constructor
|
30
|
+
#
|
31
31
|
# xf_index :
|
32
32
|
# properties : Hash of property => value
|
33
33
|
#
|
34
|
-
# Constructor
|
35
|
-
#
|
36
34
|
def initialize(xf_index = 0, properties = {}) # :nodoc:
|
37
35
|
@xf_index = xf_index
|
38
36
|
|
@@ -179,9 +177,6 @@ class Format < Colors
|
|
179
177
|
@font_only = other.font_only
|
180
178
|
end
|
181
179
|
|
182
|
-
###############################################################################
|
183
|
-
#
|
184
|
-
# get_xf($style)
|
185
180
|
#
|
186
181
|
# Generate an Excel BIFF XF record.
|
187
182
|
#
|
@@ -335,9 +330,6 @@ class Format < Colors
|
|
335
330
|
header + data
|
336
331
|
end
|
337
332
|
|
338
|
-
###############################################################################
|
339
|
-
#
|
340
|
-
# get_font()
|
341
333
|
#
|
342
334
|
# Generate an Excel BIFF FONT record.
|
343
335
|
#
|
@@ -406,9 +398,6 @@ class Format < Colors
|
|
406
398
|
header + data + rgch
|
407
399
|
end
|
408
400
|
|
409
|
-
###############################################################################
|
410
|
-
#
|
411
|
-
# get_font_key()
|
412
401
|
#
|
413
402
|
# Returns a unique hash key for a font. Used by Workbook->_store_all_fonts()
|
414
403
|
#
|
@@ -422,9 +411,6 @@ class Format < Colors
|
|
422
411
|
key.gsub(' ', '_') # Convert the key to a single word
|
423
412
|
end
|
424
413
|
|
425
|
-
###############################################################################
|
426
|
-
#
|
427
|
-
# xf_index()
|
428
414
|
#
|
429
415
|
# Returns the used by Worksheet->_XF()
|
430
416
|
#
|
@@ -616,9 +602,6 @@ class Format < Colors
|
|
616
602
|
@font_only
|
617
603
|
end
|
618
604
|
|
619
|
-
###############################################################################
|
620
|
-
#
|
621
|
-
# class method Format._get_color(colour)
|
622
605
|
#
|
623
606
|
# used from Worksheet.rb
|
624
607
|
#
|
@@ -628,9 +611,6 @@ class Format < Colors
|
|
628
611
|
Colors.new.get_color(color)
|
629
612
|
end
|
630
613
|
|
631
|
-
###############################################################################
|
632
|
-
#
|
633
|
-
# set_type()
|
634
614
|
#
|
635
615
|
# Set the XF object type as 0 = cell XF or 0xFFF5 = style XF.
|
636
616
|
#
|
@@ -986,9 +966,6 @@ class Format < Colors
|
|
986
966
|
end
|
987
967
|
end
|
988
968
|
|
989
|
-
###############################################################################
|
990
|
-
#
|
991
|
-
# set_valign()
|
992
969
|
#
|
993
970
|
# Set vertical cell alignment. This is required by the set_format_properties()
|
994
971
|
# method to differentiate between the vertical and horizontal properties.
|
@@ -1023,9 +1000,6 @@ class Format < Colors
|
|
1023
1000
|
set_text_h_align(6)
|
1024
1001
|
end
|
1025
1002
|
|
1026
|
-
###############################################################################
|
1027
|
-
#
|
1028
|
-
# set_merge()
|
1029
1003
|
#
|
1030
1004
|
# This was the way to implement a merge in Excel5. However it should have been
|
1031
1005
|
# called "center_across" and not "merge".
|
data/lib/writeexcel/formula.rb
CHANGED
@@ -31,9 +31,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
31
31
|
initialize_hashes
|
32
32
|
end
|
33
33
|
|
34
|
-
###############################################################################
|
35
|
-
#
|
36
|
-
# parse_formula()
|
37
34
|
#
|
38
35
|
# Takes a textual description of a formula and returns a RPN encoded byte
|
39
36
|
# string.
|
@@ -60,9 +57,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
60
57
|
end
|
61
58
|
end
|
62
59
|
|
63
|
-
###############################################################################
|
64
|
-
#
|
65
|
-
# parse_tokens()
|
66
60
|
#
|
67
61
|
# Convert each token or token pair to its Excel 'ptg' equivalent.
|
68
62
|
#
|
@@ -227,9 +221,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
227
221
|
###############################################################################
|
228
222
|
|
229
223
|
|
230
|
-
###############################################################################
|
231
|
-
#
|
232
|
-
# _check_volatile()
|
233
224
|
#
|
234
225
|
# Check if the formula contains a volatile function, i.e. a function that must
|
235
226
|
# be recalculated each time a cell is updated. These formulas require a ptgAttr
|
@@ -251,9 +242,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
251
242
|
volatile
|
252
243
|
end
|
253
244
|
|
254
|
-
###############################################################################
|
255
|
-
#
|
256
|
-
# _convert_volatile()
|
257
245
|
#
|
258
246
|
# Convert _vol to a ptgAttr tag formatted to indicate that the formula contains
|
259
247
|
# a volatile function. See _check_volatile()
|
@@ -263,9 +251,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
263
251
|
return [@ptg['ptgAttr'], 0x1, 0x0].pack("CCv")
|
264
252
|
end
|
265
253
|
|
266
|
-
###############################################################################
|
267
|
-
#
|
268
|
-
# _convert_bool()
|
269
254
|
#
|
270
255
|
# Convert a boolean token to ptgBool
|
271
256
|
#
|
@@ -274,9 +259,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
274
259
|
end
|
275
260
|
|
276
261
|
|
277
|
-
###############################################################################
|
278
|
-
#
|
279
|
-
# _convert_number()
|
280
262
|
#
|
281
263
|
# Convert a number token to ptgInt or ptgNum
|
282
264
|
#
|
@@ -291,9 +273,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
291
273
|
end
|
292
274
|
end
|
293
275
|
|
294
|
-
###############################################################################
|
295
|
-
#
|
296
|
-
# _convert_string()
|
297
276
|
#
|
298
277
|
# Convert a string to a ptg Str.
|
299
278
|
#
|
@@ -322,9 +301,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
322
301
|
[@ptg['ptgStr'], length, encoding].pack("CCC") + str
|
323
302
|
end
|
324
303
|
|
325
|
-
###############################################################################
|
326
|
-
#
|
327
|
-
# _convert_ref2d()
|
328
304
|
#
|
329
305
|
# Convert an Excel reference such as A1, $B2, C$3 or $D$4 to a ptgRefV.
|
330
306
|
#
|
@@ -346,9 +322,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
346
322
|
ptgref + row + col
|
347
323
|
end
|
348
324
|
|
349
|
-
###############################################################################
|
350
|
-
#
|
351
|
-
# _convert_ref3d
|
352
325
|
#
|
353
326
|
# Convert an Excel 3d reference such as "Sheet1!A1" or "Sheet1:Sheet2!A1" to a
|
354
327
|
# ptgRef3dV.
|
@@ -377,9 +350,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
377
350
|
ptgref + ext_ref + row + col
|
378
351
|
end
|
379
352
|
|
380
|
-
###############################################################################
|
381
|
-
#
|
382
|
-
# _convert_range2d()
|
383
353
|
#
|
384
354
|
# Convert an Excel range such as A1:D4 or A:D to a ptgRefV.
|
385
355
|
#
|
@@ -409,9 +379,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
409
379
|
ptgarea + row1 + row2 + col1 + col2
|
410
380
|
end
|
411
381
|
|
412
|
-
###############################################################################
|
413
|
-
#
|
414
|
-
# _convert_range3d
|
415
382
|
#
|
416
383
|
# Convert an Excel 3d range such as "Sheet1!A1:D4" or "Sheet1:Sheet2!A1:D4" to
|
417
384
|
# a ptgArea3dV.
|
@@ -448,9 +415,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
448
415
|
ptgarea + ext_ref + row1 + row2 + col1+ col2
|
449
416
|
end
|
450
417
|
|
451
|
-
###############################################################################
|
452
|
-
#
|
453
|
-
# _pack_ext_ref()
|
454
418
|
#
|
455
419
|
# Convert the sheet name part of an external reference, for example "Sheet1" or
|
456
420
|
# "Sheet1:Sheet2", to a packed structure.
|
@@ -491,9 +455,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
491
455
|
[index].pack("v")
|
492
456
|
end
|
493
457
|
|
494
|
-
###############################################################################
|
495
|
-
#
|
496
|
-
# _get_sheet_index()
|
497
458
|
#
|
498
459
|
# Look up the index that corresponds to an external sheet name. The hash of
|
499
460
|
# sheet names is updated by the add_worksheet() method of the Workbook class.
|
@@ -515,9 +476,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
515
476
|
end
|
516
477
|
public :get_sheet_index
|
517
478
|
|
518
|
-
###############################################################################
|
519
|
-
#
|
520
|
-
# set_ext_sheets()
|
521
479
|
#
|
522
480
|
# This semi-public method is used to update the hash of sheet names. It is
|
523
481
|
# updated by the add_worksheet() method of the Workbook class.
|
@@ -529,9 +487,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
529
487
|
end
|
530
488
|
public :set_ext_sheets
|
531
489
|
|
532
|
-
###############################################################################
|
533
|
-
#
|
534
|
-
# get_ext_sheets()
|
535
490
|
#
|
536
491
|
# This semi-public method is used to get the worksheet references that were
|
537
492
|
# used in formulas for inclusion in the EXTERNSHEET Workbook record.
|
@@ -541,9 +496,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
541
496
|
end
|
542
497
|
public :get_ext_sheets
|
543
498
|
|
544
|
-
###############################################################################
|
545
|
-
#
|
546
|
-
# get_ext_ref_count()
|
547
499
|
#
|
548
500
|
# TODO This semi-public method is used to update the hash of sheet names. It is
|
549
501
|
# updated by the add_worksheet() method of the Workbook class.
|
@@ -552,9 +504,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
552
504
|
@ext_ref_count
|
553
505
|
end
|
554
506
|
|
555
|
-
###############################################################################
|
556
|
-
#
|
557
|
-
# _get_name_index()
|
558
507
|
#
|
559
508
|
# Look up the index that corresponds to an external defined name. The hash of
|
560
509
|
# defined names is updated by the define_name() method in the Workbook class.
|
@@ -568,9 +517,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
568
517
|
end
|
569
518
|
private :get_name_index
|
570
519
|
|
571
|
-
###############################################################################
|
572
|
-
#
|
573
|
-
# set_ext_name()
|
574
520
|
#
|
575
521
|
# This semi-public method is used to update the hash of defined names.
|
576
522
|
#
|
@@ -579,9 +525,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
579
525
|
end
|
580
526
|
public :set_ext_name
|
581
527
|
|
582
|
-
###############################################################################
|
583
|
-
#
|
584
|
-
# _convert_function()
|
585
528
|
#
|
586
529
|
# Convert a function to a ptgFunc or ptgFuncVarV depending on the number of
|
587
530
|
# args that it takes.
|
@@ -607,9 +550,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
607
550
|
end
|
608
551
|
end
|
609
552
|
|
610
|
-
###############################################################################
|
611
|
-
#
|
612
|
-
# _convert_name()
|
613
553
|
#
|
614
554
|
# Convert a symbolic name into a name reference.
|
615
555
|
#
|
@@ -629,9 +569,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
629
569
|
end
|
630
570
|
private :convert_name
|
631
571
|
|
632
|
-
###############################################################################
|
633
|
-
#
|
634
|
-
# _cell_to_rowcol($cell_ref)
|
635
572
|
#
|
636
573
|
# Convert an Excel cell reference such as A1 or $B2 or C$3 or $D$4 to a zero
|
637
574
|
# indexed row and column number. Also returns two boolean values to indicate
|
@@ -654,9 +591,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
654
591
|
[row, col, row_rel, col_rel]
|
655
592
|
end
|
656
593
|
|
657
|
-
###############################################################################
|
658
|
-
#
|
659
|
-
# _cell_to_packed_rowcol($row, $col, $row_rel, $col_rel)
|
660
594
|
#
|
661
595
|
# pack() row and column into the required 3 byte format.
|
662
596
|
#
|
@@ -676,10 +610,6 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
676
610
|
[row, col]
|
677
611
|
end
|
678
612
|
|
679
|
-
###############################################################################
|
680
|
-
#
|
681
|
-
# _initialize_hashes()
|
682
|
-
#
|
683
613
|
def initialize_hashes
|
684
614
|
|
685
615
|
# The Excel ptg indices
|
@@ -1024,6 +954,10 @@ class Formula < ExcelFormulaParser #:nodoc:
|
|
1024
954
|
}
|
1025
955
|
|
1026
956
|
end
|
957
|
+
|
958
|
+
def inspect
|
959
|
+
to_s
|
960
|
+
end
|
1027
961
|
end
|
1028
962
|
|
1029
963
|
if $0 ==__FILE__
|
data/lib/writeexcel/helper.rb
CHANGED
File without changes
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
require 'digest/md5'
|
3
|
+
|
4
|
+
module Writeexcel
|
5
|
+
class Image
|
6
|
+
attr_reader :row, :col, :filename, :x_offset, :y_offset, :scale_x, :scale_y
|
7
|
+
attr_reader :data, :size, :checksum1, :checksum2
|
8
|
+
attr_accessor :id, :type, :width, :height, :ref_count
|
9
|
+
|
10
|
+
def initialize(row, col, filename, x_offset = 0, y_offset = 0, scale_x = 1, scale_y = 1)
|
11
|
+
@row = row
|
12
|
+
@col = col
|
13
|
+
@filename = filename
|
14
|
+
@x_offset = x_offset
|
15
|
+
@y_offset = y_offset
|
16
|
+
@scale_x = scale_x
|
17
|
+
@scale_y = scale_y
|
18
|
+
get_checksum_method
|
19
|
+
end
|
20
|
+
|
21
|
+
def import
|
22
|
+
File.open(@filename, "rb") do |fh|
|
23
|
+
raise "Couldn't import #{@filename}: #{$!}" unless fh
|
24
|
+
@data = fh.read
|
25
|
+
end
|
26
|
+
@size = data.bytesize
|
27
|
+
@checksum1 = image_checksum(@data)
|
28
|
+
@checksum2 = @checksum1
|
29
|
+
process
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Process the image and extract dimensions.
|
35
|
+
def process
|
36
|
+
case filetype
|
37
|
+
when 'PNG'
|
38
|
+
process_png(@data)
|
39
|
+
when 'JPG'
|
40
|
+
process_jpg(@data)
|
41
|
+
when 'BMP'
|
42
|
+
process_bmp(@data)
|
43
|
+
# The 14 byte header of the BMP is stripped off.
|
44
|
+
@data[0, 13] = ''
|
45
|
+
# A checksum of the new image data is also required.
|
46
|
+
@checksum2 = image_checksum(@data, @id, @id)
|
47
|
+
# Adjust size -14 (header) + 16 (extra checksum).
|
48
|
+
@size += 2
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def filetype
|
53
|
+
return 'PNG' if @data.unpack('x A3')[0] == 'PNG'
|
54
|
+
return 'BMP' if @data.unpack('A2')[0] == 'BM'
|
55
|
+
if data.unpack('n')[0] == 0xFFD8
|
56
|
+
return 'JPG' if @data.unpack('x6 A4')[0] == 'JFIF' || @data.unpack('x6 A4')[0] == 'Exif'
|
57
|
+
else
|
58
|
+
raise "Unsupported image format for file: #{@filename}\n"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Extract width and height information from a PNG file.
|
63
|
+
def process_png(data)
|
64
|
+
@type = 6 # Excel Blip type (MSOBLIPTYPE).
|
65
|
+
@width = data[16, 4].unpack("N")[0]
|
66
|
+
@height = data[20, 4].unpack("N")[0]
|
67
|
+
end
|
68
|
+
|
69
|
+
# Extract width and height information from a BMP file.
|
70
|
+
def process_bmp(data) #:nodoc:
|
71
|
+
@type = 7 # Excel Blip type (MSOBLIPTYPE).
|
72
|
+
# Read the bitmap width and height. Verify the sizes.
|
73
|
+
@width, @height = data.unpack("x18 V2")
|
74
|
+
check_verify(data)
|
75
|
+
end
|
76
|
+
|
77
|
+
def check_verify(data)
|
78
|
+
# Check that the file is big enough to be a bitmap.
|
79
|
+
raise "#{@filename} doesn't contain enough data." if data.bytesize <= 0x36
|
80
|
+
raise "#{@filename}: largest image width #{width} supported is 65k." if @width > 0xFFFF
|
81
|
+
raise "#{@filename}: largest image height supported is 65k." if @height > 0xFFFF
|
82
|
+
|
83
|
+
# Read the bitmap planes and bpp data. Verify them.
|
84
|
+
planes, bitcount = data.unpack("x26 v2")
|
85
|
+
raise "#{@filename} isn't a 24bit true color bitmap." unless bitcount == 24
|
86
|
+
raise "#{@filename}: only 1 plane supported in bitmap image." unless planes == 1
|
87
|
+
|
88
|
+
# Read the bitmap compression. Verify compression.
|
89
|
+
compression = data.unpack("x30 V")
|
90
|
+
raise "#{@filename}: compression not supported in bitmap image." unless compression == 0
|
91
|
+
end
|
92
|
+
|
93
|
+
# Extract width and height information from a JPEG file.
|
94
|
+
def process_jpg(data)
|
95
|
+
@type = 5 # Excel Blip type (MSOBLIPTYPE).
|
96
|
+
|
97
|
+
offset = 2
|
98
|
+
data_length = data.bytesize
|
99
|
+
|
100
|
+
# Search through the image data to find the 0xFFC0 marker. The height and
|
101
|
+
# width are contained in the data for that sub element.
|
102
|
+
while offset < data_length
|
103
|
+
marker = data[offset, 2].unpack("n")
|
104
|
+
marker = marker[0]
|
105
|
+
length = data[offset+2, 2].unpack("n")
|
106
|
+
length = length[0]
|
107
|
+
|
108
|
+
if marker == 0xFFC0 || marker == 0xFFC2
|
109
|
+
height = data[offset+5, 2].unpack("n")
|
110
|
+
@height = height[0]
|
111
|
+
width = data[offset+7, 2].unpack("n")
|
112
|
+
@width = width[0]
|
113
|
+
break
|
114
|
+
end
|
115
|
+
|
116
|
+
offset += length + 2
|
117
|
+
break if marker == 0xFFDA
|
118
|
+
end
|
119
|
+
|
120
|
+
raise "#{@filename}: no size data found in jpeg image.\n" unless @height
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Generate a checksum for the image using whichever module is available. The
|
125
|
+
# available modules are checked in get_checksum_method(). Excel uses an MD4
|
126
|
+
# checksum but any other will do. In the event of no checksum module being
|
127
|
+
# available we simulate a checksum using the image index.
|
128
|
+
#
|
129
|
+
# index1 and index2 is not used.
|
130
|
+
#
|
131
|
+
def image_checksum(data, index1 = 0, index2 = 0) #:nodoc:
|
132
|
+
case @checksum_method
|
133
|
+
when 3
|
134
|
+
Digest::MD5.hexdigest(data)
|
135
|
+
when 1
|
136
|
+
# Digest::MD4
|
137
|
+
# return Digest::MD4::md4_hex($data);
|
138
|
+
when 2
|
139
|
+
# Digest::Perl::MD4
|
140
|
+
# return Digest::Perl::MD4::md4_hex($data);
|
141
|
+
else
|
142
|
+
# Default
|
143
|
+
# return sprintf('%016X%016X', index2, index1)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Check for modules available to calculate image checksum. Excel uses MD4 but
|
149
|
+
# MD5 will also work.
|
150
|
+
#
|
151
|
+
# ------- cxn03651 add -------
|
152
|
+
# md5 can use in ruby. so, @checksum_method is always 3.
|
153
|
+
|
154
|
+
def get_checksum_method #:nodoc:
|
155
|
+
@checksum_method = 3
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
data/lib/writeexcel/olewriter.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|