writeexcel 0.1.0 → 0.3.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.
- data/README +26 -31
- data/examples/a_simple.rb +42 -42
- data/examples/{autofilters.rb → autofilter.rb} +264 -266
- data/examples/bigfile.rb +29 -0
- data/examples/chart_area.rb +120 -0
- data/examples/chart_bar.rb +119 -0
- data/examples/chart_column.rb +119 -0
- data/examples/chart_line.rb +119 -0
- data/examples/chart_pie.rb +107 -0
- data/examples/chart_scatter.rb +120 -0
- data/examples/chart_stock.rb +147 -0
- data/examples/copyformat.rb +51 -51
- data/examples/data_validate.rb +278 -278
- data/examples/date_time.rb +86 -86
- data/examples/defined_name.rb +31 -0
- data/examples/demo.rb +120 -118
- data/examples/diag_border.rb +35 -35
- data/examples/formats.rb +489 -489
- data/examples/header.rb +136 -136
- data/examples/hidden.rb +28 -28
- data/examples/hyperlink.rb +42 -42
- data/examples/images.rb +52 -52
- data/examples/merge1.rb +39 -39
- data/examples/merge2.rb +44 -44
- data/examples/merge3.rb +65 -65
- data/examples/merge4.rb +82 -82
- data/examples/merge5.rb +79 -79
- data/examples/properties.rb +33 -0
- data/examples/properties_jp.rb +32 -0
- data/examples/protection.rb +46 -46
- data/examples/regions.rb +52 -52
- data/examples/repeat.rb +42 -42
- data/examples/stats.rb +75 -75
- data/examples/stocks.rb +80 -80
- data/examples/tab_colors.rb +30 -30
- data/examples/write_arrays.rb +82 -0
- data/lib/writeexcel.rb +1134 -18
- data/lib/writeexcel/biffwriter.rb +273 -260
- data/lib/writeexcel/chart.rb +2306 -217
- data/lib/writeexcel/charts/area.rb +152 -0
- data/lib/writeexcel/charts/bar.rb +177 -0
- data/lib/writeexcel/charts/column.rb +156 -0
- data/lib/writeexcel/charts/external.rb +61 -0
- data/lib/writeexcel/charts/line.rb +152 -0
- data/lib/writeexcel/charts/pie.rb +169 -0
- data/lib/writeexcel/charts/scatter.rb +192 -0
- data/lib/writeexcel/charts/stock.rb +211 -0
- data/lib/writeexcel/excelformulaparser.rb +208 -195
- data/lib/writeexcel/format.rb +1697 -1108
- data/lib/writeexcel/formula.rb +1050 -986
- data/lib/writeexcel/olewriter.rb +322 -322
- data/lib/writeexcel/properties.rb +251 -250
- data/lib/writeexcel/storage_lite.rb +968 -0
- data/lib/writeexcel/workbook.rb +3294 -2630
- data/lib/writeexcel/worksheet.rb +9012 -6377
- 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/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/a_simple.xls +0 -0
- data/test/perl_output/autofilter.xls +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/data_validate.xls +0 -0
- data/test/perl_output/date_time.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/headers.xls +0 -0
- data/test/perl_output/hyperlink.xls +0 -0
- data/test/perl_output/images.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/protection.xls +0 -0
- data/test/perl_output/regions.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/workbook1.xls +0 -0
- data/test/perl_output/workbook2.xls +0 -0
- data/test/tc_all.rb +32 -31
- data/test/tc_biff.rb +104 -104
- data/test/tc_chart.rb +22 -22
- data/test/tc_example_match.rb +1944 -1280
- data/test/tc_format.rb +1254 -1267
- data/test/tc_formula.rb +63 -63
- data/test/tc_ole.rb +110 -110
- data/test/tc_storage_lite.rb +149 -0
- data/test/tc_workbook.rb +140 -115
- data/test/tc_worksheet.rb +115 -115
- data/test/test_00_IEEE_double.rb +14 -14
- data/test/test_01_add_worksheet.rb +12 -12
- data/test/test_02_merge_formats.rb +58 -58
- data/test/test_04_dimensions.rb +397 -397
- data/test/test_05_rows.rb +182 -182
- data/test/test_06_extsst.rb +80 -80
- data/test/test_11_date_time.rb +484 -484
- data/test/test_12_date_only.rb +506 -506
- data/test/test_13_date_seconds.rb +486 -486
- data/test/test_21_escher.rb +642 -629
- data/test/test_22_mso_drawing_group.rb +750 -739
- data/test/test_23_note.rb +78 -78
- data/test/test_24_txo.rb +80 -80
- data/test/test_25_position_object.rb +82 -0
- data/test/test_26_autofilter.rb +327 -327
- data/test/test_27_autofilter.rb +144 -144
- data/test/test_28_autofilter.rb +174 -174
- data/test/test_29_process_jpg.rb +681 -131
- data/test/test_30_validation_dval.rb +82 -82
- data/test/test_31_validation_dv_strings.rb +131 -131
- data/test/test_32_validation_dv_formula.rb +211 -211
- data/test/test_40_property_types.rb +191 -191
- data/test/test_41_properties.rb +238 -238
- data/test/test_42_set_properties.rb +442 -419
- data/test/test_50_name_stored.rb +305 -0
- data/test/test_51_name_print_area.rb +363 -0
- data/test/test_52_name_print_titles.rb +460 -0
- data/test/test_53_autofilter.rb +209 -0
- data/test/test_60_chart_generic.rb +576 -0
- data/test/test_61_chart_subclasses.rb +97 -0
- data/test/test_62_chart_formats.rb +270 -0
- data/test/test_63_chart_area_formats.rb +647 -0
- data/test/test_chartex.rb +35 -0
- data/test/ts_all.rb +46 -34
- data/writeexcel.gemspec +18 -0
- data/writeexcel.rdoc +583 -0
- metadata +162 -108
@@ -1,260 +1,273 @@
|
|
1
|
-
#
|
2
|
-
# BIFFwriter - An abstract base class for Excel workbooks and worksheets.
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# Used in conjunction with
|
6
|
-
#
|
7
|
-
# Copyright 2000-
|
8
|
-
#
|
9
|
-
# original written in Perl by John McNamara
|
10
|
-
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
require 'tempfile'
|
15
|
-
|
16
|
-
class BIFFWriter
|
17
|
-
|
18
|
-
BIFF_Version = 0x0600
|
19
|
-
BigEndian = [1].pack("I") == [1].pack("N")
|
20
|
-
|
21
|
-
attr_reader :byte_order, :data, :datasize
|
22
|
-
|
23
|
-
######################################################################
|
24
|
-
# The args here aren't used by BIFFWriter, but they are needed by its
|
25
|
-
# subclasses. I don't feel like creating multiple constructors.
|
26
|
-
######################################################################
|
27
|
-
|
28
|
-
def initialize
|
29
|
-
set_byte_order
|
30
|
-
@data = ''
|
31
|
-
@datasize = 0
|
32
|
-
@limit = 8224
|
33
|
-
@ignore_continue = 0
|
34
|
-
|
35
|
-
# Open a tmp file to store the majority of the Worksheet data. If this fails,
|
36
|
-
# for example due to write permissions, store the data in memory. This can be
|
37
|
-
# slow for large files.
|
38
|
-
@filehandle = Tempfile.new('spreadsheetwriteexcel')
|
39
|
-
@filehandle.binmode
|
40
|
-
|
41
|
-
# failed. store temporary data in memory.
|
42
|
-
@using_tmpfile = @filehandle ? true : false
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
###############################################################################
|
47
|
-
#
|
48
|
-
# _set_byte_order()
|
49
|
-
#
|
50
|
-
# Determine the byte order and store it as class data to avoid
|
51
|
-
# recalculating it for each call to new().
|
52
|
-
#
|
53
|
-
def set_byte_order
|
54
|
-
# Check if "pack" gives the required IEEE 64bit float
|
55
|
-
teststr = [1.2345].pack("d")
|
56
|
-
hexdata = [0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F]
|
57
|
-
number = hexdata.pack("C8")
|
58
|
-
|
59
|
-
if number == teststr
|
60
|
-
@byte_order = 0 # Little Endian
|
61
|
-
elsif number == teststr.reverse
|
62
|
-
@byte_order = 1 # Big Endian
|
63
|
-
else
|
64
|
-
# Give up. I'll fix this in a later version.
|
65
|
-
raise( "Required floating point format not supported " +
|
66
|
-
"on this platform. See the portability section " +
|
67
|
-
"of the documentation."
|
68
|
-
)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
###############################################################################
|
73
|
-
#
|
74
|
-
# _prepend($data)
|
75
|
-
#
|
76
|
-
# General storage function
|
77
|
-
#
|
78
|
-
def prepend(*args)
|
79
|
-
d = args.join
|
80
|
-
d = add_continue(d) if d.length > @limit
|
81
|
-
|
82
|
-
@datasize += d.length
|
83
|
-
@data = d + @data
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
return d
|
88
|
-
end
|
89
|
-
|
90
|
-
###############################################################################
|
91
|
-
#
|
92
|
-
# _append($data)
|
93
|
-
#
|
94
|
-
# General storage function
|
95
|
-
#
|
96
|
-
def append(*args)
|
97
|
-
d = args.join
|
98
|
-
# Add CONTINUE records if necessary
|
99
|
-
d = add_continue(d) if d.length > @limit
|
100
|
-
if @using_tmpfile
|
101
|
-
@filehandle.write d
|
102
|
-
@datasize += d.length
|
103
|
-
else
|
104
|
-
@datasize += d.length
|
105
|
-
@data = @data + d
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
@data
|
126
|
-
|
127
|
-
|
128
|
-
@filehandle.
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
return
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
#
|
145
|
-
#
|
146
|
-
#
|
147
|
-
# $type =
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
#
|
157
|
-
|
158
|
-
#
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
#
|
176
|
-
#
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
#
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
#
|
207
|
-
|
208
|
-
|
209
|
-
#
|
210
|
-
#
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
#
|
241
|
-
#
|
242
|
-
#
|
243
|
-
#
|
244
|
-
#
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
1
|
+
#
|
2
|
+
# BIFFwriter - An abstract base class for Excel workbooks and worksheets.
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# Used in conjunction with WriteExcel
|
6
|
+
#
|
7
|
+
# Copyright 2000-2010, John McNamara, jmcnamara@cpan.org
|
8
|
+
#
|
9
|
+
# original written in Perl by John McNamara
|
10
|
+
# converted to Ruby by Hideo Nakamura, cxn03651@msj.biglobe.ne.jp
|
11
|
+
#
|
12
|
+
|
13
|
+
|
14
|
+
require 'tempfile'
|
15
|
+
|
16
|
+
class BIFFWriter #:nodoc:
|
17
|
+
|
18
|
+
BIFF_Version = 0x0600
|
19
|
+
BigEndian = [1].pack("I") == [1].pack("N")
|
20
|
+
|
21
|
+
attr_reader :byte_order, :data, :datasize
|
22
|
+
|
23
|
+
######################################################################
|
24
|
+
# The args here aren't used by BIFFWriter, but they are needed by its
|
25
|
+
# subclasses. I don't feel like creating multiple constructors.
|
26
|
+
######################################################################
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
set_byte_order
|
30
|
+
@data = ''
|
31
|
+
@datasize = 0
|
32
|
+
@limit = 8224
|
33
|
+
@ignore_continue = 0
|
34
|
+
|
35
|
+
# Open a tmp file to store the majority of the Worksheet data. If this fails,
|
36
|
+
# for example due to write permissions, store the data in memory. This can be
|
37
|
+
# slow for large files.
|
38
|
+
@filehandle = Tempfile.new('spreadsheetwriteexcel')
|
39
|
+
@filehandle.binmode
|
40
|
+
|
41
|
+
# failed. store temporary data in memory.
|
42
|
+
@using_tmpfile = @filehandle ? true : false
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
###############################################################################
|
47
|
+
#
|
48
|
+
# _set_byte_order()
|
49
|
+
#
|
50
|
+
# Determine the byte order and store it as class data to avoid
|
51
|
+
# recalculating it for each call to new().
|
52
|
+
#
|
53
|
+
def set_byte_order
|
54
|
+
# Check if "pack" gives the required IEEE 64bit float
|
55
|
+
teststr = [1.2345].pack("d")
|
56
|
+
hexdata = [0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F]
|
57
|
+
number = hexdata.pack("C8")
|
58
|
+
|
59
|
+
if number == teststr
|
60
|
+
@byte_order = 0 # Little Endian
|
61
|
+
elsif number == teststr.reverse
|
62
|
+
@byte_order = 1 # Big Endian
|
63
|
+
else
|
64
|
+
# Give up. I'll fix this in a later version.
|
65
|
+
raise( "Required floating point format not supported " +
|
66
|
+
"on this platform. See the portability section " +
|
67
|
+
"of the documentation."
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
###############################################################################
|
73
|
+
#
|
74
|
+
# _prepend($data)
|
75
|
+
#
|
76
|
+
# General storage function
|
77
|
+
#
|
78
|
+
def prepend(*args)
|
79
|
+
d = args.join
|
80
|
+
d = add_continue(d) if d.length > @limit
|
81
|
+
|
82
|
+
@datasize += d.length
|
83
|
+
@data = d + @data
|
84
|
+
|
85
|
+
print "prepend\n" if defined?($debug)
|
86
|
+
print d.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ') + "\n\n" if defined?($debug)
|
87
|
+
return d
|
88
|
+
end
|
89
|
+
|
90
|
+
###############################################################################
|
91
|
+
#
|
92
|
+
# _append($data)
|
93
|
+
#
|
94
|
+
# General storage function
|
95
|
+
#
|
96
|
+
def append(*args)
|
97
|
+
d = args.join
|
98
|
+
# Add CONTINUE records if necessary
|
99
|
+
d = add_continue(d) if d.length > @limit
|
100
|
+
if @using_tmpfile
|
101
|
+
@filehandle.write d
|
102
|
+
@datasize += d.length
|
103
|
+
else
|
104
|
+
@datasize += d.length
|
105
|
+
@data = @data + d
|
106
|
+
end
|
107
|
+
|
108
|
+
print "append\n" if defined?($debug)
|
109
|
+
print d.unpack('C*').map! {|c| sprintf("%02X", c) }.join(' ') + "\n\n" if defined?($debug)
|
110
|
+
return d
|
111
|
+
end
|
112
|
+
|
113
|
+
###############################################################################
|
114
|
+
#
|
115
|
+
# get_data().
|
116
|
+
#
|
117
|
+
# Retrieves data from memory in one chunk, or from disk in $buffer
|
118
|
+
# sized chunks.
|
119
|
+
#
|
120
|
+
def get_data
|
121
|
+
buflen = 4096
|
122
|
+
|
123
|
+
# Return data stored in memory
|
124
|
+
unless @data.nil?
|
125
|
+
tmp = @data
|
126
|
+
@data = nil
|
127
|
+
if @using_tmpfile
|
128
|
+
@filehandle.open
|
129
|
+
@filehandle.binmode
|
130
|
+
end
|
131
|
+
return tmp
|
132
|
+
end
|
133
|
+
|
134
|
+
# Return data stored on disk
|
135
|
+
if @using_tmpfile
|
136
|
+
return @filehandle.read(buflen)
|
137
|
+
end
|
138
|
+
|
139
|
+
# No data to return
|
140
|
+
return nil
|
141
|
+
end
|
142
|
+
|
143
|
+
###############################################################################
|
144
|
+
#
|
145
|
+
# _store_bof($type)
|
146
|
+
#
|
147
|
+
# $type = 0x0005, Workbook
|
148
|
+
# $type = 0x0010, Worksheet
|
149
|
+
# $type = 0x0020, Chart
|
150
|
+
#
|
151
|
+
# Writes Excel BOF record to indicate the beginning of a stream or
|
152
|
+
# sub-stream in the BIFF file.
|
153
|
+
#
|
154
|
+
def store_bof(type = 0x0005)
|
155
|
+
record = 0x0809 # Record identifier
|
156
|
+
length = 0x0010 # Number of bytes to follow
|
157
|
+
|
158
|
+
# According to the SDK $build and $year should be set to zero.
|
159
|
+
# However, this throws a warning in Excel 5. So, use these
|
160
|
+
# magic numbers.
|
161
|
+
build = 0x0DBB
|
162
|
+
year = 0x07CC
|
163
|
+
|
164
|
+
bfh = 0x00000041
|
165
|
+
sfo = 0x00000006
|
166
|
+
|
167
|
+
header = [record,length].pack("vv")
|
168
|
+
data = [BIFF_Version,type,build,year,bfh,sfo].pack("vvvvVV")
|
169
|
+
|
170
|
+
print "store_bof in #{__FILE__}\n" if defined?($debug)
|
171
|
+
prepend(header, data)
|
172
|
+
end
|
173
|
+
|
174
|
+
###############################################################################
|
175
|
+
#
|
176
|
+
# _store_eof()
|
177
|
+
#
|
178
|
+
# Writes Excel EOF record to indicate the end of a BIFF stream.
|
179
|
+
#
|
180
|
+
def store_eof
|
181
|
+
record = 0x000A
|
182
|
+
length = 0x0000
|
183
|
+
header = [record,length].pack("vv")
|
184
|
+
|
185
|
+
print "store_eof in #{__FILE__}\n" if defined?($debug)
|
186
|
+
append(header)
|
187
|
+
end
|
188
|
+
|
189
|
+
###############################################################################
|
190
|
+
#
|
191
|
+
# _add_continue()
|
192
|
+
#
|
193
|
+
# Excel limits the size of BIFF records. In Excel 5 the limit is 2084 bytes. In
|
194
|
+
# Excel 97 the limit is 8228 bytes. Records that are longer than these limits
|
195
|
+
# must be split up into CONTINUE blocks.
|
196
|
+
#
|
197
|
+
# This function take a long BIFF record and inserts CONTINUE records as
|
198
|
+
# necessary.
|
199
|
+
#
|
200
|
+
# Some records have their own specialised Continue blocks so there is also an
|
201
|
+
# option to bypass this function.
|
202
|
+
#
|
203
|
+
def add_continue(data)
|
204
|
+
record = 0x003C # Record identifier
|
205
|
+
|
206
|
+
# Skip this if another method handles the continue blocks.
|
207
|
+
return data if @ignore_continue != 0
|
208
|
+
|
209
|
+
# The first 2080/8224 bytes remain intact. However, we have to change
|
210
|
+
# the length field of the record.
|
211
|
+
#
|
212
|
+
|
213
|
+
# in perl
|
214
|
+
# $tmp = substr($data, 0, $limit, "");
|
215
|
+
if data.length > @limit
|
216
|
+
tmp = data[0, @limit]
|
217
|
+
data[0, @limit] = ''
|
218
|
+
else
|
219
|
+
tmp = data.dup
|
220
|
+
data = ''
|
221
|
+
end
|
222
|
+
|
223
|
+
tmp[2, 2] = [@limit-4].pack('v')
|
224
|
+
|
225
|
+
# Strip out chunks of 2080/8224 bytes +4 for the header.
|
226
|
+
while (data.length > @limit)
|
227
|
+
header = [record, @limit].pack("vv")
|
228
|
+
tmp = tmp + header + data[0, @limit]
|
229
|
+
data[0, @limit] = ''
|
230
|
+
end
|
231
|
+
|
232
|
+
# Mop up the last of the data
|
233
|
+
header = [record, data.length].pack("vv")
|
234
|
+
tmp = tmp + header + data
|
235
|
+
|
236
|
+
return tmp
|
237
|
+
end
|
238
|
+
|
239
|
+
###############################################################################
|
240
|
+
#
|
241
|
+
# _add_mso_generic()
|
242
|
+
# my $type = $_[0];
|
243
|
+
# my $version = $_[1];
|
244
|
+
# my $instance = $_[2];
|
245
|
+
# my $data = $_[3];
|
246
|
+
#
|
247
|
+
# Create a mso structure that is part of an Escher drawing object. These are
|
248
|
+
# are used for images, comments and filters. This generic method is used by
|
249
|
+
# other methods to create specific mso records.
|
250
|
+
#
|
251
|
+
# Returns the packed record.
|
252
|
+
#
|
253
|
+
def add_mso_generic(type, version, instance, data, length = nil)
|
254
|
+
length = length.nil? ? data.length : length
|
255
|
+
|
256
|
+
# The header contains version and instance info packed into 2 bytes.
|
257
|
+
header = version | (instance << 4)
|
258
|
+
|
259
|
+
record = [header, type, length].pack('vvV') + data
|
260
|
+
|
261
|
+
return record
|
262
|
+
end
|
263
|
+
|
264
|
+
def not_using_tmpfile
|
265
|
+
@filehandle.close(true) if @filehandle
|
266
|
+
@filehandle = nil
|
267
|
+
@using_tmpfile = nil
|
268
|
+
end
|
269
|
+
|
270
|
+
def clear_data_for_test # :nodoc:
|
271
|
+
@data = ''
|
272
|
+
end
|
273
|
+
end
|