ricardoo27-writeexcel 0.6.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitattributes +1 -0
- data/README.rdoc +136 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/charts/chartex.rb +316 -0
- data/charts/demo1.rb +46 -0
- data/charts/demo101.bin +0 -0
- data/charts/demo2.rb +65 -0
- data/charts/demo201.bin +0 -0
- data/charts/demo3.rb +117 -0
- data/charts/demo301.bin +0 -0
- data/charts/demo4.rb +119 -0
- data/charts/demo401.bin +0 -0
- data/charts/demo5.rb +48 -0
- data/charts/demo501.bin +0 -0
- data/examples/a_simple.rb +43 -0
- data/examples/autofilter.rb +265 -0
- data/examples/bigfile.rb +30 -0
- data/examples/chart_area.rb +121 -0
- data/examples/chart_bar.rb +120 -0
- data/examples/chart_column.rb +120 -0
- data/examples/chart_line.rb +120 -0
- data/examples/chart_pie.rb +108 -0
- data/examples/chart_scatter.rb +121 -0
- data/examples/chart_stock.rb +148 -0
- data/examples/chess.rb +142 -0
- data/examples/colors.rb +129 -0
- data/examples/comments1.rb +27 -0
- data/examples/comments2.rb +352 -0
- data/examples/copyformat.rb +52 -0
- data/examples/data_validate.rb +279 -0
- data/examples/date_time.rb +87 -0
- data/examples/defined_name.rb +32 -0
- data/examples/demo.rb +124 -0
- data/examples/diag_border.rb +36 -0
- data/examples/formats.rb +490 -0
- data/examples/formula_result.rb +30 -0
- data/examples/header.rb +137 -0
- data/examples/hide_sheet.rb +29 -0
- data/examples/hyperlink.rb +43 -0
- data/examples/images.rb +63 -0
- data/examples/indent.rb +31 -0
- data/examples/merge1.rb +40 -0
- data/examples/merge2.rb +45 -0
- data/examples/merge3.rb +66 -0
- data/examples/merge4.rb +83 -0
- data/examples/merge5.rb +80 -0
- data/examples/merge6.rb +67 -0
- data/examples/outline.rb +255 -0
- data/examples/outline_collapsed.rb +209 -0
- data/examples/panes.rb +113 -0
- data/examples/password_protection.rb +33 -0
- data/examples/properties.rb +34 -0
- data/examples/properties_jp.rb +33 -0
- data/examples/protection.rb +47 -0
- data/examples/regions.rb +53 -0
- data/examples/repeat.rb +43 -0
- data/examples/republic.png +0 -0
- data/examples/right_to_left.rb +27 -0
- data/examples/row_wrap.rb +53 -0
- data/examples/set_first_sheet.rb +14 -0
- data/examples/stats.rb +74 -0
- data/examples/stocks.rb +81 -0
- data/examples/store_formula.rb +15 -0
- data/examples/tab_colors.rb +31 -0
- data/examples/utf8.rb +15 -0
- data/examples/write_arrays.rb +83 -0
- data/html/en/doc_en.html +5946 -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.rb +1159 -0
- data/lib/writeexcel/biffwriter.rb +223 -0
- data/lib/writeexcel/caller_info.rb +12 -0
- data/lib/writeexcel/cell_range.rb +332 -0
- data/lib/writeexcel/chart.rb +1968 -0
- data/lib/writeexcel/charts/area.rb +154 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +66 -0
- data/lib/writeexcel/charts/line.rb +154 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +213 -0
- data/lib/writeexcel/col_info.rb +87 -0
- data/lib/writeexcel/colors.rb +68 -0
- data/lib/writeexcel/comments.rb +460 -0
- data/lib/writeexcel/compatibility.rb +65 -0
- data/lib/writeexcel/convert_date_time.rb +117 -0
- data/lib/writeexcel/data_validations.rb +370 -0
- data/lib/writeexcel/debug_info.rb +41 -0
- data/lib/writeexcel/embedded_chart.rb +35 -0
- data/lib/writeexcel/excelformula.y +139 -0
- data/lib/writeexcel/excelformulaparser.rb +587 -0
- data/lib/writeexcel/format.rb +1575 -0
- data/lib/writeexcel/formula.rb +987 -0
- data/lib/writeexcel/helper.rb +78 -0
- data/lib/writeexcel/image.rb +218 -0
- data/lib/writeexcel/olewriter.rb +305 -0
- data/lib/writeexcel/outline.rb +24 -0
- data/lib/writeexcel/properties.rb +242 -0
- data/lib/writeexcel/shared_string_table.rb +153 -0
- data/lib/writeexcel/storage_lite.rb +984 -0
- data/lib/writeexcel/workbook.rb +2478 -0
- data/lib/writeexcel/worksheet.rb +6925 -0
- data/lib/writeexcel/worksheets.rb +25 -0
- data/lib/writeexcel/write_file.rb +63 -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 +31 -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 +31 -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/comments0.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 +1 -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 +1 -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/password_protection.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/store_formula.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 +1 -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 +1 -0
- data/test/republic.png +0 -0
- data/test/test_00_IEEE_double.rb +13 -0
- data/test/test_01_add_worksheet.rb +10 -0
- data/test/test_02_merge_formats.rb +49 -0
- data/test/test_04_dimensions.rb +388 -0
- data/test/test_05_rows.rb +175 -0
- data/test/test_06_extsst.rb +74 -0
- data/test/test_11_date_time.rb +475 -0
- data/test/test_12_date_only.rb +525 -0
- data/test/test_13_date_seconds.rb +477 -0
- data/test/test_21_escher.rb +624 -0
- data/test/test_22_mso_drawing_group.rb +741 -0
- data/test/test_23_note.rb +57 -0
- data/test/test_24_txo.rb +74 -0
- data/test/test_25_position_object.rb +80 -0
- data/test/test_26_autofilter.rb +309 -0
- data/test/test_27_autofilter.rb +126 -0
- data/test/test_28_autofilter.rb +156 -0
- data/test/test_29_process_jpg.rb +670 -0
- data/test/test_30_validation_dval.rb +74 -0
- data/test/test_31_validation_dv_strings.rb +123 -0
- data/test/test_32_validation_dv_formula.rb +203 -0
- data/test/test_40_property_types.rb +188 -0
- data/test/test_41_properties.rb +235 -0
- data/test/test_42_set_properties.rb +434 -0
- data/test/test_50_name_stored.rb +295 -0
- data/test/test_51_name_print_area.rb +353 -0
- data/test/test_52_name_print_titles.rb +450 -0
- data/test/test_53_autofilter.rb +199 -0
- data/test/test_60_chart_generic.rb +574 -0
- data/test/test_61_chart_subclasses.rb +84 -0
- data/test/test_62_chart_formats.rb +268 -0
- data/test/test_63_chart_area_formats.rb +645 -0
- data/test/test_biff.rb +71 -0
- data/test/test_big_workbook.rb +17 -0
- data/test/test_compatibility.rb +12 -0
- data/test/test_example_match.rb +3246 -0
- data/test/test_format.rb +1189 -0
- data/test/test_formula.rb +61 -0
- data/test/test_ole.rb +102 -0
- data/test/test_storage_lite.rb +116 -0
- data/test/test_workbook.rb +146 -0
- data/test/test_worksheet.rb +106 -0
- data/utils/add_magic_comment.rb +80 -0
- data/writeexcel.gemspec +278 -0
- data/writeexcel.rdoc +1425 -0
- metadata +292 -0
data/.document
ADDED
data/.gitattributes
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.rb diff=ruby
|
data/README.rdoc
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
= writeexcel
|
2
|
+
|
3
|
+
Write to a cross-platform Excel binary file.
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
This library is converted from Spreadsheet::WriteExcel module of Perl.
|
8
|
+
http://search.cpan.org/~jmcnamara/Spreadsheet-WriteExcel-2.37/
|
9
|
+
|
10
|
+
Some examples written in perl was successfully converted to Ruby. But
|
11
|
+
this library written in Ruby has many bugs, I think.
|
12
|
+
|
13
|
+
Original description is below:
|
14
|
+
|
15
|
+
The Spreadsheet::WriteExcel module can be used to create a cross-
|
16
|
+
platform Excel binary file. Multiple worksheets can be added to a
|
17
|
+
workbook and formatting can be applied to cells. Text, numbers,
|
18
|
+
formulas, hyperlinks, images and charts can be written to the cells.
|
19
|
+
|
20
|
+
TThe Excel file produced by this module is compatible with 97,
|
21
|
+
2000, 2002, 2003 and 2007.
|
22
|
+
|
23
|
+
The module will work on the majority of Windows, UNIX and
|
24
|
+
Macintosh platforms. Generated files are also compatible with the
|
25
|
+
spreadsheet applications Gnumeric and OpenOffice.org.
|
26
|
+
|
27
|
+
This module cannot be used to read an Excel file.
|
28
|
+
|
29
|
+
== Usage
|
30
|
+
|
31
|
+
See rdoc's WriteExcel class document or Reference http://writeexcel.web.fc2.com/ .
|
32
|
+
You must save source file in UTF8 and run ruby with -Ku option or set $KCODE='u'.
|
33
|
+
|
34
|
+
Example Code:
|
35
|
+
|
36
|
+
require 'writeexcel'
|
37
|
+
|
38
|
+
# Create a new Excel Workbook
|
39
|
+
workbook = WriteExcel.new('ruby.xls')
|
40
|
+
|
41
|
+
# Add worksheet(s)
|
42
|
+
worksheet = workbook.add_worksheet
|
43
|
+
worksheet2 = workbook.add_worksheet
|
44
|
+
|
45
|
+
# Add and define a format
|
46
|
+
format = workbook.add_format
|
47
|
+
format.set_bold
|
48
|
+
format.set_color('red')
|
49
|
+
format.set_align('right')
|
50
|
+
|
51
|
+
# write a formatted and unformatted string.
|
52
|
+
worksheet.write(1, 1, 'Hi Excel.', format) # cell B2
|
53
|
+
worksheet.write(2, 1, 'Hi Excel.') # cell B3
|
54
|
+
|
55
|
+
# write a number and formula using A1 notation
|
56
|
+
worksheet.write('B4', 3.14159)
|
57
|
+
worksheet.write('B5', '=SIN(B4/4)')
|
58
|
+
|
59
|
+
# write to file
|
60
|
+
workbook.close
|
61
|
+
|
62
|
+
== Difference with Perl module
|
63
|
+
|
64
|
+
* WriteExcel.new()
|
65
|
+
* accept default format parameter such as new('foo.xls', :font => 'Roman', :size => 12)
|
66
|
+
* Unary minus is supported, but it will be stored as '-1*'. ex) '=-1' -> '=-1*1', '=-SIN(PI()/2)' => '=-1*SIN(PI()/2)'
|
67
|
+
* Worksheet.write(row, col, token, format)
|
68
|
+
* if token.kind_of?(Numeric) then call write_number, if token.kind_of?(String) then not call write_number().
|
69
|
+
* Worksheet.keep_leading_zeros()
|
70
|
+
* ignore. if write 0001, use string such as write(1,2, '0001')
|
71
|
+
* and ......
|
72
|
+
|
73
|
+
== Caution
|
74
|
+
|
75
|
+
You must save source file in UTF8 and run ruby with -Ku option or set $KCODE='u'
|
76
|
+
when use urf8 string data.
|
77
|
+
|
78
|
+
== Recent Changes
|
79
|
+
v0.6.12
|
80
|
+
* Bug fix issue 17. Worksheet#store_formula shouldn't be private
|
81
|
+
|
82
|
+
v0.6.11
|
83
|
+
* Bug fix issue 15. Worksheet#write_comment on the same row overwrite other comments.
|
84
|
+
|
85
|
+
v0.6.10
|
86
|
+
* Bug fix. method missing split_string_setup() in shared_string_table.rb. see https://github.com/cxn03651/writeexcel/pull/13
|
87
|
+
|
88
|
+
v0.6.9
|
89
|
+
* Bug fix. When sheetname is cell's A1 notation such as 'D1', Worksheet#autofilter causes exception.
|
90
|
+
|
91
|
+
v0.6.8
|
92
|
+
* Bug fix. Worksheet#protect doesn't work well.
|
93
|
+
|
94
|
+
v0.6.7
|
95
|
+
* Bug fix. Worksheet#set_first_sheet doesn't work well.
|
96
|
+
* Bug fix. Worksheet#hide_zero doesn't work well.
|
97
|
+
* Bug fix. Worksheet#set_column - col width doesn't set to zero when pass hidden 1.
|
98
|
+
'
|
99
|
+
v0.6.6
|
100
|
+
* add private method to avoid warning: private attribute?
|
101
|
+
|
102
|
+
v0.6.5
|
103
|
+
* Bug fix. if workbook already has worksheet of utf8 name, Workbook#add_worksheet, Workbook#add_chart, Workbook#add_chart_ext raise exception when add new worksheet of utf8 name.
|
104
|
+
|
105
|
+
v0.6.4
|
106
|
+
* Bug fix. endless loop when inserted image size > 8224bytes.
|
107
|
+
|
108
|
+
v0.6.3
|
109
|
+
* Bug fix. endless loop when inserted image size > 8224.
|
110
|
+
|
111
|
+
v0.6.1
|
112
|
+
* Bug fix. to avoid output stack trace for debug when defined $debug such as Rails 2.3.8 development console.
|
113
|
+
|
114
|
+
v0.6.0
|
115
|
+
* Bug fix. to avoid destroy to_json method when using with Rails 3
|
116
|
+
|
117
|
+
== Author
|
118
|
+
|
119
|
+
Original was written in Perl by John McNamara (jmcnamara@cpan.org).
|
120
|
+
|
121
|
+
Convert to ruby by Hideo Nakamura (cxn03651@msj.biglobe.ne.jp)
|
122
|
+
Copyright (c) 2009-2010 Hideo NAKAMURA. See LICENSE for details.
|
123
|
+
|
124
|
+
== License
|
125
|
+
|
126
|
+
same as Ruby.
|
127
|
+
|
128
|
+
== Note on Patches/Pull Requests
|
129
|
+
|
130
|
+
* Fork the project.
|
131
|
+
* Make your feature addition or bug fix.
|
132
|
+
* Add tests for it. This is important so I don't break it in a
|
133
|
+
future version unintentionally.
|
134
|
+
* Commit, do not mess with rakefile, version, or history.
|
135
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
136
|
+
* Send me a pull request. Bonus points for topic branches.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "writeexcel"
|
8
|
+
gem.summary = %Q{Write to a cross-platform Excel binary file.}
|
9
|
+
gem.description = %Q{Multiple worksheets can be added to a workbook and formatting can be applied to cells. Text, numbers, formulas, hyperlinks and images can be written to the cells.}
|
10
|
+
gem.email = "cxn03651@msj.biglobe.ne.jp"
|
11
|
+
gem.homepage = "http://wiki.github.com/cxn03651/writeexcel/"
|
12
|
+
gem.authors = ["Hideo NAKAMURA"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "writeexcel #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.6.12
|
data/charts/chartex.rb
ADDED
@@ -0,0 +1,316 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
|
4
|
+
#######################################################################
|
5
|
+
#
|
6
|
+
# chartex - A utility to extract charts from an Excel file for
|
7
|
+
# insertion into a WriteExcel file.
|
8
|
+
#
|
9
|
+
# reverse('ゥ'), September 2007, John McNamara, jmcnamara@cpan.org
|
10
|
+
#
|
11
|
+
# original written in Perl by John McNamara
|
12
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
13
|
+
#
|
14
|
+
# Documentation after __END__
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'writeexcel'
|
18
|
+
|
19
|
+
class Chartex
|
20
|
+
attr_reader :file
|
21
|
+
|
22
|
+
def initialize(file = nil)
|
23
|
+
@file = file
|
24
|
+
@sheetnames = Array.new
|
25
|
+
@exrefs = Array.new
|
26
|
+
@buf = StringIO.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_file(file)
|
30
|
+
@file = file
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_workbook(file = nil)
|
34
|
+
file ||= @file
|
35
|
+
ole = OLEStorageLite.new(file)
|
36
|
+
book97 = 'Workbook'.unpack('C*').pack('v*')
|
37
|
+
workbook = ole.getPpsSearch([book97], 1, 1)[0]
|
38
|
+
@buf.write(workbook.data)
|
39
|
+
@buf.rewind
|
40
|
+
workbook
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# main
|
45
|
+
|
46
|
+
if $0 == __FILE__
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
=begin
|
51
|
+
my $man = 0;
|
52
|
+
my $help = 0;
|
53
|
+
my $in_chart = 0;
|
54
|
+
my $chart_name = 'chart';
|
55
|
+
my $chart_index = 1;
|
56
|
+
my $sheet_index = -1;
|
57
|
+
my @sheetnames;
|
58
|
+
my @exrefs;
|
59
|
+
my $depth_count = 0;
|
60
|
+
my $max_font = 0;
|
61
|
+
|
62
|
+
#
|
63
|
+
# Do the Getopt and Pod::Usage routines.
|
64
|
+
#
|
65
|
+
GetOptions(
|
66
|
+
'help|?' => \$help,
|
67
|
+
'man' => \$man,
|
68
|
+
'chart=s' => \$chart_name,
|
69
|
+
) or pod2usage(2);
|
70
|
+
|
71
|
+
pod2usage(1) if $help;
|
72
|
+
pod2usage(-verbose => 2) if $man;
|
73
|
+
|
74
|
+
|
75
|
+
# From the Pod::Usage pod:
|
76
|
+
# If no arguments were given, then allow STDIN to be used only
|
77
|
+
# if it's not connected to a terminal (otherwise print usage)
|
78
|
+
pod2usage() if @ARGV == 0 && -t STDIN;
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
# Check that the file can be opened because OLE::Storage_Lite won't tell us.
|
84
|
+
# Possible race condition here. Could fix with latest OLE::Storage_Lite. TODO.
|
85
|
+
#
|
86
|
+
my $file = $ARGV[0];
|
87
|
+
|
88
|
+
open TMP, $file or die "Couldn't open $file. $!\n";
|
89
|
+
close TMP;
|
90
|
+
|
91
|
+
my $ole = OLE::Storage_Lite->new($file);
|
92
|
+
my $book97 = pack 'v*', unpack 'C*', 'Workbook';
|
93
|
+
my $workbook = ($ole->getPpsSearch([$book97], 1, 1))[0];
|
94
|
+
|
95
|
+
die "Couldn't find Excel97 data in file $file.\n" unless $workbook;
|
96
|
+
|
97
|
+
|
98
|
+
# Write the data to a file so that we can access it with read().
|
99
|
+
my $tmpfile = IO::File->new_tmpfile();
|
100
|
+
binmode $tmpfile;
|
101
|
+
|
102
|
+
my $biff = $workbook->{Data};
|
103
|
+
print {$tmpfile} $biff;
|
104
|
+
seek $tmpfile, 0, 0;
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
my $header;
|
109
|
+
my $data;
|
110
|
+
|
111
|
+
# Read the file record by record and look for a chart BOF record.
|
112
|
+
#
|
113
|
+
while (read $tmpfile, $header, 4) {
|
114
|
+
|
115
|
+
my ($record, $length) = unpack "vv", $header;
|
116
|
+
next unless $record;
|
117
|
+
|
118
|
+
read $tmpfile, $data, $length;
|
119
|
+
|
120
|
+
# BOUNDSHEET
|
121
|
+
if ($record == 0x0085) {
|
122
|
+
push @sheetnames, substr $data, 8;
|
123
|
+
}
|
124
|
+
|
125
|
+
# EXTERNSHEET
|
126
|
+
if ($record == 0x0017) {
|
127
|
+
my $count = unpack 'v', $data;
|
128
|
+
|
129
|
+
for my $i (1 .. $count) {
|
130
|
+
my @tmp = unpack 'vvv', substr($data, 2 +6*($i-1));
|
131
|
+
push @exrefs, [@tmp];
|
132
|
+
}
|
133
|
+
|
134
|
+
}
|
135
|
+
|
136
|
+
# BOF
|
137
|
+
if ($record == 0x0809) {
|
138
|
+
my $type = unpack 'xx v', $data;
|
139
|
+
|
140
|
+
if ($type == 0x0020) {
|
141
|
+
my $filename = sprintf "%s%02d.bin", $chart_name, $chart_index;
|
142
|
+
open CHART, ">$filename" or die "Couldn't open $filename: $!";
|
143
|
+
binmode CHART;
|
144
|
+
|
145
|
+
my $sheet_name = $sheetnames[$sheet_index];
|
146
|
+
$sheet_name .= ' embedded' if $depth_count;
|
147
|
+
|
148
|
+
printf "\nExtracting \%s\ to %s", $sheet_name, $filename;
|
149
|
+
$in_chart = 1;
|
150
|
+
$chart_index++;
|
151
|
+
}
|
152
|
+
$depth_count++;
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
# FBI, Chart fonts
|
157
|
+
if ($record == 0x1060) {
|
158
|
+
|
159
|
+
my $index = substr $data, 8, 2, '';
|
160
|
+
$index = unpack 'v', $index;
|
161
|
+
|
162
|
+
# Ignore the inbuilt fonts.
|
163
|
+
if ($index >= 5) {
|
164
|
+
$max_font = $index if $index > $max_font;
|
165
|
+
|
166
|
+
# Shift index past S::WE fonts
|
167
|
+
$index += 2;
|
168
|
+
}
|
169
|
+
|
170
|
+
$data .= pack 'v', $index;
|
171
|
+
}
|
172
|
+
|
173
|
+
# FONTX, Chart fonts
|
174
|
+
if ($record == 0x1026) {
|
175
|
+
|
176
|
+
my $index = unpack 'v', $data;
|
177
|
+
|
178
|
+
# Ignore the inbuilt fonts.
|
179
|
+
if ($index >= 5) {
|
180
|
+
$max_font = $index if $index > $max_font;
|
181
|
+
|
182
|
+
# Shift index past S::WE fonts
|
183
|
+
$index += 2;
|
184
|
+
}
|
185
|
+
|
186
|
+
$data = pack 'v', $index;
|
187
|
+
}
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
if ($in_chart) {
|
192
|
+
print CHART $header, $data;
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
# EOF
|
197
|
+
if ($record == 0x000A) {
|
198
|
+
$in_chart = 0;
|
199
|
+
$depth_count--;
|
200
|
+
$sheet_index++ if $depth_count == 0;
|
201
|
+
;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
if ($chart_index > 1) {
|
207
|
+
print "\n\n";
|
208
|
+
print "Add the following near the start of your program\n";
|
209
|
+
print "and change the variable names if required.\n\n";
|
210
|
+
}
|
211
|
+
else {
|
212
|
+
print "\nNo charts found in workbook\n";
|
213
|
+
}
|
214
|
+
|
215
|
+
for my $aref (@exrefs) {
|
216
|
+
my $sheet1 = $sheetnames[$aref->[1]];
|
217
|
+
my $sheet2 = $sheetnames[$aref->[2]];
|
218
|
+
|
219
|
+
my $range;
|
220
|
+
|
221
|
+
if ($sheet1 ne $sheet2) {
|
222
|
+
$range = $sheet1 . ":" . $sheet2;
|
223
|
+
}
|
224
|
+
else {
|
225
|
+
$range = $sheet1;
|
226
|
+
}
|
227
|
+
|
228
|
+
$range = "'$range'" if $range =~ /[^\w:]/;
|
229
|
+
|
230
|
+
print " \$worksheet->store_formula('=$range!A1');\n";
|
231
|
+
}
|
232
|
+
|
233
|
+
print "\n";
|
234
|
+
|
235
|
+
for my $i (5 .. $max_font) {
|
236
|
+
|
237
|
+
printf " my \$chart_font_%d = \$workbook->add_format(font_only => 1);\n",
|
238
|
+
$i -4;
|
239
|
+
|
240
|
+
}
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
__END__
|
247
|
+
|
248
|
+
|
249
|
+
=head1 NAME
|
250
|
+
|
251
|
+
chartex - A utility to extract charts from an Excel file for insertion into a Spreadsheet::WriteExcel file.
|
252
|
+
|
253
|
+
=head1 DESCRIPTION
|
254
|
+
|
255
|
+
This program is used for extracting one or more charts from an Excel file in binary format. The charts can then be included in a C<Spreadsheet::WriteExcel> file.
|
256
|
+
|
257
|
+
See the C<add_chart_ext()> section of the Spreadsheet::WriteExcel documentation for more details.
|
258
|
+
|
259
|
+
|
260
|
+
=head1 SYNOPSIS
|
261
|
+
|
262
|
+
chartex [--chartname --help --man] file.xls
|
263
|
+
|
264
|
+
Options:
|
265
|
+
--chartname -c The root name for the extracted charts,
|
266
|
+
defaults to "chart".
|
267
|
+
|
268
|
+
|
269
|
+
=head1 OPTIONS
|
270
|
+
|
271
|
+
=over 4
|
272
|
+
|
273
|
+
=item B<--chartname or -c>
|
274
|
+
|
275
|
+
This sets the root name for the extracted charts, defaults to "chart". For example:
|
276
|
+
|
277
|
+
$ chartex file.xls
|
278
|
+
|
279
|
+
Extracting "Chart1" to chart01.bin
|
280
|
+
|
281
|
+
|
282
|
+
$ chartex -c mychart file.xls
|
283
|
+
|
284
|
+
Extracting "Chart1" to mychart01.bin
|
285
|
+
|
286
|
+
=item B<--help or -h>
|
287
|
+
|
288
|
+
Print a brief help message and exits.
|
289
|
+
|
290
|
+
|
291
|
+
=item B<--man or -m>
|
292
|
+
|
293
|
+
Prints the manual page and exits.
|
294
|
+
|
295
|
+
=back
|
296
|
+
|
297
|
+
|
298
|
+
=head1 AUTHOR
|
299
|
+
|
300
|
+
John McNamara jmcnamara@cpan.org
|
301
|
+
|
302
|
+
|
303
|
+
=head1 VERSION
|
304
|
+
|
305
|
+
Version 0.02.
|
306
|
+
|
307
|
+
|
308
|
+
=head1 COPYRIGHT
|
309
|
+
|
310
|
+
ゥ MMV, John McNamara.
|
311
|
+
|
312
|
+
All Rights Reserved. This program is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.
|
313
|
+
|
314
|
+
|
315
|
+
=cut
|
316
|
+
=end
|