1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.office.excel.versions.biff8;
22
23 import org.millscript.office.excel.BIFFRecordInputStream;
24 import org.millscript.office.excel.RecordParser;
25 import org.millscript.office.excel.records.substructures.CellRangeAddress;
26 import org.millscript.office.excel.records.substructures.ConstantCachedValue;
27 import org.millscript.office.excel.records.substructures.FormattingRun;
28 import org.millscript.office.excel.versions.BIFFVersion;
29 import org.millscript.office.excel.versions.biff7.Biff7RecordTokenizer;
30 import org.millscript.office.spreadsheet.formula.AbsoluteCellAddress;
31 import org.millscript.office.spreadsheet.formula.OffsetCellAddress;
32
33 /**
34 *
35 */
36 public class Biff8RecordTokenizer extends Biff7RecordTokenizer {
37
38 /**
39 * @param version
40 * @param bis
41 */
42 public Biff8RecordTokenizer( final BIFFVersion version, final BIFFRecordInputStream bis, final byte[] bofData ) {
43 super( version, bis, bofData );
44 }
45
46 /**
47 * @see org.millscript.office.excel.versions.biff7.Biff7RecordTokenizer#getRecordParser()
48 */
49 @Override
50 public RecordParser getRecordParser() {
51 return new BIFF8RecordParser( this );
52 }
53
54 /**
55 * @see org.millscript.office.excel.RecordTokenizer#readAbsoluteCellAddress()
56 */
57 @Override
58 public AbsoluteCellAddress readAbsoluteCellAddress() {
59 final int rowIndex = this.read2ByteChar() + 1;
60 final char colIndexWithRelativeFlags = this.read2ByteChar();
61
62 return new AbsoluteCellAddress(
63
64 rowIndex,
65
66 ( 0 != ( colIndexWithRelativeFlags & 0x8000 ) ),
67
68 ( ( colIndexWithRelativeFlags & 0x00FF ) + 1 ),
69
70 ( 0 != ( colIndexWithRelativeFlags & 0x4000 ) )
71 );
72 }
73
74 /**
75 * @see org.millscript.office.excel.RecordTokenizer#readCellRangeAddress()
76 */
77 @Override
78 public CellRangeAddress readCellRangeAddress() {
79
80 return new CellRangeAddress(
81 this.readUnsigned2Byte(),
82 this.readUnsigned2Byte(),
83 this.readUnsigned2Byte(),
84 this.readUnsigned2Byte()
85 );
86 }
87
88 /**
89 * @see org.millscript.office.excel.RecordTokenizer#readConstantCachedValueArray()
90 */
91 @Override
92 public ConstantCachedValue[] readConstantCachedValueArray() {
93 return this.readConstantCachedValues(
94 ( this.readUnsignedByte() + 1 ) * ( this.readUnsigned2Byte() + 1 )
95 );
96 }
97
98 /**
99 * @see org.millscript.office.excel.RecordTokenizer#readFormattingRun()
100 */
101 @Override
102 public FormattingRun readFormattingRun() {
103 return new FormattingRun(
104 this.read2ByteInt(),
105 this.read2ByteInt()
106 );
107 }
108
109 /**
110 * @see org.millscript.office.excel.RecordTokenizer#readOffsetCellAddress()
111 */
112 @Override
113 public OffsetCellAddress readOffsetCellAddress() {
114 int rowIndex = this.read2ByteInt();
115 final char colIndexWithRelativeFlags = this.read2ByteChar();
116 final boolean columnIndexIsOffet = ( 0 != ( colIndexWithRelativeFlags & 0x4000 ) );
117 final boolean rowIndexIsOffet = ( 0 != ( colIndexWithRelativeFlags & 0x8000 ) );
118 int columnIndex = 0;
119 if ( columnIndexIsOffet ) {
120
121 columnIndex = ( colIndexWithRelativeFlags & 0x00FF ) | 0xFF00;
122 } else {
123
124 columnIndex = ( colIndexWithRelativeFlags & 0x00FF ) + 1;
125 }
126 if ( ! rowIndexIsOffet ) {
127
128 rowIndex = ( rowIndex & 0xFFFF ) + 1;
129 }
130
131 return new OffsetCellAddress(
132
133 rowIndex,
134
135 rowIndexIsOffet,
136
137 columnIndex,
138
139 columnIndexIsOffet
140 );
141 }
142
143 /**
144 * @see org.millscript.office.excel.RecordTokenizer#readString(int)
145 */
146 @Override
147 public String readString( final int length ) {
148
149
150 return this.readUnicodeString( length );
151 }
152
153 }