1 /
55
56 package org.apache.poi.hssf.model;
57
58 import java.io.*;
59
60 import java.util.ArrayList;
61 import java.util.List;
62 import java.util.Iterator;
63
64 import org.apache.poi.hssf.record.*;
65 import org.apache.poi.util.POILogger;
66 import org.apache.poi.util.POILogFactory;
67
68
87
88 public class Workbook {
89 private static final int DEBUG = POILogger.DEBUG;
90
91
95
96 private final static short CODEPAGE = ( short ) 0x4b0;
97
98
101
102 protected ArrayList records = null;
103
104
108
109 protected SSTRecord sst = null;
110
111
114
115 protected ExternSheetRecord externSheet= null;
116
117
121
122
123 protected ArrayList boundsheets = new ArrayList();
124
125 protected ArrayList names = new ArrayList();
126
127 protected int bspos =
128 0;
129 protected int tabpos =
130 0;
131 protected int fontpos =
132 0;
133 protected int numfonts =
134 0;
135 protected int xfpos =
136 0;
137 protected int numxfs =
138 0;
139 private int backuppos =
140 0;
141 private int namepos =
142 0;
143 private int supbookpos =
144 0;
145
146 private static POILogger log =
147 POILogFactory.getLogger(Workbook.class);
148
149
153
154 public Workbook() {
155 }
156
157
169
170 public static Workbook createWorkbook(List recs) {
171 log.log(DEBUG, "Workbook (readfile) created with reclen=",
172 new Integer(recs.size()));
173 Workbook retval = new Workbook();
174 ArrayList records = new ArrayList(recs.size() / 3);
175
176 for (int k = 0; k < recs.size(); k++) {
177 Record rec = ( Record ) recs.get(k);
178
179 if (rec.getSid() == EOFRecord.sid) {
180 records.add(rec);
181 log.log(DEBUG, "found workbook eof record at " + k);
182 break;
183 }
184 switch (rec.getSid()) {
185
186 case BoundSheetRecord.sid :
187 log.log(DEBUG, "found boundsheet record at " + k);
188 retval.boundsheets.add(rec);
189 retval.bspos = k;
190 break;
191
192 case SSTRecord.sid :
193 log.log(DEBUG, "found sst record at " + k);
194 retval.sst = ( SSTRecord ) rec;
195 break;
196
197 case FontRecord.sid :
198 log.log(DEBUG, "found font record at " + k);
199 retval.fontpos = k;
200 retval.numfonts++;
201 break;
202
203 case ExtendedFormatRecord.sid :
204 log.log(DEBUG, "found XF record at " + k);
205 retval.xfpos = k;
206 retval.numxfs++;
207 break;
208
209 case TabIdRecord.sid :
210 log.log(DEBUG, "found tabid record at " + k);
211 retval.tabpos = k;
212 break;
213
214 case BackupRecord.sid :
215 log.log(DEBUG, "found backup record at " + k);
216 retval.backuppos = k;
217 break;
218 case ExternSheetRecord.sid :
219 log.log(DEBUG, "found extern sheet record at " + k);
220 retval.externSheet = ( ExternSheetRecord ) rec;
221 break;
222 case NameRecord.sid :
223 log.log(DEBUG, "found name record at " + k);
224 retval.names.add(rec);
225 retval.namepos = k;
226 break;
227 case 0x1AE :
228
229
230 log.log(DEBUG, "found SupBook record at " + k);
231 retval.supbookpos = k;
232 break;
233
234 default :
235 }
236 records.add(rec);
237 }
238
239 if (retval.supbookpos == 0) {
240 retval.supbookpos = retval.bspos + 1;
241 retval.namepos = retval.supbookpos + 1;
242 }
243
244 retval.records = records;
245 log.log(DEBUG, "exit create workbook from existing file function");
246 return retval;
247 }
248
249
253
254 public static Workbook createWorkbook() {
255 log.log(DEBUG, "creating new workbook from scratch");
256 Workbook retval = new Workbook();
257 ArrayList records = new ArrayList(30);
258
259 records.add(retval.createBOF());
260 records.add(retval.createInterfaceHdr());
261 records.add(retval.createMMS());
262 records.add(retval.createInterfaceEnd());
263 records.add(retval.createWriteAccess());
264 records.add(retval.createCodepage());
265 records.add(retval.createDSF());
266 records.add(retval.createTabId());
267 retval.tabpos = records.size() - 1;
268 records.add(retval.createFnGroupCount());
269 records.add(retval.createWindowProtect());
270 records.add(retval.createProtect());
271 records.add(retval.createPassword());
272 records.add(retval.createProtectionRev4());
273 records.add(retval.createPasswordRev4());
274 records.add(retval.createWindowOne());
275 records.add(retval.createBackup());
276 retval.backuppos = records.size() - 1;
277 records.add(retval.createHideObj());
278 records.add(retval.createDateWindow1904());
279 records.add(retval.createPrecision());
280 records.add(retval.createRefreshAll());
281 records.add(retval.createBookBool());
282 records.add(retval.createFont());
283 records.add(retval.createFont());
284 records.add(retval.createFont());
285 records.add(retval.createFont());
286 retval.fontpos = records.size() - 1;
287 retval.numfonts = 4;
288 records.add(retval.createFormat(0));
289 records.add(retval.createFormat(1));
290 records.add(retval.createFormat(2));
291 records.add(retval.createFormat(3));
292 records.add(retval.createFormat(4));
293 records.add(retval.createFormat(5));
294 records.add(retval.createFormat(6));
295 records.add(retval.createFormat(7));
296 for (int k = 0; k < 21; k++) {
297 records.add(retval.createExtendedFormat(k));
298 retval.numxfs++;
299 }
300 retval.xfpos = records.size() - 1;
301 for (int k = 0; k < 6; k++) {
302 records.add(retval.createStyle(k));
303 }
304 records.add(retval.createUseSelFS());
305 for (int k = 0; k < 1; k++) {
306 BoundSheetRecord bsr =
307 ( BoundSheetRecord ) retval.createBoundSheet(k);
308
309 records.add(bsr);
310 retval.boundsheets.add(bsr);
311 retval.bspos = records.size() - 1;
312 }
313 records.add(retval.createCountry());
314 retval.sst = ( SSTRecord ) retval.createSST();
315 records.add(retval.sst);
316 records.add(retval.createExtendedSST());
317
318
319 records.add(retval.createEOF());
320 retval.records = records;
321 log.log(DEBUG, "exit create new workbook from scratch");
322 return retval;
323 }
324
325 public int getNumRecords() {
326 return records.size();
327 }
328
329
337
338 public FontRecord getFontRecordAt(int idx) {
339 int index = idx;
340
341 if (index > 4) {
342 index -= 1;
343 }
344 if (index > (numfonts - 1)) {
345 throw new ArrayIndexOutOfBoundsException(
346 "There are only " + numfonts
347 + " font records, you asked for " + idx);
348 }
349 FontRecord retval =
350 ( FontRecord ) records.get((fontpos - (numfonts - 1)) + index);
351
352 return retval;
353 }
354
355
362
363 public FontRecord createNewFont() {
364 FontRecord rec = ( FontRecord ) createFont();
365
366 ++fontpos;
367 ++bspos;
368 ++xfpos;
369 records.add(fontpos, rec);
370 numfonts++;
371 return rec;
372 }
373
374
379
380 public int getNumberOfFontRecords() {
381 return numfonts;
382 }
383
384
390
391 public void setSheetBof(int sheetnum, int pos) {
392 log.log(DEBUG, "setting bof for sheetnum =", new Integer(sheetnum),
393 " at pos=", new Integer(pos));
394 checkSheets(sheetnum);
395 (( BoundSheetRecord ) boundsheets.get(sheetnum))
396 .setPositionOfBof(pos);
397 }
398
399
402
403 public BackupRecord getBackupRecord() {
404 return ( BackupRecord ) records.get(backuppos);
405 }
406
407
415
416 public void setSheetName(int sheetnum, String sheetname) {
417 checkSheets(sheetnum);
418 (( BoundSheetRecord ) boundsheets.get(sheetnum))
419 .setSheetname(sheetname);
420 (( BoundSheetRecord ) boundsheets.get(sheetnum))
421 .setSheetnameLength(( byte ) sheetname.length());
422 }
423
424
430
431 public String getSheetName(int sheetnum) {
432 return (( BoundSheetRecord ) boundsheets.get(sheetnum))
433 .getSheetname();
434 }
435
436
441
442 public int getSheetIndex(String name) {
443 int retval = -1;
444
445 for (int k = 0; k < boundsheets.size(); k++) {
446 String sheet = getSheetName(k);
447
448 if (sheet.equals(name)) {
449 retval = k;
450 break;
451 }
452 }
453 return retval;
454 }
455
456
460
461 private void checkSheets(int sheetnum) {
462 if ((boundsheets.size()) <= sheetnum) {
463 if ((boundsheets.size() + 1) <= sheetnum) {
464 throw new RuntimeException("Sheet number out of bounds!");
465 }
466 BoundSheetRecord bsr =
467 ( BoundSheetRecord ) createBoundSheet(sheetnum);
468
469 records.add(++bspos, bsr);
470 boundsheets.add(bsr);
471 fixTabIdRecord();
472 }
473 }
474
475 public void removeSheet(int sheetnum) {
476 if (boundsheets.size() > sheetnum) {
477 records.remove(bspos - (boundsheets.size() - 1) + sheetnum);
478 bspos--;
479 boundsheets.remove(sheetnum);
480 fixTabIdRecord();
481 }
482 }
483
484
488
489 private void fixTabIdRecord() {
490 TabIdRecord tir = ( TabIdRecord ) records.get(tabpos);
491 short[] tia = new short[ boundsheets.size() ];
492
493 for (short k = 0; k < tia.length; k++) {
494 tia[ k ] = k;
495 }
496 tir.setTabIdArray(tia);
497 }
498
499
504
505 public int getNumSheets() {
506 log.log(DEBUG, "getNumSheets=", new Integer(boundsheets.size()));
507 return boundsheets.size();
508 }
509
510
515
516 public int getNumExFormats() {
517 log.log(DEBUG, "getXF=", new Integer(boundsheets.size()));
518 return numxfs;
519 }
520
521
527
528 public ExtendedFormatRecord getExFormatAt(int index) {
529 int xfptr = xfpos - (numxfs - 1);
530
531 xfptr += index;
532 ExtendedFormatRecord retval =
533 ( ExtendedFormatRecord ) records.get(xfptr);
534
535 return retval;
536 }
537
538
544
545 public ExtendedFormatRecord createCellXF() {
546 ExtendedFormatRecord xf = createExtendedFormat();
547
548 ++xfpos;
549 ++bspos;
550 records.add(xfpos, xf);
551 numxfs++;
552 return xf;
553 }
554
555
563
564 public int addSSTString(String string, boolean use16bits) {
565 log.log(DEBUG, "insert to sst string='", string, "' and use16bits= ",
566 new Boolean(use16bits));
567 if (sst == null) {
568 insertSST();
569 }
570 return sst.addString(string, use16bits);
571 }
572
573
582
583 public int addSSTString(String string) {
584 return addSSTString(string, false);
585 }
586
587
591
592 public String getSSTString(int str) {
593 if (sst == null) {
594 insertSST();
595 }
596 String retval = sst.getString(str);
597
598 log.log(DEBUG, "Returning SST for index=", new Integer(str),
599 " String= ", retval);
600 return retval;
601 }
602
603
609
610 public void insertSST() {
611 log.log(DEBUG, "creating new SST via insertSST!");
612 sst = ( SSTRecord ) createSST();
613 records.add(records.size() - 1, createExtendedSST());
614 records.add(records.size() - 2, sst);
615 }
616
617
623
624 public byte [] serialize() {
625 log.log(DEBUG, "Serializing Workbook!");
626 byte[] retval = null;
627
628
629 int arraysize = getSize();
630 int pos = 0;
631
632
633
634
635
636
637
638
639
640 retval = new byte[ arraysize ];
641 for (int k = 0; k < records.size(); k++) {
642
643
644
645 pos += (( Record ) records.get(k)).serialize(pos,
646 retval);
647 }
648 log.log(DEBUG, "Exiting serialize workbook");
649 return retval;
650 }
651
652
658
659 public int serialize(int offset, byte [] data) {
660 log.log(DEBUG, "Serializing Workbook with offsets");
661
662
663
664 int pos = 0;
665
666
667
668
669
670
671
672
673
674
675 for (int k = 0; k < records.size(); k++) {
676
677
678
679 pos += (( Record ) records.get(k)).serialize(pos + offset,
680 data);
681 }
682 log.log(DEBUG, "Exiting serialize workbook");
683 return pos;
684 }
685
686 public int getSize() {
687 int retval = 0;
688
689 for (int k = 0; k < records.size(); k++) {
690 retval += (( Record ) records.get(k)).getRecordSize();
691 }
692 return retval;
693 }
694
695
701
702 protected Record createBOF() {
703 BOFRecord retval = new BOFRecord();
704
705 retval.setVersion(( short ) 0x600);
706 retval.setType(( short ) 5);
707 retval.setBuild(( short ) 0x10d3);
708
709
710 retval.setBuildYear(( short ) 1996);
711 retval.setHistoryBitMask(0x41);
712 retval.setRequiredVersion(0x6);
713 return retval;
714 }
715
716
722
723 protected Record createInterfaceHdr() {
724 InterfaceHdrRecord retval = new InterfaceHdrRecord();
725
726 retval.setCodepage(CODEPAGE);
727 return retval;
728 }
729
730
736
737 protected Record createMMS() {
738 MMSRecord retval = new MMSRecord();
739
740 retval.setAddMenuCount(( byte ) 0);
741 retval.setDelMenuCount(( byte ) 0);
742 return retval;
743 }
744
745
751
752 protected Record createInterfaceEnd() {
753 return new InterfaceEndRecord();
754 }
755
756
762
763 protected Record createWriteAccess() {
764 WriteAccessRecord retval = new WriteAccessRecord();
765
766 retval.setUsername(System.getProperty("user.name"));
767 return retval;
768 }
769
770
776
777 protected Record createCodepage() {
778 CodepageRecord retval = new CodepageRecord();
779
780 retval.setCodepage(CODEPAGE);
781 return retval;
782 }
783
784
790
791 protected Record createDSF() {
792 DSFRecord retval = new DSFRecord();
793
794 retval.setDsf(
795 ( short ) 0);
796 return retval;
797 }
798
799
806
807 protected Record createTabId() {
808 TabIdRecord retval = new TabIdRecord();
809 short[] tabidarray = {
810 0
811 };
812
813 retval.setTabIdArray(tabidarray);
814 return retval;
815 }
816
817
823
824 protected Record createFnGroupCount() {
825 FnGroupCountRecord retval = new FnGroupCountRecord();
826
827 retval.setCount(( short ) 14);
828 return retval;
829 }
830
831
837
838 protected Record createWindowProtect() {
839 WindowProtectRecord retval = new WindowProtectRecord();
840
841 retval.setProtect(
842 false);
843 return retval;
844 }
845
846
852
853 protected Record createProtect() {
854 ProtectRecord retval = new ProtectRecord();
855
856 retval.setProtect(
857 false);
858 return retval;
859 }
860
861
867
868 protected Record createPassword() {
869 PasswordRecord retval = new PasswordRecord();
870
871 retval.setPassword(( short ) 0);
872 return retval;
873 }
874
875
881
882 protected Record createProtectionRev4() {
883 ProtectionRev4Record retval = new ProtectionRev4Record();
884
885 retval.setProtect(false);
886 return retval;
887 }
888
889
895
896 protected Record createPasswordRev4() {
897 PasswordRev4Record retval = new PasswordRev4Record();
898
899 retval.setPassword(( short ) 0);
900 return retval;
901 }
902
903
918
919 protected Record createWindowOne() {
920 WindowOneRecord retval = new WindowOneRecord();
921
922 retval.setHorizontalHold(( short ) 0x168);
923 retval.setVerticalHold(( short ) 0x10e);
924 retval.setWidth(( short ) 0x3a5c);
925 retval.setHeight(( short ) 0x23be);
926 retval.setOptions(( short ) 0x38);
927 retval.setSelectedTab(( short ) 0x0);
928 retval.setDisplayedTab(( short ) 0x0);
929 retval.setNumSelectedTabs(( short ) 1);
930 retval.setTabWidthRatio(( short ) 0x258);
931 return retval;
932 }
933
934
940
941 protected Record createBackup() {
942 BackupRecord retval = new BackupRecord();
943
944 retval.setBackup(
945 ( short ) 0);
946 return retval;
947 }
948
949
955
956 protected Record createHideObj() {
957 HideObjRecord retval = new HideObjRecord();
958
959 retval.setHideObj(( short ) 0);
960 return retval;
961 }
962
963
969
970 protected Record createDateWindow1904() {
971 DateWindow1904Record retval = new DateWindow1904Record();
972
973 retval.setWindowing(
974 ( short ) 0);
975 return retval;
976 }
977
978
984
985 protected Record createPrecision() {
986 PrecisionRecord retval = new PrecisionRecord();
987
988 retval.setFullPrecision(
989 true);
990 return retval;
991 }
992
993
999
1000 protected Record createRefreshAll() {
1001 RefreshAllRecord retval = new RefreshAllRecord();
1002
1003 retval.setRefreshAll(false);
1004 return retval;
1005 }
1006
1007
1013
1014 protected Record createBookBool() {
1015 BookBoolRecord retval = new BookBoolRecord();
1016
1017 retval.setSaveLinkValues(( short ) 0);
1018 return retval;
1019 }
1020
1021
1034
1035 protected Record createFont() {
1036 FontRecord retval = new FontRecord();
1037
1038 retval.setFontHeight(( short ) 0xc8);
1039 retval.setAttributes(( short ) 0x0);
1040 retval.setColorPaletteIndex(( short ) 0x7fff);
1041 retval.setBoldWeight(( short ) 0x190);
1042 retval.setFontNameLength(( byte ) 5);
1043 retval.setFontName("Arial");
1044 return retval;
1045 }
1046
1047
1055
1056 protected Record createFormat(int id) {
1057 FormatRecord retval = new FormatRecord();
1058
1059 switch (id) {
1060
1061 case 0 :
1062 retval.setIndexCode(( short ) 5);
1063 retval.setFormatStringLength(( byte ) 0x17);
1064 retval.setFormatString("\"$\"#,##0_);\\(\"$\"#,##0\\)");
1065 break;
1066
1067 case 1 :
1068 retval.setIndexCode(( short ) 6);
1069 retval.setFormatStringLength(( byte ) 0x1c);
1070 retval.setFormatString("\"$\"#,##0_);[Red]\\(\"$\"#,##0\\)");
1071 break;
1072
1073 case 2 :
1074 retval.setIndexCode(( short ) 7);
1075 retval.setFormatStringLength(( byte ) 0x1d);
1076 retval.setFormatString("\"$\"#,##0.00_);\\(\"$\"#,##0.00\\)");
1077 break;
1078
1079 case 3 :
1080 retval.setIndexCode(( short ) 8);
1081 retval.setFormatStringLength(( byte ) 0x22);
1082 retval.setFormatString(
1083 "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)");
1084 break;
1085
1086 case 4 :
1087 retval.setIndexCode(( short ) 0x2a);
1088 retval.setFormatStringLength(( byte ) 0x32);
1089 retval.setFormatString(
1090 "_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)");
1091 break;
1092
1093 case 5 :
1094 retval.setIndexCode(( short ) 0x29);
1095 retval.setFormatStringLength(( byte ) 0x29);
1096 retval.setFormatString(
1097 "_(* #,##0_);_(* \\(#,##0\\);_(* \"-\"_);_(@_)");
1098 break;
1099
1100 case 6 :
1101 retval.setIndexCode(( short ) 0x2c);
1102 retval.setFormatStringLength(( byte ) 0x3a);
1103 retval.setFormatString(
1104 "_(\"$\"* #,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)");
1105 break;
1106
1107 case 7 :
1108 retval.setIndexCode(( short ) 0x2b);
1109 retval.setFormatStringLength(( byte ) 0x31);
1110 retval.setFormatString(
1111 "_(* #,##0.00_);_(* \\(#,##0.00\\);_(* \"-\"??_);_(@_)");
1112 break;
1113 }
1114 return retval;
1115 }
1116
1117
1126
1127 protected Record createExtendedFormat(int id) {
1128 ExtendedFormatRecord retval = new ExtendedFormatRecord();
1129
1130 switch (id) {
1131
1132 case 0 :
1133 retval.setFontIndex(( short ) 0);
1134 retval.setFormatIndex(( short ) 0);
1135 retval.setCellOptions(( short ) 0xfffffff5);
1136 retval.setAlignmentOptions(( short ) 0x20);
1137 retval.setIndentionOptions(( short ) 0);
1138 retval.setBorderOptions(( short ) 0);
1139 retval.setPaletteOptions(( short ) 0);
1140 retval.setAdtlPaletteOptions(( short ) 0);
1141 retval.setFillPaletteOptions(( short ) 0x20c0);
1142 break;
1143
1144 case 1 :
1145 retval.setFontIndex(( short ) 1);
1146 retval.setFormatIndex(( short ) 0);
1147 retval.setCellOptions(( short ) 0xfffffff5);
1148 retval.setAlignmentOptions(( short ) 0x20);
1149 retval.setIndentionOptions(( short ) 0xfffff400);
1150 retval.setBorderOptions(( short ) 0);
1151 retval.setPaletteOptions(( short ) 0);
1152 retval.setAdtlPaletteOptions(( short ) 0);
1153 retval.setFillPaletteOptions(( short ) 0x20c0);
1154 break;
1155
1156 case 2 :
1157 retval.setFontIndex(( short ) 1);
1158 retval.setFormatIndex(( short ) 0);
1159 retval.setCellOptions(( short ) 0xfffffff5);
1160 retval.setAlignmentOptions(( short ) 0x20);
1161 retval.setIndentionOptions(( short ) 0xfffff400);
1162 retval.setBorderOptions(( short ) 0);
1163 retval.setPaletteOptions(( short ) 0);
1164 retval.setAdtlPaletteOptions(( short ) 0);
1165 retval.setFillPaletteOptions(( short ) 0x20c0);
1166 break;
1167
1168 case 3 :
1169 retval.setFontIndex(( short ) 2);
1170 retval.setFormatIndex(( short ) 0);
1171 retval.setCellOptions(( short ) 0xfffffff5);
1172 retval.setAlignmentOptions(( short ) 0x20);
1173 retval.setIndentionOptions(( short ) 0xfffff400);
1174 retval.setBorderOptions(( short ) 0);
1175 retval.setPaletteOptions(( short ) 0);
1176 retval.setAdtlPaletteOptions(( short ) 0);
1177 retval.setFillPaletteOptions(( short ) 0x20c0);
1178 break;
1179
1180 case 4 :
1181 retval.setFontIndex(( short ) 2);
1182 retval.setFormatIndex(( short ) 0);
1183 retval.setCellOptions(( short ) 0xfffffff5);
1184 retval.setAlignmentOptions(( short ) 0x20);
1185 retval.setIndentionOptions(( short ) 0xfffff400);
1186 retval.setBorderOptions(( short ) 0);
1187 retval.setPaletteOptions(( short ) 0);
1188 retval.setAdtlPaletteOptions(( short ) 0);
1189 retval.setFillPaletteOptions(( short ) 0x20c0);
1190 break;
1191
1192 case 5 :
1193 retval.setFontIndex(( short ) 0);
1194 retval.setFormatIndex(( short ) 0);
1195 retval.setCellOptions(( short ) 0xfffffff5);
1196 retval.setAlignmentOptions(( short ) 0x20);
1197 retval.setIndentionOptions(( short ) 0xfffff400);
1198 retval.setBorderOptions(( short ) 0);
1199 retval.setPaletteOptions(( short ) 0);
1200 retval.setAdtlPaletteOptions(( short ) 0);
1201 retval.setFillPaletteOptions(( short ) 0x20c0);
1202 break;
1203
1204 case 6 :
1205 retval.setFontIndex(( short ) 0);
1206 retval.setFormatIndex(( short ) 0);
1207 retval.setCellOptions(( short ) 0xfffffff5);
1208 retval.setAlignmentOptions(( short ) 0x20);
1209 retval.setIndentionOptions(( short ) 0xfffff400);
1210 retval.setBorderOptions(( short ) 0);
1211 retval.setPaletteOptions(( short ) 0);
1212 retval.setAdtlPaletteOptions(( short ) 0);
1213 retval.setFillPaletteOptions(( short ) 0x20c0);
1214 break;
1215
1216 case 7 :
1217 retval.setFontIndex(( short ) 0);
1218 retval.setFormatIndex(( short ) 0);
1219 retval.setCellOptions(( short ) 0xfffffff5);
1220 retval.setAlignmentOptions(( short ) 0x20);
1221 retval.setIndentionOptions(( short ) 0xfffff400);
1222 retval.setBorderOptions(( short ) 0);
1223 retval.setPaletteOptions(( short ) 0);
1224 retval.setAdtlPaletteOptions(( short ) 0);
1225 retval.setFillPaletteOptions(( short ) 0x20c0);
1226 break;
1227
1228 case 8 :
1229 retval.setFontIndex(( short ) 0);
1230 retval.setFormatIndex(( short ) 0);
1231 retval.setCellOptions(( short ) 0xfffffff5);
1232 retval.setAlignmentOptions(( short ) 0x20);
1233 retval.setIndentionOptions(( short ) 0xfffff400);
1234 retval.setBorderOptions(( short ) 0);
1235 retval.setPaletteOptions(( short ) 0);
1236 retval.setAdtlPaletteOptions(( short ) 0);
1237 retval.setFillPaletteOptions(( short ) 0x20c0);
1238 break;
1239
1240 case 9 :
1241 retval.setFontIndex(( short ) 0);
1242 retval.setFormatIndex(( short ) 0);
1243 retval.setCellOptions(( short ) 0xfffffff5);
1244 retval.setAlignmentOptions(( short ) 0x20);
1245 retval.setIndentionOptions(( short ) 0xfffff400);
1246 retval.setBorderOptions(( short ) 0);
1247 retval.setPaletteOptions(( short ) 0);
1248 retval.setAdtlPaletteOptions(( short ) 0);
1249 retval.setFillPaletteOptions(( short ) 0x20c0);
1250 break;
1251
1252 case 10 :
1253 retval.setFontIndex(( short ) 0);
1254 retval.setFormatIndex(( short ) 0);
1255 retval.setCellOptions(( short ) 0xfffffff5);
1256 retval.setAlignmentOptions(( short ) 0x20);
1257 retval.setIndentionOptions(( short ) 0xfffff400);
1258 retval.setBorderOptions(( short ) 0);
1259 retval.setPaletteOptions(( short ) 0);
1260 retval.setAdtlPaletteOptions(( short ) 0);
1261 retval.setFillPaletteOptions(( short ) 0x20c0);
1262 break;
1263
1264 case 11 :
1265 retval.setFontIndex(( short ) 0);
1266 retval.setFormatIndex(( short ) 0);
1267 retval.setCellOptions(( short ) 0xfffffff5);
1268 retval.setAlignmentOptions(( short ) 0x20);
1269 retval.setIndentionOptions(( short ) 0xfffff400);
1270 retval.setBorderOptions(( short ) 0);
1271 retval.setPaletteOptions(( short ) 0);
1272 retval.setAdtlPaletteOptions(( short ) 0);
1273 retval.setFillPaletteOptions(( short ) 0x20c0);
1274 break;
1275
1276 case 12 :
1277 retval.setFontIndex(( short ) 0);
1278 retval.setFormatIndex(( short ) 0);
1279 retval.setCellOptions(( short ) 0xfffffff5);
1280 retval.setAlignmentOptions(( short ) 0x20);
1281 retval.setIndentionOptions(( short ) 0xfffff400);
1282 retval.setBorderOptions(( short ) 0);
1283 retval.setPaletteOptions(( short ) 0);
1284 retval.setAdtlPaletteOptions(( short ) 0);
1285 retval.setFillPaletteOptions(( short ) 0x20c0);
1286 break;
1287
1288 case 13 :
1289 retval.setFontIndex(( short ) 0);
1290 retval.setFormatIndex(( short ) 0);
1291 retval.setCellOptions(( short ) 0xfffffff5);
1292 retval.setAlignmentOptions(( short ) 0x20);
1293 retval.setIndentionOptions(( short ) 0xfffff400);
1294 retval.setBorderOptions(( short ) 0);
1295 retval.setPaletteOptions(( short ) 0);
1296 retval.setAdtlPaletteOptions(( short ) 0);
1297 retval.setFillPaletteOptions(( short ) 0x20c0);
1298 break;
1299
1300 case 14 :
1301 retval.setFontIndex(( short ) 0);
1302 retval.setFormatIndex(( short ) 0);
1303 retval.setCellOptions(( short ) 0xfffffff5);
1304 retval.setAlignmentOptions(( short ) 0x20);
1305 retval.setIndentionOptions(( short ) 0xfffff400);
1306 retval.setBorderOptions(( short ) 0);
1307 retval.setPaletteOptions(( short ) 0);
1308 retval.setAdtlPaletteOptions(( short ) 0);
1309 retval.setFillPaletteOptions(( short ) 0x20c0);
1310 break;
1311
1312
1313 case 15 :
1314 retval.setFontIndex(( short ) 0);
1315 retval.setFormatIndex(( short ) 0);
1316 retval.setCellOptions(( short ) 0x1);
1317 retval.setAlignmentOptions(( short ) 0x20);
1318 retval.setIndentionOptions(( short ) 0x0);
1319 retval.setBorderOptions(( short ) 0);
1320 retval.setPaletteOptions(( short ) 0);
1321 retval.setAdtlPaletteOptions(( short ) 0);
1322 retval.setFillPaletteOptions(( short ) 0x20c0);
1323 break;
1324
1325
1326 case 16 :
1327 retval.setFontIndex(( short ) 1);
1328 retval.setFormatIndex(( short ) 0x2b);
1329 retval.setCellOptions(( short ) 0xfffffff5);
1330 retval.setAlignmentOptions(( short ) 0x20);
1331 retval.setIndentionOptions(( short ) 0xfffff800);
1332 retval.setBorderOptions(( short ) 0);
1333 retval.setPaletteOptions(( short ) 0);
1334 retval.setAdtlPaletteOptions(( short ) 0);
1335 retval.setFillPaletteOptions(( short ) 0x20c0);
1336 break;
1337
1338 case 17 :
1339 retval.setFontIndex(( short ) 1);
1340 retval.setFormatIndex(( short ) 0x29);
1341 retval.setCellOptions(( short ) 0xfffffff5);
1342 retval.setAlignmentOptions(( short ) 0x20);
1343 retval.setIndentionOptions(( short ) 0xfffff800);
1344 retval.setBorderOptions(( short ) 0);
1345 retval.setPaletteOptions(( short ) 0);
1346 retval.setAdtlPaletteOptions(( short ) 0);
1347 retval.setFillPaletteOptions(( short ) 0x20c0);
1348 break;
1349
1350 case 18 :
1351 retval.setFontIndex(( short ) 1);
1352 retval.setFormatIndex(( short ) 0x2c);
1353 retval.setCellOptions(( short ) 0xfffffff5);
1354 retval.setAlignmentOptions(( short ) 0x20);
1355 retval.setIndentionOptions(( short ) 0xfffff800);
1356 retval.setBorderOptions(( short ) 0);
1357 retval.setPaletteOptions(( short ) 0);
1358 retval.setAdtlPaletteOptions(( short ) 0);
1359 retval.setFillPaletteOptions(( short ) 0x20c0);
1360 break;
1361
1362 case 19 :
1363 retval.setFontIndex(( short ) 1);
1364 retval.setFormatIndex(( short ) 0x2a);
1365 retval.setCellOptions(( short ) 0xfffffff5);
1366 retval.setAlignmentOptions(( short ) 0x20);
1367 retval.setIndentionOptions(( short ) 0xfffff800);
1368 retval.setBorderOptions(( short ) 0);
1369 retval.setPaletteOptions(( short ) 0);
1370 retval.setAdtlPaletteOptions(( short ) 0);
1371 retval.setFillPaletteOptions(( short ) 0x20c0);
1372 break;
1373
1374 case 20 :
1375 retval.setFontIndex(( short ) 1);
1376 retval.setFormatIndex(( short ) 0x9);
1377 retval.setCellOptions(( short ) 0xfffffff5);
1378 retval.setAlignmentOptions(( short ) 0x20);
1379 retval.setIndentionOptions(( short ) 0xfffff800);
1380 retval.setBorderOptions(( short ) 0);
1381 retval.setPaletteOptions(( short ) 0);
1382 retval.setAdtlPaletteOptions(( short ) 0);
1383 retval.setFillPaletteOptions(( short ) 0x20c0);
1384 break;
1385
1386
1387 case 21 :
1388 retval.setFontIndex(( short ) 5);
1389 retval.setFormatIndex(( short ) 0x0);
1390 retval.setCellOptions(( short ) 0x1);
1391 retval.setAlignmentOptions(( short ) 0x20);
1392 retval.setIndentionOptions(( short ) 0x800);
1393 retval.setBorderOptions(( short ) 0);
1394 retval.setPaletteOptions(( short ) 0);
1395 retval.setAdtlPaletteOptions(( short ) 0);
1396 retval.setFillPaletteOptions(( short ) 0x20c0);
1397 break;
1398
1399 case 22 :
1400 retval.setFontIndex(( short ) 6);
1401 retval.setFormatIndex(( short ) 0x0);
1402 retval.setCellOptions(( short ) 0x1);
1403 retval.setAlignmentOptions(( short ) 0x20);
1404 retval.setIndentionOptions(( short ) 0x5c00);
1405 retval.setBorderOptions(( short ) 0);
1406 retval.setPaletteOptions(( short ) 0);
1407 retval.setAdtlPaletteOptions(( short ) 0);
1408 retval.setFillPaletteOptions(( short ) 0x20c0);
1409 break;
1410
1411 case 23 :
1412 retval.setFontIndex(( short ) 0);
1413 retval.setFormatIndex(( short ) 0x31);
1414 retval.setCellOptions(( short ) 0x1);
1415 retval.setAlignmentOptions(( short ) 0x20);
1416 retval.setIndentionOptions(( short ) 0x5c00);
1417 retval.setBorderOptions(( short ) 0);
1418 retval.setPaletteOptions(( short ) 0);
1419 retval.setAdtlPaletteOptions(( short ) 0);
1420 retval.setFillPaletteOptions(( short ) 0x20c0);
1421 break;
1422
1423 case 24 :
1424 retval.setFontIndex(( short ) 0);
1425 retval.setFormatIndex(( short ) 0x8);
1426 retval.setCellOptions(( short ) 0x1);
1427 retval.setAlignmentOptions(( short ) 0x20);
1428 retval.setIndentionOptions(( short ) 0x5c00);
1429 retval.setBorderOptions(( short ) 0);
1430 retval.setPaletteOptions(( short ) 0);
1431 retval.setAdtlPaletteOptions(( short ) 0);
1432 retval.setFillPaletteOptions(( short ) 0x20c0);
1433 break;
1434
1435 case 25 :
1436 retval.setFontIndex(( short ) 6);
1437 retval.setFormatIndex(( short ) 0x8);
1438 retval.setCellOptions(( short ) 0x1);
1439 retval.setAlignmentOptions(( short ) 0x20);
1440 retval.setIndentionOptions(( short ) 0x5c00);
1441 retval.setBorderOptions(( short ) 0);
1442 retval.setPaletteOptions(( short ) 0);
1443 retval.setAdtlPaletteOptions(( short ) 0);
1444 retval.setFillPaletteOptions(( short ) 0x20c0);
1445 break;
1446 }
1447 return retval;
1448 }
1449
1450
1454
1455 protected ExtendedFormatRecord createExtendedFormat() {
1456 ExtendedFormatRecord retval = new ExtendedFormatRecord();
1457
1458 retval.setFontIndex(( short ) 0);
1459 retval.setFormatIndex(( short ) 0x0);
1460 retval.setCellOptions(( short ) 0x1);
1461 retval.setAlignmentOptions(( short ) 0x20);
1462 retval.setIndentionOptions(( short ) 0);
1463 retval.setBorderOptions(( short ) 0);
1464 retval.setPaletteOptions(( short ) 0);
1465 retval.setAdtlPaletteOptions(( short ) 0);
1466 retval.setFillPaletteOptions(( short ) 0x20c0);
1467 return retval;
1468 }
1469
1470
1478
1479 protected Record createStyle(int id) {
1480 StyleRecord retval = new StyleRecord();
1481
1482 switch (id) {
1483
1484 case 0 :
1485 retval.setIndex(( short ) 0xffff8010);
1486 retval.setBuiltin(( byte ) 3);
1487 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1488 break;
1489
1490 case 1 :
1491 retval.setIndex(( short ) 0xffff8011);
1492 retval.setBuiltin(( byte ) 6);
1493 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1494 break;
1495
1496 case 2 :
1497 retval.setIndex(( short ) 0xffff8012);
1498 retval.setBuiltin(( byte ) 4);
1499 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1500 break;
1501
1502 case 3 :
1503 retval.setIndex(( short ) 0xffff8013);
1504 retval.setBuiltin(( byte ) 7);
1505 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1506 break;
1507
1508 case 4 :
1509 retval.setIndex(( short ) 0xffff8000);
1510 retval.setBuiltin(( byte ) 0);
1511 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1512 break;
1513
1514 case 5 :
1515 retval.setIndex(( short ) 0xffff8014);
1516 retval.setBuiltin(( byte ) 5);
1517 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1518 break;
1519 }
1520 return retval;
1521 }
1522
1523
1529
1530 protected Record createUseSelFS() {
1531 UseSelFSRecord retval = new UseSelFSRecord();
1532
1533 retval.setFlag(( short ) 0);
1534 return retval;
1535 }
1536
1537
1545
1546 protected Record createBoundSheet(int id) {
1547 BoundSheetRecord retval = new BoundSheetRecord();
1548
1549 switch (id) {
1550
1551 case 0 :
1552 retval.setPositionOfBof(0x0);
1553 retval.setOptionFlags(( short ) 0);
1554 retval.setSheetnameLength(( byte ) 0x6);
1555 retval.setCompressedUnicodeFlag(( byte ) 0);
1556 retval.setSheetname("Sheet1");
1557 break;
1558
1559 case 1 :
1560 retval.setPositionOfBof(0x0);
1561 retval.setOptionFlags(( short ) 0);
1562 retval.setSheetnameLength(( byte ) 0x6);
1563 retval.setCompressedUnicodeFlag(( byte ) 0);
1564 retval.setSheetname("Sheet2");
1565 break;
1566
1567 case 2 :
1568 retval.setPositionOfBof(0x0);
1569 retval.setOptionFlags(( short ) 0);
1570 retval.setSheetnameLength(( byte ) 0x6);
1571 retval.setCompressedUnicodeFlag(( byte ) 0);
1572 retval.setSheetname("Sheet3");
1573 break;
1574 }
1575 return retval;
1576 }
1577
1578
1584
1585 protected Record createCountry() {
1586 CountryRecord retval = new CountryRecord();
1587
1588 retval.setDefaultCountry(( short ) 1);
1589 retval.setCurrentCountry(( short ) 1);
1590 return retval;
1591 }
1592
1593
1599
1600 protected Record createSST() {
1601 return new SSTRecord();
1602 }
1603
1604
1613
1614 protected Record createExtendedSST() {
1615 ExtSSTRecord retval = new ExtSSTRecord();
1616
1617 retval.setNumStringsPerBucket(( short ) 0x8);
1618 return retval;
1619 }
1620
1621
1627
1628 protected Record createEOF() {
1629 return new EOFRecord();
1630 }
1631
1632
1636 public String findSheetNameFromExternSheet(short num){
1637 String result;
1638
1639 short indexToSheet = externSheet.getREFRecordAt(num).getIndexToFirstSupBook();
1640 result = getSheetName(indexToSheet);
1641
1642 return result;
1643 }
1644
1645
1650 public short checkExternSheet(int sheetNumber){
1651
1652 int i = 0;
1653 boolean flag = false;
1654 short result = 0;
1655
1656 if (externSheet == null) {
1657 externSheet = createExternSheet();
1658 }
1659
1660
1661 while (i < externSheet.getNumOfREFStructures() && !flag){
1662 ExternSheetSubRecord record = externSheet.getREFRecordAt(i);
1663
1664 if (record.getIndexToFirstSupBook() == sheetNumber &&
1665 record.getIndexToLastSupBook() == sheetNumber){
1666 flag = true;
1667 result = (short) i;
1668 }
1669
1670 ++i;
1671 }
1672
1673
1674 if (!flag) {
1675 result = addSheetIndexToExternSheet((short) sheetNumber);
1676 }
1677
1678 return result;
1679 }
1680
1681 private short addSheetIndexToExternSheet(short sheetNumber){
1682 short result;
1683
1684 ExternSheetSubRecord record = new ExternSheetSubRecord();
1685 record.setIndexToFirstSupBook(sheetNumber);
1686 record.setIndexToLastSupBook(sheetNumber);
1687 externSheet.addREFRecord(record);
1688 externSheet.setNumOfREFStructures((short)(externSheet.getNumOfREFStructures() + 1));
1689 result = (short)(externSheet.getNumOfREFStructures() - 1);
1690
1691 return result;
1692 }
1693
1694
1695
1696
1699 public int getNumNames(){
1700 int result = names.size();
1701
1702 return result;
1703 }
1704
1705
1709 public NameRecord getNameRecord(int index){
1710 NameRecord result = (NameRecord) names.get(index);
1711
1712 return result;
1713
1714 }
1715
1716
1719 public NameRecord createName(){
1720
1721 NameRecord name = new NameRecord();
1722
1723 records.add(++namepos, name);
1724 names.add(name);
1725
1726 return name;
1727 }
1728
1729
1732 public void removeName(int namenum){
1733 if (names.size() > namenum) {
1734 records.remove(namepos - (names.size() - 1) + namenum);
1735 namepos--;
1736 names.remove(namenum);
1737 }
1738
1739 }
1740
1741
1744 protected ExternSheetRecord createExternSheet(){
1745 ExternSheetRecord rec = new ExternSheetRecord();
1746
1747 records.add(supbookpos + 1 , rec);
1748
1749
1750 SupBookRecord supbook = new SupBookRecord();
1751
1752 supbook.setNumberOfSheets((short)getNumSheets());
1753
1754
1755 records.add(supbookpos + 1 , supbook);
1756
1757 return rec;
1758 }
1759
1760
1761
1764
1765 public Record findFirstRecordBySid(short sid) {
1766 for (Iterator iterator = records.iterator(); iterator.hasNext(); ) {
1767 Record record = ( Record ) iterator.next();
1768
1769 if (record.getSid() == sid) {
1770 return record;
1771 }
1772 }
1773 return null;
1774 }
1775
1776 public List getRecords()
1777 {
1778 return records;
1779 }
1780 }
1781