Lines 55-62
Link Here
|
55 |
|
55 |
|
56 |
package org.apache.poi.hssf.record; |
56 |
package org.apache.poi.hssf.record; |
57 |
|
57 |
|
|
|
58 |
import java.io.*; |
59 |
import java.io.UnsupportedEncodingException; |
60 |
|
61 |
import org.apache.poi.util.BinaryTree; |
58 |
import org.apache.poi.util.LittleEndian; |
62 |
import org.apache.poi.util.LittleEndian; |
59 |
import org.apache.poi.util.StringUtil; |
63 |
import org.apache.poi.util.StringUtil; |
|
|
64 |
import sun.awt.image.ByteInterleavedRaster; |
60 |
|
65 |
|
61 |
/** |
66 |
/** |
62 |
* Title: Bound Sheet Record (aka BundleSheet) <P> |
67 |
* Title: Bound Sheet Record (aka BundleSheet) <P> |
Lines 65-70
Link Here
|
65 |
* file. <P> |
70 |
* file. <P> |
66 |
* REFERENCE: PG 291 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> |
71 |
* REFERENCE: PG 291 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> |
67 |
* @author Andrew C. Oliver (acoliver at apache dot org) |
72 |
* @author Andrew C. Oliver (acoliver at apache dot org) |
|
|
73 |
* @author Sergei Kozello (sergeikozello at mail.ru) |
68 |
* @version 2.0-pre |
74 |
* @version 2.0-pre |
69 |
*/ |
75 |
*/ |
70 |
|
76 |
|
Lines 116-133
Link Here
|
116 |
throw new RecordFormatException("NOT A Bound Sheet RECORD"); |
122 |
throw new RecordFormatException("NOT A Bound Sheet RECORD"); |
117 |
} |
123 |
} |
118 |
} |
124 |
} |
|
|
125 |
|
126 |
/** |
127 |
* UTF8: |
128 |
* sid + len + bof + flags + len(str) + unicode + str |
129 |
* 2 + 2 + 4 + 2 + 1 + 1 + len(str) |
130 |
* |
131 |
* UNICODE: |
132 |
* sid + len + bof + flags + len(str) + unicode + str |
133 |
* 2 + 2 + 4 + 2 + 1 + 1 + 2 * len(str) |
134 |
* |
135 |
*/ |
119 |
|
136 |
|
120 |
protected void fillFields(byte [] data, short size, int offset) |
137 |
protected void fillFields(byte [] data, short size, int offset) |
121 |
{ |
138 |
{ |
122 |
field_1_position_of_BOF = LittleEndian.getInt(data, |
139 |
field_1_position_of_BOF = LittleEndian.getInt(data, 0 + offset); // bof |
123 |
0 + offset); |
140 |
field_2_option_flags = LittleEndian.getShort(data, 4 + offset); // flags |
124 |
field_2_option_flags = LittleEndian.getShort(data, |
141 |
field_3_sheetname_length = data[ 6 + offset ]; // len(str) |
125 |
4 + offset); |
142 |
field_4_compressed_unicode_flag = data[ 7 + offset ]; // unicode |
126 |
field_3_sheetname_length = data[ 6 + offset ]; |
143 |
|
127 |
field_4_compressed_unicode_flag = data[ 7 + offset ]; |
144 |
int nameLength = LittleEndian.ubyteToInt( field_3_sheetname_length ); |
128 |
field_5_sheetname = new String(data, 8 + offset, |
145 |
if ( ( field_4_compressed_unicode_flag & 0x01 ) == 1 ) { |
129 |
LittleEndian.ubyteToInt( field_3_sheetname_length)); |
146 |
field_5_sheetname = StringUtil.getFromUnicodeHigh( data, 8 + offset, nameLength ); |
130 |
} |
147 |
} |
|
|
148 |
else { |
149 |
field_5_sheetname = new String( data, 8 + offset, nameLength ); |
150 |
} |
151 |
} |
131 |
|
152 |
|
132 |
/** |
153 |
/** |
133 |
* set the offset in bytes of the Beginning of File Marker within the HSSF Stream part of the POIFS file |
154 |
* set the offset in bytes of the Beginning of File Marker within the HSSF Stream part of the POIFS file |
Lines 169-175
Link Here
|
169 |
* @param flag (0/1) 0- compressed, 1 - uncompressed (16-bit) |
190 |
* @param flag (0/1) 0- compressed, 1 - uncompressed (16-bit) |
170 |
*/ |
191 |
*/ |
171 |
|
192 |
|
172 |
public void setCompressedUnicodeFlag(byte flag) |
193 |
public void setCompressedUnicodeFlag( byte flag ) |
173 |
{ |
194 |
{ |
174 |
field_4_compressed_unicode_flag = flag; |
195 |
field_4_compressed_unicode_flag = flag; |
175 |
} |
196 |
} |
Lines 178-185
Link Here
|
178 |
* Set the sheetname for this sheet. (this appears in the tabs at the bottom) |
199 |
* Set the sheetname for this sheet. (this appears in the tabs at the bottom) |
179 |
* @param sheetname the name of the sheet |
200 |
* @param sheetname the name of the sheet |
180 |
*/ |
201 |
*/ |
181 |
|
202 |
|
182 |
public void setSheetname(String sheetname) |
203 |
public void setSheetname( String sheetname ) |
183 |
{ |
204 |
{ |
184 |
field_5_sheetname = sheetname; |
205 |
field_5_sheetname = sheetname; |
185 |
} |
206 |
} |
Lines 215-221
Link Here
|
215 |
|
236 |
|
216 |
public byte getSheetnameLength() |
237 |
public byte getSheetnameLength() |
217 |
{ |
238 |
{ |
218 |
return field_3_sheetname_length; |
239 |
return field_3_sheetname_length; |
|
|
240 |
} |
241 |
|
242 |
/** |
243 |
* get the length of the raw sheetname in characters |
244 |
* the length depends on the unicode flag |
245 |
* |
246 |
* @return number of characters in the raw sheet name |
247 |
*/ |
248 |
|
249 |
public byte getRawSheetnameLength() |
250 |
{ |
251 |
return (byte)( ( ( field_4_compressed_unicode_flag & 0x01 ) == 1 ) |
252 |
? 2 * field_3_sheetname_length |
253 |
: field_3_sheetname_length ); |
219 |
} |
254 |
} |
220 |
|
255 |
|
221 |
/** |
256 |
/** |
Lines 262-283
Link Here
|
262 |
public int serialize(int offset, byte [] data) |
297 |
public int serialize(int offset, byte [] data) |
263 |
{ |
298 |
{ |
264 |
LittleEndian.putShort(data, 0 + offset, sid); |
299 |
LittleEndian.putShort(data, 0 + offset, sid); |
265 |
LittleEndian.putShort(data, 2 + offset, |
300 |
LittleEndian.putShort( data, 2 + offset, (short)( 8 + getRawSheetnameLength() ) ); |
266 |
( short ) (0x08 + getSheetnameLength())); |
|
|
267 |
LittleEndian.putInt(data, 4 + offset, getPositionOfBof()); |
301 |
LittleEndian.putInt(data, 4 + offset, getPositionOfBof()); |
268 |
LittleEndian.putShort(data, 8 + offset, getOptionFlags()); |
302 |
LittleEndian.putShort(data, 8 + offset, getOptionFlags()); |
269 |
data[ 10 + offset ] = getSheetnameLength(); |
303 |
data[ 10 + offset ] = (byte)( getSheetnameLength() ); |
270 |
data[ 11 + offset ] = getCompressedUnicodeFlag(); |
304 |
data[ 11 + offset ] = getCompressedUnicodeFlag(); |
|
|
305 |
|
306 |
if ( ( field_4_compressed_unicode_flag & 0x01 ) == 1 ) |
307 |
StringUtil.putUncompressedUnicode( getSheetname(), data, 12 + offset ); |
308 |
else |
309 |
StringUtil.putCompressedUnicode( getSheetname(), data, 12 + offset ); |
310 |
|
271 |
|
311 |
|
272 |
// we assume compressed unicode (bein the dern americans we are ;-p) |
|
|
273 |
StringUtil.putCompressedUnicode(getSheetname(), data, 12 + offset); |
274 |
return getRecordSize(); |
312 |
return getRecordSize(); |
|
|
313 |
|
314 |
/* |
315 |
byte[] fake = new byte[] { (byte)0x85, 0x00, // sid |
316 |
0x1a, 0x00, // length |
317 |
0x3C, 0x09, 0x00, 0x00, // bof |
318 |
0x00, 0x00, // flags |
319 |
0x09, // len( str ) |
320 |
0x01, // unicode |
321 |
// <str> |
322 |
0x21, 0x04, 0x42, 0x04, 0x40, 0x04, 0x30, 0x04, 0x3D, |
323 |
0x04, 0x38, 0x04, 0x47, 0x04, 0x3A, 0x04, 0x30, 0x04 |
324 |
// </str> |
325 |
}; |
326 |
|
327 |
sid + len + bof + flags + len(str) + unicode + str |
328 |
2 + 2 + 4 + 2 + 1 + 1 + len(str) |
329 |
|
330 |
System.arraycopy( fake, 0, data, offset, fake.length ); |
331 |
|
332 |
return fake.length; |
333 |
*/ |
275 |
} |
334 |
} |
276 |
|
335 |
|
277 |
public int getRecordSize() |
336 |
public int getRecordSize() |
278 |
{ |
337 |
{ |
279 |
return 12 + getSheetnameLength(); |
338 |
// return 30; |
280 |
} |
339 |
return 12 + getRawSheetnameLength(); |
|
|
340 |
} |
281 |
|
341 |
|
282 |
public short getSid() |
342 |
public short getSid() |
283 |
{ |
343 |
{ |