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 {
90 private static final int DEBUG = POILogger.DEBUG;
91
92
96
97 private final static short CODEPAGE = ( short ) 0x4b0;
98
99
102
103 protected ArrayList records = null;
104
105
109
110 protected SSTRecord sst = null;
111
112
116
117 protected ArrayList boundsheets = new ArrayList();
118 protected int bspos =
119 0;
120 protected int tabpos =
121 0;
122 protected int fontpos =
123 0;
124 protected int numfonts =
125 0;
126 protected int xfpos =
127 0;
128 protected int numxfs =
129 0;
130 private int backuppos =
131 0;
132 private static POILogger log =
133 POILogFactory.getLogger(Workbook.class);
134
135
139
140 public Workbook()
141 {
142 }
143
144
156
157 public static Workbook createWorkbook(List recs)
158 {
159 log.log(DEBUG, "Workbook (readfile) created with reclen=",
160 new Integer(recs.size()));
161 Workbook retval = new Workbook();
162 ArrayList records = new ArrayList(recs.size() / 3);
163
164 for (int k = 0; k < recs.size(); k++)
165 {
166 Record rec = ( Record ) recs.get(k);
167
168 if (rec.getSid() == EOFRecord.sid)
169 {
170 records.add(rec);
171 log.log(DEBUG, "found workbook eof record at " + k);
172 break;
173 }
174 switch (rec.getSid())
175 {
176
177 case BoundSheetRecord.sid :
178 log.log(DEBUG, "found boundsheet record at " + k);
179 retval.boundsheets.add(rec);
180 retval.bspos = k;
181 break;
182
183 case SSTRecord.sid :
184 log.log(DEBUG, "found sst record at " + k);
185 retval.sst = ( SSTRecord ) rec;
186 break;
187
188 case FontRecord.sid :
189 log.log(DEBUG, "found font record at " + k);
190 retval.fontpos = k;
191 retval.numfonts++;
192 break;
193
194 case ExtendedFormatRecord.sid :
195 log.log(DEBUG, "found XF record at " + k);
196 retval.xfpos = k;
197 retval.numxfs++;
198 break;
199
200 case TabIdRecord.sid :
201 log.log(DEBUG, "found tabid record at " + k);
202 retval.tabpos = k;
203 break;
204
205 case BackupRecord.sid :
206 log.log(DEBUG, "found backup record at " + k);
207 retval.backuppos = k;
208 break;
209
210 default :
211 }
212 records.add(rec);
213 }
214 retval.records = records;
215 log.log(DEBUG, "exit create workbook from existing file function");
216 return retval;
217 }
218
219
223
224 public static Workbook createWorkbook()
225 {
226 log.log(DEBUG, "creating new workbook from scratch");
227 Workbook retval = new Workbook();
228 ArrayList records = new ArrayList(30);
229
230 records.add(retval.createBOF());
231 records.add(retval.createInterfaceHdr());
232 records.add(retval.createMMS());
233 records.add(retval.createInterfaceEnd());
234 records.add(retval.createWriteAccess());
235 records.add(retval.createCodepage());
236 records.add(retval.createDSF());
237 records.add(retval.createTabId());
238 retval.tabpos = records.size() - 1;
239 records.add(retval.createFnGroupCount());
240 records.add(retval.createWindowProtect());
241 records.add(retval.createProtect());
242 records.add(retval.createPassword());
243 records.add(retval.createProtectionRev4());
244 records.add(retval.createPasswordRev4());
245 records.add(retval.createWindowOne());
246 records.add(retval.createBackup());
247 retval.backuppos = records.size() - 1;
248 records.add(retval.createHideObj());
249 records.add(retval.createDateWindow1904());
250 records.add(retval.createPrecision());
251 records.add(retval.createRefreshAll());
252 records.add(retval.createBookBool());
253 records.add(retval.createFont());
254 records.add(retval.createFont());
255 records.add(retval.createFont());
256 records.add(retval.createFont());
257 retval.fontpos = records.size() - 1;
258 retval.numfonts = 4;
259 records.add(retval.createFormat(0));
260 records.add(retval.createFormat(1));
261 records.add(retval.createFormat(2));
262 records.add(retval.createFormat(3));
263 records.add(retval.createFormat(4));
264 records.add(retval.createFormat(5));
265 records.add(retval.createFormat(6));
266 records.add(retval.createFormat(7));
267 for (int k = 0; k < 21; k++)
268 {
269 records.add(retval.createExtendedFormat(k));
270 retval.numxfs++;
271 }
272 retval.xfpos = records.size() - 1;
273 for (int k = 0; k < 6; k++)
274 {
275 records.add(retval.createStyle(k));
276 }
277 records.add(retval.createUseSelFS());
278 for (int k = 0; k < 1; k++)
279 {
280 BoundSheetRecord bsr =
281 ( BoundSheetRecord ) retval.createBoundSheet(k);
282
283 records.add(bsr);
284 retval.boundsheets.add(bsr);
285 retval.bspos = records.size() - 1;
286 }
287 records.add(retval.createCountry());
288 retval.sst = ( SSTRecord ) retval.createSST();
289 records.add(retval.sst);
290 records.add(retval.createExtendedSST());
291
292
293 records.add(retval.createEOF());
294 retval.records = records;
295 log.log(DEBUG, "exit create new workbook from scratch");
296 return retval;
297 }
298
299 public int getNumRecords()
300 {
301 return records.size();
302 }
303
304
312
313 public FontRecord getFontRecordAt(int idx)
314 {
315 int index = idx;
316
317 if (index > 4)
318 {
319 index -= 1;
320 }
321 if (index > (numfonts - 1))
322 {
323 throw new ArrayIndexOutOfBoundsException(
324 "There are only " + numfonts
325 + " font records, you asked for " + idx);
326 }
327 FontRecord retval =
328 ( FontRecord ) records.get((fontpos - (numfonts - 1)) + index);
329
330 return retval;
331 }
332
333
340
341 public FontRecord createNewFont()
342 {
343 FontRecord rec = ( FontRecord ) createFont();
344
345 ++fontpos;
346 ++bspos;
347 ++xfpos;
348 records.add(fontpos, rec);
349 numfonts++;
350 return rec;
351 }
352
353
358
359 public int getNumberOfFontRecords()
360 {
361 return numfonts;
362 }
363
364
370
371 public void setSheetBof(int sheetnum, int pos)
372 {
373 log.log(DEBUG, "setting bof for sheetnum =", new Integer(sheetnum),
374 " at pos=", new Integer(pos));
375 checkSheets(sheetnum);
376 (( BoundSheetRecord ) boundsheets.get(sheetnum))
377 .setPositionOfBof(pos);
378 }
379
380
383
384 public BackupRecord getBackupRecord()
385 {
386 return ( BackupRecord ) records.get(backuppos);
387 }
388
389
397
398 public void setSheetName(int sheetnum, String sheetname)
399 {
400 checkSheets(sheetnum);
401 (( BoundSheetRecord ) boundsheets.get(sheetnum))
402 .setSheetname(sheetname);
403 (( BoundSheetRecord ) boundsheets.get(sheetnum))
404 .setSheetnameLength(( byte ) sheetname.length());
405 }
406
407
413
414 public String getSheetName(int sheetnum)
415 {
416 return (( BoundSheetRecord ) boundsheets.get(sheetnum))
417 .getSheetname();
418 }
419
420
424
425 private void checkSheets(int sheetnum)
426 {
427 if ((boundsheets.size()) <= sheetnum)
428 {
429 if ((boundsheets.size() + 1) <= sheetnum)
430 {
431 throw new RuntimeException("Sheet number out of bounds!");
432 }
433 BoundSheetRecord bsr =
434 ( BoundSheetRecord ) createBoundSheet(sheetnum);
435
436 records.add(++bspos, bsr);
437 boundsheets.add(bsr);
438 fixTabIdRecord();
439 }
440 }
441
442 public void removeSheet(int sheetnum)
443 {
444 if (boundsheets.size() > sheetnum)
445 {
446 records.remove(bspos - (boundsheets.size() - 1) + sheetnum);
447 bspos--;
448 boundsheets.remove(sheetnum);
449 fixTabIdRecord();
450 }
451 }
452
453
457
458 private void fixTabIdRecord()
459 {
460 TabIdRecord tir = ( TabIdRecord ) records.get(tabpos);
461 short[] tia = new short[ boundsheets.size() ];
462
463 for (short k = 0; k < tia.length; k++)
464 {
465 tia[ k ] = k;
466 }
467 tir.setTabIdArray(tia);
468 }
469
470
475
476 public int getNumSheets()
477 {
478 log.log(DEBUG, "getNumSheets=", new Integer(boundsheets.size()));
479 return boundsheets.size();
480 }
481
482
487
488 public int getNumExFormats()
489 {
490 log.log(DEBUG, "getXF=", new Integer(boundsheets.size()));
491 return numxfs;
492 }
493
494
500
501 public ExtendedFormatRecord getExFormatAt(int index)
502 {
503 int xfptr = xfpos - (numxfs - 1);
504
505 xfptr += index;
506 ExtendedFormatRecord retval =
507 ( ExtendedFormatRecord ) records.get(xfptr);
508
509 return retval;
510 }
511
512
518
519 public ExtendedFormatRecord createCellXF()
520 {
521 ExtendedFormatRecord xf = createExtendedFormat();
522
523 ++xfpos;
524 ++bspos;
525 records.add(xfpos, xf);
526 numxfs++;
527 return xf;
528 }
529
530
538
539 public int addSSTString(String string, boolean use16bits)
540 {
541 log.log(DEBUG, "insert to sst string='", string, "' and use16bits= ",
542 new Boolean(use16bits));
543 if (sst == null)
544 {
545 insertSST();
546 }
547 return sst.addString(string, use16bits);
548 }
549
550
559
560 public int addSSTString(String string)
561 {
562 return addSSTString(string, false);
563 }
564
565
569
570 public String getSSTString(int str)
571 {
572 if (sst == null)
573 {
574 insertSST();
575 }
576 String retval = sst.getString(str);
577
578 log.log(DEBUG, "Returning SST for index=", new Integer(str),
579 " String= ", retval);
580 return retval;
581 }
582
583
589
590 public void insertSST()
591 {
592 log.log(DEBUG, "creating new SST via insertSST!");
593 sst = ( SSTRecord ) createSST();
594 records.add(records.size() - 1, createExtendedSST());
595 records.add(records.size() - 2, sst);
596 }
597
598
604
605 public byte [] serialize()
606 {
607 log.log(DEBUG, "Serializing Workbook!");
608 byte[] retval = null;
609
610
611 int arraysize = getSize();
612 int pos = 0;
613
614
615
616
617
618
619
620
621
622 retval = new byte[ arraysize ];
623 for (int k = 0; k < records.size(); k++)
624 {
625
626
627
628 pos += (( Record ) records.get(k)).serialize(pos,
629 retval);
630 }
631 log.log(DEBUG, "Exiting serialize workbook");
632 return retval;
633 }
634
635
641
642 public int serialize(int offset, byte [] data)
643 {
644 log.log(DEBUG, "Serializing Workbook with offsets");
645
646
647
648 int pos = 0;
649
650
651
652
653
654
655
656
657
658
659 for (int k = 0; k < records.size(); k++)
660 {
661
662
663
664 pos += (( Record ) records.get(k)).serialize(pos + offset,
665 data);
666 }
667 log.log(DEBUG, "Exiting serialize workbook");
668 return pos;
669 }
670
671 public int getSize()
672 {
673 int retval = 0;
674
675 for (int k = 0; k < records.size(); k++)
676 {
677 retval += (( Record ) records.get(k)).getRecordSize();
678 }
679 return retval;
680 }
681
682
688
689 protected Record createBOF()
690 {
691 BOFRecord retval = new BOFRecord();
692
693 retval.setVersion(( short ) 0x600);
694 retval.setType(( short ) 5);
695 retval.setBuild(( short ) 0x10d3);
696
697
698 retval.setBuildYear(( short ) 1996);
699 retval.setHistoryBitMask(0x41);
700 retval.setRequiredVersion(0x6);
701 return retval;
702 }
703
704
710
711 protected Record createInterfaceHdr()
712 {
713 InterfaceHdrRecord retval = new InterfaceHdrRecord();
714
715 retval.setCodepage(CODEPAGE);
716 return retval;
717 }
718
719
725
726 protected Record createMMS()
727 {
728 MMSRecord retval = new MMSRecord();
729
730 retval.setAddMenuCount(( byte ) 0);
731 retval.setDelMenuCount(( byte ) 0);
732 return retval;
733 }
734
735
741
742 protected Record createInterfaceEnd()
743 {
744 return new InterfaceEndRecord();
745 }
746
747
753
754 protected Record createWriteAccess()
755 {
756 WriteAccessRecord retval = new WriteAccessRecord();
757
758 retval.setUsername(System.getProperty("user.name"));
759 return retval;
760 }
761
762
768
769 protected Record createCodepage()
770 {
771 CodepageRecord retval = new CodepageRecord();
772
773 retval.setCodepage(CODEPAGE);
774 return retval;
775 }
776
777
783
784 protected Record createDSF()
785 {
786 DSFRecord retval = new DSFRecord();
787
788 retval.setDsf(
789 ( short ) 0);
790 return retval;
791 }
792
793
800
801 protected Record createTabId()
802 {
803 TabIdRecord retval = new TabIdRecord();
804 short[] tabidarray =
805 {
806 0
807 };
808
809 retval.setTabIdArray(tabidarray);
810 return retval;
811 }
812
813
819
820 protected Record createFnGroupCount()
821 {
822 FnGroupCountRecord retval = new FnGroupCountRecord();
823
824 retval.setCount(( short ) 14);
825 return retval;
826 }
827
828
834
835 protected Record createWindowProtect()
836 {
837 WindowProtectRecord retval = new WindowProtectRecord();
838
839 retval.setProtect(
840 false);
841 return retval;
842 }
843
844
850
851 protected Record createProtect()
852 {
853 ProtectRecord retval = new ProtectRecord();
854
855 retval.setProtect(
856 false);
857 return retval;
858 }
859
860
866
867 protected Record createPassword()
868 {
869 PasswordRecord retval = new PasswordRecord();
870
871 retval.setPassword(( short ) 0);
872 return retval;
873 }
874
875
881
882 protected Record createProtectionRev4()
883 {
884 ProtectionRev4Record retval = new ProtectionRev4Record();
885
886 retval.setProtect(false);
887 return retval;
888 }
889
890
896
897 protected Record createPasswordRev4()
898 {
899 PasswordRev4Record retval = new PasswordRev4Record();
900
901 retval.setPassword(( short ) 0);
902 return retval;
903 }
904
905
920
921 protected Record createWindowOne()
922 {
923 WindowOneRecord retval = new WindowOneRecord();
924
925 retval.setHorizontalHold(( short ) 0x168);
926 retval.setVerticalHold(( short ) 0x10e);
927 retval.setWidth(( short ) 0x3a5c);
928 retval.setHeight(( short ) 0x23be);
929 retval.setOptions(( short ) 0x38);
930 retval.setSelectedTab(( short ) 0x0);
931 retval.setDisplayedTab(( short ) 0x0);
932 retval.setNumSelectedTabs(( short ) 1);
933 retval.setTabWidthRatio(( short ) 0x258);
934 return retval;
935 }
936
937
943
944 protected Record createBackup()
945 {
946 BackupRecord retval = new BackupRecord();
947
948 retval.setBackup(
949 ( short ) 0);
950 return retval;
951 }
952
953
959
960 protected Record createHideObj()
961 {
962 HideObjRecord retval = new HideObjRecord();
963
964 retval.setHideObj(( short ) 0);
965 return retval;
966 }
967
968
974
975 protected Record createDateWindow1904()
976 {
977 DateWindow1904Record retval = new DateWindow1904Record();
978
979 retval.setWindowing(
980 ( short ) 0);
981 return retval;
982 }
983
984
990
991 protected Record createPrecision()
992 {
993 PrecisionRecord retval = new PrecisionRecord();
994
995 retval.setFullPrecision(
996 true);
997 return retval;
998 }
999
1000
1006
1007 protected Record createRefreshAll()
1008 {
1009 RefreshAllRecord retval = new RefreshAllRecord();
1010
1011 retval.setRefreshAll(false);
1012 return retval;
1013 }
1014
1015
1021
1022 protected Record createBookBool()
1023 {
1024 BookBoolRecord retval = new BookBoolRecord();
1025
1026 retval.setSaveLinkValues(( short ) 0);
1027 return retval;
1028 }
1029
1030
1043
1044 protected Record createFont()
1045 {
1046 FontRecord retval = new FontRecord();
1047
1048 retval.setFontHeight(( short ) 0xc8);
1049 retval.setAttributes(( short ) 0x0);
1050 retval.setColorPaletteIndex(( short ) 0x7fff);
1051 retval.setBoldWeight(( short ) 0x190);
1052 retval.setFontNameLength(( byte ) 5);
1053 retval.setFontName("Arial");
1054 return retval;
1055 }
1056
1057
1065
1066 protected Record createFormat(int id)
1067 {
1068 FormatRecord retval = new FormatRecord();
1069
1070 switch (id)
1071 {
1072
1073 case 0 :
1074 retval.setIndexCode(( short ) 5);
1075 retval.setFormatStringLength(( byte ) 0x17);
1076 retval.setFormatString("\"$\"#,##0_);\\(\"$\"#,##0\\)");
1077 break;
1078
1079 case 1 :
1080 retval.setIndexCode(( short ) 6);
1081 retval.setFormatStringLength(( byte ) 0x1c);
1082 retval.setFormatString("\"$\"#,##0_);[Red]\\(\"$\"#,##0\\)");
1083 break;
1084
1085 case 2 :
1086 retval.setIndexCode(( short ) 7);
1087 retval.setFormatStringLength(( byte ) 0x1d);
1088 retval.setFormatString("\"$\"#,##0.00_);\\(\"$\"#,##0.00\\)");
1089 break;
1090
1091 case 3 :
1092 retval.setIndexCode(( short ) 8);
1093 retval.setFormatStringLength(( byte ) 0x22);
1094 retval.setFormatString(
1095 "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)");
1096 break;
1097
1098 case 4 :
1099 retval.setIndexCode(( short ) 0x2a);
1100 retval.setFormatStringLength(( byte ) 0x32);
1101 retval.setFormatString(
1102 "_(\"$\"* #,##0_);_(\"$\"* \\(#,##0\\);_(\"$\"* \"-\"_);_(@_)");
1103 break;
1104
1105 case 5 :
1106 retval.setIndexCode(( short ) 0x29);
1107 retval.setFormatStringLength(( byte ) 0x29);
1108 retval.setFormatString(
1109 "_(* #,##0_);_(* \\(#,##0\\);_(* \"-\"_);_(@_)");
1110 break;
1111
1112 case 6 :
1113 retval.setIndexCode(( short ) 0x2c);
1114 retval.setFormatStringLength(( byte ) 0x3a);
1115 retval.setFormatString(
1116 "_(\"$\"* #,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)");
1117 break;
1118
1119 case 7 :
1120 retval.setIndexCode(( short ) 0x2b);
1121 retval.setFormatStringLength(( byte ) 0x31);
1122 retval.setFormatString(
1123 "_(* #,##0.00_);_(* \\(#,##0.00\\);_(* \"-\"??_);_(@_)");
1124 break;
1125 }
1126 return retval;
1127 }
1128
1129
1138
1139 protected Record createExtendedFormat(int id)
1140 {
1141 ExtendedFormatRecord retval = new ExtendedFormatRecord();
1142
1143 switch (id)
1144 {
1145
1146 case 0 :
1147 retval.setFontIndex(( short ) 0);
1148 retval.setFormatIndex(( short ) 0);
1149 retval.setCellOptions(( short ) 0xfffffff5);
1150 retval.setAlignmentOptions(( short ) 0x20);
1151 retval.setIndentionOptions(( short ) 0);
1152 retval.setBorderOptions(( short ) 0);
1153 retval.setPaletteOptions(( short ) 0);
1154 retval.setAdtlPaletteOptions(( short ) 0);
1155 retval.setFillPaletteOptions(( short ) 0x20c0);
1156 break;
1157
1158 case 1 :
1159 retval.setFontIndex(( short ) 1);
1160 retval.setFormatIndex(( short ) 0);
1161 retval.setCellOptions(( short ) 0xfffffff5);
1162 retval.setAlignmentOptions(( short ) 0x20);
1163 retval.setIndentionOptions(( short ) 0xfffff400);
1164 retval.setBorderOptions(( short ) 0);
1165 retval.setPaletteOptions(( short ) 0);
1166 retval.setAdtlPaletteOptions(( short ) 0);
1167 retval.setFillPaletteOptions(( short ) 0x20c0);
1168 break;
1169
1170 case 2 :
1171 retval.setFontIndex(( short ) 1);
1172 retval.setFormatIndex(( short ) 0);
1173 retval.setCellOptions(( short ) 0xfffffff5);
1174 retval.setAlignmentOptions(( short ) 0x20);
1175 retval.setIndentionOptions(( short ) 0xfffff400);
1176 retval.setBorderOptions(( short ) 0);
1177 retval.setPaletteOptions(( short ) 0);
1178 retval.setAdtlPaletteOptions(( short ) 0);
1179 retval.setFillPaletteOptions(( short ) 0x20c0);
1180 break;
1181
1182 case 3 :
1183 retval.setFontIndex(( short ) 2);
1184 retval.setFormatIndex(( short ) 0);
1185 retval.setCellOptions(( short ) 0xfffffff5);
1186 retval.setAlignmentOptions(( short ) 0x20);
1187 retval.setIndentionOptions(( short ) 0xfffff400);
1188 retval.setBorderOptions(( short ) 0);
1189 retval.setPaletteOptions(( short ) 0);
1190 retval.setAdtlPaletteOptions(( short ) 0);
1191 retval.setFillPaletteOptions(( short ) 0x20c0);
1192 break;
1193
1194 case 4 :
1195 retval.setFontIndex(( short ) 2);
1196 retval.setFormatIndex(( short ) 0);
1197 retval.setCellOptions(( short ) 0xfffffff5);
1198 retval.setAlignmentOptions(( short ) 0x20);
1199 retval.setIndentionOptions(( short ) 0xfffff400);
1200 retval.setBorderOptions(( short ) 0);
1201 retval.setPaletteOptions(( short ) 0);
1202 retval.setAdtlPaletteOptions(( short ) 0);
1203 retval.setFillPaletteOptions(( short ) 0x20c0);
1204 break;
1205
1206 case 5 :
1207 retval.setFontIndex(( short ) 0);
1208 retval.setFormatIndex(( short ) 0);
1209 retval.setCellOptions(( short ) 0xfffffff5);
1210 retval.setAlignmentOptions(( short ) 0x20);
1211 retval.setIndentionOptions(( short ) 0xfffff400);
1212 retval.setBorderOptions(( short ) 0);
1213 retval.setPaletteOptions(( short ) 0);
1214 retval.setAdtlPaletteOptions(( short ) 0);
1215 retval.setFillPaletteOptions(( short ) 0x20c0);
1216 break;
1217
1218 case 6 :
1219 retval.setFontIndex(( short ) 0);
1220 retval.setFormatIndex(( short ) 0);
1221 retval.setCellOptions(( short ) 0xfffffff5);
1222 retval.setAlignmentOptions(( short ) 0x20);
1223 retval.setIndentionOptions(( short ) 0xfffff400);
1224 retval.setBorderOptions(( short ) 0);
1225 retval.setPaletteOptions(( short ) 0);
1226 retval.setAdtlPaletteOptions(( short ) 0);
1227 retval.setFillPaletteOptions(( short ) 0x20c0);
1228 break;
1229
1230 case 7 :
1231 retval.setFontIndex(( short ) 0);
1232 retval.setFormatIndex(( short ) 0);
1233 retval.setCellOptions(( short ) 0xfffffff5);
1234 retval.setAlignmentOptions(( short ) 0x20);
1235 retval.setIndentionOptions(( short ) 0xfffff400);
1236 retval.setBorderOptions(( short ) 0);
1237 retval.setPaletteOptions(( short ) 0);
1238 retval.setAdtlPaletteOptions(( short ) 0);
1239 retval.setFillPaletteOptions(( short ) 0x20c0);
1240 break;
1241
1242 case 8 :
1243 retval.setFontIndex(( short ) 0);
1244 retval.setFormatIndex(( short ) 0);
1245 retval.setCellOptions(( short ) 0xfffffff5);
1246 retval.setAlignmentOptions(( short ) 0x20);
1247 retval.setIndentionOptions(( short ) 0xfffff400);
1248 retval.setBorderOptions(( short ) 0);
1249 retval.setPaletteOptions(( short ) 0);
1250 retval.setAdtlPaletteOptions(( short ) 0);
1251 retval.setFillPaletteOptions(( short ) 0x20c0);
1252 break;
1253
1254 case 9 :
1255 retval.setFontIndex(( short ) 0);
1256 retval.setFormatIndex(( short ) 0);
1257 retval.setCellOptions(( short ) 0xfffffff5);
1258 retval.setAlignmentOptions(( short ) 0x20);
1259 retval.setIndentionOptions(( short ) 0xfffff400);
1260 retval.setBorderOptions(( short ) 0);
1261 retval.setPaletteOptions(( short ) 0);
1262 retval.setAdtlPaletteOptions(( short ) 0);
1263 retval.setFillPaletteOptions(( short ) 0x20c0);
1264 break;
1265
1266 case 10 :
1267 retval.setFontIndex(( short ) 0);
1268 retval.setFormatIndex(( short ) 0);
1269 retval.setCellOptions(( short ) 0xfffffff5);
1270 retval.setAlignmentOptions(( short ) 0x20);
1271 retval.setIndentionOptions(( short ) 0xfffff400);
1272 retval.setBorderOptions(( short ) 0);
1273 retval.setPaletteOptions(( short ) 0);
1274 retval.setAdtlPaletteOptions(( short ) 0);
1275 retval.setFillPaletteOptions(( short ) 0x20c0);
1276 break;
1277
1278 case 11 :
1279 retval.setFontIndex(( short ) 0);
1280 retval.setFormatIndex(( short ) 0);
1281 retval.setCellOptions(( short ) 0xfffffff5);
1282 retval.setAlignmentOptions(( short ) 0x20);
1283 retval.setIndentionOptions(( short ) 0xfffff400);
1284 retval.setBorderOptions(( short ) 0);
1285 retval.setPaletteOptions(( short ) 0);
1286 retval.setAdtlPaletteOptions(( short ) 0);
1287 retval.setFillPaletteOptions(( short ) 0x20c0);
1288 break;
1289
1290 case 12 :
1291 retval.setFontIndex(( short ) 0);
1292 retval.setFormatIndex(( short ) 0);
1293 retval.setCellOptions(( short ) 0xfffffff5);
1294 retval.setAlignmentOptions(( short ) 0x20);
1295 retval.setIndentionOptions(( short ) 0xfffff400);
1296 retval.setBorderOptions(( short ) 0);
1297 retval.setPaletteOptions(( short ) 0);
1298 retval.setAdtlPaletteOptions(( short ) 0);
1299 retval.setFillPaletteOptions(( short ) 0x20c0);
1300 break;
1301
1302 case 13 :
1303 retval.setFontIndex(( short ) 0);
1304 retval.setFormatIndex(( short ) 0);
1305 retval.setCellOptions(( short ) 0xfffffff5);
1306 retval.setAlignmentOptions(( short ) 0x20);
1307 retval.setIndentionOptions(( short ) 0xfffff400);
1308 retval.setBorderOptions(( short ) 0);
1309 retval.setPaletteOptions(( short ) 0);
1310 retval.setAdtlPaletteOptions(( short ) 0);
1311 retval.setFillPaletteOptions(( short ) 0x20c0);
1312 break;
1313
1314 case 14 :
1315 retval.setFontIndex(( short ) 0);
1316 retval.setFormatIndex(( short ) 0);
1317 retval.setCellOptions(( short ) 0xfffffff5);
1318 retval.setAlignmentOptions(( short ) 0x20);
1319 retval.setIndentionOptions(( short ) 0xfffff400);
1320 retval.setBorderOptions(( short ) 0);
1321 retval.setPaletteOptions(( short ) 0);
1322 retval.setAdtlPaletteOptions(( short ) 0);
1323 retval.setFillPaletteOptions(( short ) 0x20c0);
1324 break;
1325
1326
1327 case 15 :
1328 retval.setFontIndex(( short ) 0);
1329 retval.setFormatIndex(( short ) 0);
1330 retval.setCellOptions(( short ) 0x1);
1331 retval.setAlignmentOptions(( short ) 0x20);
1332 retval.setIndentionOptions(( short ) 0x0);
1333 retval.setBorderOptions(( short ) 0);
1334 retval.setPaletteOptions(( short ) 0);
1335 retval.setAdtlPaletteOptions(( short ) 0);
1336 retval.setFillPaletteOptions(( short ) 0x20c0);
1337 break;
1338
1339
1340 case 16 :
1341 retval.setFontIndex(( short ) 1);
1342 retval.setFormatIndex(( short ) 0x2b);
1343 retval.setCellOptions(( short ) 0xfffffff5);
1344 retval.setAlignmentOptions(( short ) 0x20);
1345 retval.setIndentionOptions(( short ) 0xfffff800);
1346 retval.setBorderOptions(( short ) 0);
1347 retval.setPaletteOptions(( short ) 0);
1348 retval.setAdtlPaletteOptions(( short ) 0);
1349 retval.setFillPaletteOptions(( short ) 0x20c0);
1350 break;
1351
1352 case 17 :
1353 retval.setFontIndex(( short ) 1);
1354 retval.setFormatIndex(( short ) 0x29);
1355 retval.setCellOptions(( short ) 0xfffffff5);
1356 retval.setAlignmentOptions(( short ) 0x20);
1357 retval.setIndentionOptions(( short ) 0xfffff800);
1358 retval.setBorderOptions(( short ) 0);
1359 retval.setPaletteOptions(( short ) 0);
1360 retval.setAdtlPaletteOptions(( short ) 0);
1361 retval.setFillPaletteOptions(( short ) 0x20c0);
1362 break;
1363
1364 case 18 :
1365 retval.setFontIndex(( short ) 1);
1366 retval.setFormatIndex(( short ) 0x2c);
1367 retval.setCellOptions(( short ) 0xfffffff5);
1368 retval.setAlignmentOptions(( short ) 0x20);
1369 retval.setIndentionOptions(( short ) 0xfffff800);
1370 retval.setBorderOptions(( short ) 0);
1371 retval.setPaletteOptions(( short ) 0);
1372 retval.setAdtlPaletteOptions(( short ) 0);
1373 retval.setFillPaletteOptions(( short ) 0x20c0);
1374 break;
1375
1376 case 19 :
1377 retval.setFontIndex(( short ) 1);
1378 retval.setFormatIndex(( short ) 0x2a);
1379 retval.setCellOptions(( short ) 0xfffffff5);
1380 retval.setAlignmentOptions(( short ) 0x20);
1381 retval.setIndentionOptions(( short ) 0xfffff800);
1382 retval.setBorderOptions(( short ) 0);
1383 retval.setPaletteOptions(( short ) 0);
1384 retval.setAdtlPaletteOptions(( short ) 0);
1385 retval.setFillPaletteOptions(( short ) 0x20c0);
1386 break;
1387
1388 case 20 :
1389 retval.setFontIndex(( short ) 1);
1390 retval.setFormatIndex(( short ) 0x9);
1391 retval.setCellOptions(( short ) 0xfffffff5);
1392 retval.setAlignmentOptions(( short ) 0x20);
1393 retval.setIndentionOptions(( short ) 0xfffff800);
1394 retval.setBorderOptions(( short ) 0);
1395 retval.setPaletteOptions(( short ) 0);
1396 retval.setAdtlPaletteOptions(( short ) 0);
1397 retval.setFillPaletteOptions(( short ) 0x20c0);
1398 break;
1399
1400
1401 case 21 :
1402 retval.setFontIndex(( short ) 5);
1403 retval.setFormatIndex(( short ) 0x0);
1404 retval.setCellOptions(( short ) 0x1);
1405 retval.setAlignmentOptions(( short ) 0x20);
1406 retval.setIndentionOptions(( short ) 0x800);
1407 retval.setBorderOptions(( short ) 0);
1408 retval.setPaletteOptions(( short ) 0);
1409 retval.setAdtlPaletteOptions(( short ) 0);
1410 retval.setFillPaletteOptions(( short ) 0x20c0);
1411 break;
1412
1413 case 22 :
1414 retval.setFontIndex(( short ) 6);
1415 retval.setFormatIndex(( short ) 0x0);
1416 retval.setCellOptions(( short ) 0x1);
1417 retval.setAlignmentOptions(( short ) 0x20);
1418 retval.setIndentionOptions(( short ) 0x5c00);
1419 retval.setBorderOptions(( short ) 0);
1420 retval.setPaletteOptions(( short ) 0);
1421 retval.setAdtlPaletteOptions(( short ) 0);
1422 retval.setFillPaletteOptions(( short ) 0x20c0);
1423 break;
1424
1425 case 23 :
1426 retval.setFontIndex(( short ) 0);
1427 retval.setFormatIndex(( short ) 0x31);
1428 retval.setCellOptions(( short ) 0x1);
1429 retval.setAlignmentOptions(( short ) 0x20);
1430 retval.setIndentionOptions(( short ) 0x5c00);
1431 retval.setBorderOptions(( short ) 0);
1432 retval.setPaletteOptions(( short ) 0);
1433 retval.setAdtlPaletteOptions(( short ) 0);
1434 retval.setFillPaletteOptions(( short ) 0x20c0);
1435 break;
1436
1437 case 24 :
1438 retval.setFontIndex(( short ) 0);
1439 retval.setFormatIndex(( short ) 0x8);
1440 retval.setCellOptions(( short ) 0x1);
1441 retval.setAlignmentOptions(( short ) 0x20);
1442 retval.setIndentionOptions(( short ) 0x5c00);
1443 retval.setBorderOptions(( short ) 0);
1444 retval.setPaletteOptions(( short ) 0);
1445 retval.setAdtlPaletteOptions(( short ) 0);
1446 retval.setFillPaletteOptions(( short ) 0x20c0);
1447 break;
1448
1449 case 25 :
1450 retval.setFontIndex(( short ) 6);
1451 retval.setFormatIndex(( short ) 0x8);
1452 retval.setCellOptions(( short ) 0x1);
1453 retval.setAlignmentOptions(( short ) 0x20);
1454 retval.setIndentionOptions(( short ) 0x5c00);
1455 retval.setBorderOptions(( short ) 0);
1456 retval.setPaletteOptions(( short ) 0);
1457 retval.setAdtlPaletteOptions(( short ) 0);
1458 retval.setFillPaletteOptions(( short ) 0x20c0);
1459 break;
1460 }
1461 return retval;
1462 }
1463
1464
1468
1469 protected ExtendedFormatRecord createExtendedFormat()
1470 {
1471 ExtendedFormatRecord retval = new ExtendedFormatRecord();
1472
1473 retval.setFontIndex(( short ) 0);
1474 retval.setFormatIndex(( short ) 0x0);
1475 retval.setCellOptions(( short ) 0x1);
1476 retval.setAlignmentOptions(( short ) 0x20);
1477 retval.setIndentionOptions(( short ) 0);
1478 retval.setBorderOptions(( short ) 0);
1479 retval.setPaletteOptions(( short ) 0);
1480 retval.setAdtlPaletteOptions(( short ) 0);
1481 retval.setFillPaletteOptions(( short ) 0x20c0);
1482 return retval;
1483 }
1484
1485
1493
1494 protected Record createStyle(int id)
1495 {
1496 StyleRecord retval = new StyleRecord();
1497
1498 switch (id)
1499 {
1500
1501 case 0 :
1502 retval.setIndex(( short ) 0xffff8010);
1503 retval.setBuiltin(( byte ) 3);
1504 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1505 break;
1506
1507 case 1 :
1508 retval.setIndex(( short ) 0xffff8011);
1509 retval.setBuiltin(( byte ) 6);
1510 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1511 break;
1512
1513 case 2 :
1514 retval.setIndex(( short ) 0xffff8012);
1515 retval.setBuiltin(( byte ) 4);
1516 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1517 break;
1518
1519 case 3 :
1520 retval.setIndex(( short ) 0xffff8013);
1521 retval.setBuiltin(( byte ) 7);
1522 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1523 break;
1524
1525 case 4 :
1526 retval.setIndex(( short ) 0xffff8000);
1527 retval.setBuiltin(( byte ) 0);
1528 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1529 break;
1530
1531 case 5 :
1532 retval.setIndex(( short ) 0xffff8014);
1533 retval.setBuiltin(( byte ) 5);
1534 retval.setOutlineStyleLevel(( byte ) 0xffffffff);
1535 break;
1536 }
1537 return retval;
1538 }
1539
1540
1546
1547 protected Record createUseSelFS()
1548 {
1549 UseSelFSRecord retval = new UseSelFSRecord();
1550
1551 retval.setFlag(( short ) 0);
1552 return retval;
1553 }
1554
1555
1563
1564 protected Record createBoundSheet(int id)
1565 {
1566 BoundSheetRecord retval = new BoundSheetRecord();
1567
1568 switch (id)
1569 {
1570
1571 case 0 :
1572 retval.setPositionOfBof(0x0);
1573 retval.setOptionFlags(( short ) 0);
1574 retval.setSheetnameLength(( byte ) 0x6);
1575 retval.setCompressedUnicodeFlag(( byte ) 0);
1576 retval.setSheetname("Sheet1");
1577 break;
1578
1579 case 1 :
1580 retval.setPositionOfBof(0x0);
1581 retval.setOptionFlags(( short ) 0);
1582 retval.setSheetnameLength(( byte ) 0x6);
1583 retval.setCompressedUnicodeFlag(( byte ) 0);
1584 retval.setSheetname("Sheet2");
1585 break;
1586
1587 case 2 :
1588 retval.setPositionOfBof(0x0);
1589 retval.setOptionFlags(( short ) 0);
1590 retval.setSheetnameLength(( byte ) 0x6);
1591 retval.setCompressedUnicodeFlag(( byte ) 0);
1592 retval.setSheetname("Sheet3");
1593 break;
1594 }
1595 return retval;
1596 }
1597
1598
1604
1605 protected Record createCountry()
1606 {
1607 CountryRecord retval = new CountryRecord();
1608
1609 retval.setDefaultCountry(( short ) 1);
1610 retval.setCurrentCountry(( short ) 1);
1611 return retval;
1612 }
1613
1614
1620
1621 protected Record createSST()
1622 {
1623 return new SSTRecord();
1624 }
1625
1626
1635
1636 protected Record createExtendedSST()
1637 {
1638 ExtSSTRecord retval = new ExtSSTRecord();
1639
1640 retval.setNumStringsPerBucket(( short ) 0x8);
1641 return retval;
1642 }
1643
1644
1650
1651 protected Record createEOF()
1652 {
1653 return new EOFRecord();
1654 }
1655
1656
1659
1660 public Record findFirstRecordBySid(short sid)
1661 {
1662 for (Iterator iterator = records.iterator(); iterator.hasNext(); )
1663 {
1664 Record record = ( Record ) iterator.next();
1665
1666 if (record.getSid() == sid)
1667 {
1668 return record;
1669 }
1670 }
1671 return null;
1672 }
1673 }
1674