1 2 17 18 19 package org.apache.poi.hssf.model; 20 21 import org.apache.poi.hssf.record.*; 22 import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate; 23 import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate; 24 import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate; 25 import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate; 26 import org.apache.poi.hssf.record.formula.Ptg; 27 import org.apache.poi.util.POILogFactory; 28 import org.apache.poi.util.POILogger; 29 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 55 56 public class Sheet implements Model 57 { 58 public static final short LeftMargin = 0; 59 public static final short RightMargin = 1; 60 public static final short TopMargin = 2; 61 public static final short BottomMargin = 3; 62 63 private static POILogger log = POILogFactory.getLogger(Sheet.class); 64 65 protected ArrayList records = null; 66 int preoffset = 0; int loc = 0; 68 protected boolean containsLabels = false; 69 protected int dimsloc = 0; 70 protected DimensionsRecord dims; 71 protected DefaultColWidthRecord defaultcolwidth = null; 72 protected DefaultRowHeightRecord defaultrowheight = null; 73 protected GridsetRecord gridset = null; 74 protected PrintSetupRecord printSetup = null; 75 protected HeaderRecord header = null; 76 protected FooterRecord footer = null; 77 protected PrintGridlinesRecord printGridlines = null; 78 protected WindowTwoRecord windowTwo = null; 79 protected MergeCellsRecord merged = null; 80 protected Margin[] margins = null; 81 protected List mergedRecords = new ArrayList (); 82 protected int numMergedRegions = 0; 83 protected SelectionRecord selection = null; 84 protected ColumnInfoRecordsAggregate columns = null; 85 protected ValueRecordsAggregate cells = null; 86 protected RowRecordsAggregate rows = null; 87 private Iterator valueRecIterator = null; 88 private Iterator rowRecIterator = null; 89 protected int eofLoc = 0; 90 protected ProtectRecord protect = null; 91 protected PageBreakRecord rowBreaks = null; 92 protected PageBreakRecord colBreaks = null; 93 94 95 public static final byte PANE_LOWER_RIGHT = (byte)0; 96 public static final byte PANE_UPPER_RIGHT = (byte)1; 97 public static final byte PANE_LOWER_LEFT = (byte)2; 98 public static final byte PANE_UPPER_LEFT = (byte)3; 99 100 104 public Sheet() 105 { 106 } 107 108 125 public static Sheet createSheet(List recs, int sheetnum, int offset) 126 { 127 if (log.check( POILogger.DEBUG )) 128 log.logFormatted(POILogger.DEBUG, 129 "Sheet createSheet (existing file) with %", 130 new Integer (recs.size())); 131 Sheet retval = new Sheet(); 132 ArrayList records = new ArrayList (recs.size() / 5); 133 boolean isfirstcell = true; 134 boolean isfirstrow = true; 135 int bofEofNestingLevel = 0; 136 137 for (int k = offset; k < recs.size(); k++) 138 { 139 Record rec = ( Record ) recs.get(k); 140 141 if (rec.getSid() == LabelRecord.sid) 142 { 143 if (log.check( POILogger.DEBUG )) 144 log.log(POILogger.DEBUG, "Hit label record."); 145 retval.containsLabels = true; 146 } 147 else if (rec.getSid() == BOFRecord.sid) 148 { 149 bofEofNestingLevel++; 150 if (log.check( POILogger.DEBUG )) 151 log.log(POILogger.DEBUG, "Hit BOF record. Nesting increased to " + bofEofNestingLevel); 152 } 153 else if (rec.getSid() == EOFRecord.sid) 154 { 155 --bofEofNestingLevel; 156 if (log.check( POILogger.DEBUG )) 157 log.log(POILogger.DEBUG, "Hit EOF record. Nesting decreased to " + bofEofNestingLevel); 158 if (bofEofNestingLevel == 0) { 159 records.add(rec); 160 retval.eofLoc = k; 161 break; 162 } 163 } 164 else if (rec.getSid() == DimensionsRecord.sid) 165 { 166 if (retval.columns == null) 168 { 169 retval.columns = new ColumnInfoRecordsAggregate(); 170 records.add(retval.columns); 171 } 172 173 retval.dims = ( DimensionsRecord ) rec; 174 retval.dimsloc = records.size(); 175 } 176 else if (rec.getSid() == MergeCellsRecord.sid) 177 { 178 retval.mergedRecords.add(rec); 179 retval.merged = ( MergeCellsRecord ) rec; 180 retval.numMergedRegions += retval.merged.getNumAreas(); 181 } 182 else if (rec.getSid() == ColumnInfoRecord.sid) 183 { 184 ColumnInfoRecord col = (ColumnInfoRecord)rec; 185 if (retval.columns != null) 186 { 187 rec = null; } 189 else 190 { 191 rec = retval.columns = new ColumnInfoRecordsAggregate(); 192 } 193 retval.columns.insertColumn(col); 194 } 195 else if (rec.getSid() == DefaultColWidthRecord.sid) 196 { 197 retval.defaultcolwidth = ( DefaultColWidthRecord ) rec; 198 } 199 else if (rec.getSid() == DefaultRowHeightRecord.sid) 200 { 201 retval.defaultrowheight = ( DefaultRowHeightRecord ) rec; 202 } 203 else if ( rec.isValue() && bofEofNestingLevel == 1 ) 204 { 205 if ( isfirstcell ) 206 { 207 retval.cells = new ValueRecordsAggregate(); 208 rec = retval.cells; 209 retval.cells.construct( k, recs ); 210 isfirstcell = false; 211 } 212 else 213 { 214 rec = null; 215 } 216 } 217 else if ( rec.getSid() == StringRecord.sid ) 218 { 219 rec = null; 220 } 221 else if ( rec.getSid() == RowRecord.sid ) 222 { 223 RowRecord row = (RowRecord)rec; 224 if (!isfirstrow) rec = null; 226 if ( isfirstrow ) 227 { 228 retval.rows = new RowRecordsAggregate(); 229 rec = retval.rows; 230 isfirstrow = false; 231 } 232 retval.rows.insertRow(row); 233 } 234 else if ( rec.getSid() == PrintGridlinesRecord.sid ) 235 { 236 retval.printGridlines = (PrintGridlinesRecord) rec; 237 } 238 else if ( rec.getSid() == HeaderRecord.sid && bofEofNestingLevel == 1) 239 { 240 retval.header = (HeaderRecord) rec; 241 } 242 else if ( rec.getSid() == FooterRecord.sid && bofEofNestingLevel == 1) 243 { 244 retval.footer = (FooterRecord) rec; 245 } 246 else if ( rec.getSid() == PrintSetupRecord.sid && bofEofNestingLevel == 1) 247 { 248 retval.printSetup = (PrintSetupRecord) rec; 249 } 250 else if ( rec.getSid() == LeftMarginRecord.sid) 251 { 252 retval.getMargins()[LeftMargin] = (LeftMarginRecord) rec; 253 } 254 else if ( rec.getSid() == RightMarginRecord.sid) 255 { 256 retval.getMargins()[RightMargin] = (RightMarginRecord) rec; 257 } 258 else if ( rec.getSid() == TopMarginRecord.sid) 259 { 260 retval.getMargins()[TopMargin] = (TopMarginRecord) rec; 261 } 262 else if ( rec.getSid() == BottomMarginRecord.sid) 263 { 264 retval.getMargins()[BottomMargin] = (BottomMarginRecord) rec; 265 } 266 else if ( rec.getSid() == SelectionRecord.sid ) 267 { 268 retval.selection = (SelectionRecord) rec; 269 } 270 else if ( rec.getSid() == WindowTwoRecord.sid ) 271 { 272 retval.windowTwo = (WindowTwoRecord) rec; 273 } 274 else if ( rec.getSid() == DBCellRecord.sid ) 275 { 276 rec = null; 277 } 278 else if ( rec.getSid() == IndexRecord.sid ) 279 { 280 rec = null; 281 } 282 283 else if ( rec.getSid() == ProtectRecord.sid ) 284 { 285 retval.protect = (ProtectRecord) rec; 286 } 287 else if (rec.getSid() == PageBreakRecord.HORIZONTAL_SID) 288 { 289 retval.rowBreaks = (PageBreakRecord)rec; 290 } 291 else if (rec.getSid() == PageBreakRecord.VERTICAL_SID) 292 { 293 retval.colBreaks = (PageBreakRecord)rec; 294 } 295 296 if (rec != null) 297 { 298 records.add(rec); 299 } 300 } 301 retval.records = records; 302 retval.checkCells(); 307 retval.checkRows(); 308 if (log.check( POILogger.DEBUG )) 313 log.log(POILogger.DEBUG, "sheet createSheet (existing file) exited"); 314 return retval; 315 } 316 317 324 public Sheet cloneSheet() 325 { 326 ArrayList clonedRecords = new ArrayList (this.records.size()); 327 for (int i=0; i<this.records.size();i++) { 328 Record rec = (Record)((Record)this.records.get(i)).clone(); 329 if (rec instanceof RowRecordsAggregate) { 334 RowRecordsAggregate rrAgg = (RowRecordsAggregate)rec; 335 for (Iterator rowIter = rrAgg.getIterator();rowIter.hasNext();) { 336 Record rowRec = (Record)rowIter.next(); 337 clonedRecords.add(rowRec); 338 } 339 } else if (rec instanceof ValueRecordsAggregate) { 340 ValueRecordsAggregate vrAgg = (ValueRecordsAggregate)rec; 341 for (Iterator cellIter = vrAgg.getIterator();cellIter.hasNext();) { 342 Record valRec = (Record)cellIter.next(); 343 clonedRecords.add(valRec); 344 } 345 } else if (rec instanceof FormulaRecordAggregate) { 346 FormulaRecordAggregate fmAgg = (FormulaRecordAggregate)rec; 347 Record fmAggRec = fmAgg.getFormulaRecord(); 348 if (fmAggRec != null) 349 clonedRecords.add(fmAggRec); 350 fmAggRec = fmAgg.getStringRecord(); 351 if (fmAggRec != null) 352 clonedRecords.add(fmAggRec); 353 } else { 354 clonedRecords.add(rec); 355 } 356 } 357 return createSheet(clonedRecords, 0, 0); 358 } 359 360 361 369 370 public static Sheet createSheet(List records, int sheetnum) 371 { 372 if (log.check( POILogger.DEBUG )) 373 log.log(POILogger.DEBUG, 374 "Sheet createSheet (exisiting file) assumed offset 0"); 375 return createSheet(records, sheetnum, 0); 376 } 377 378 385 386 public static Sheet createSheet() 387 { 388 if (log.check( POILogger.DEBUG )) 389 log.log(POILogger.DEBUG, "Sheet createsheet from scratch called"); 390 Sheet retval = new Sheet(); 391 ArrayList records = new ArrayList (30); 392 393 records.add(retval.createBOF()); 394 395 records.add(retval.createCalcMode()); 397 records.add(retval.createCalcCount() ); 398 records.add( retval.createRefMode() ); 399 records.add( retval.createIteration() ); 400 records.add( retval.createDelta() ); 401 records.add( retval.createSaveRecalc() ); 402 records.add( retval.createPrintHeaders() ); 403 retval.printGridlines = (PrintGridlinesRecord) retval.createPrintGridlines(); 404 records.add( retval.printGridlines ); 405 retval.gridset = (GridsetRecord) retval.createGridset(); 406 records.add( retval.gridset ); 407 records.add( retval.createGuts() ); 408 retval.defaultrowheight = 409 (DefaultRowHeightRecord) retval.createDefaultRowHeight(); 410 records.add( retval.defaultrowheight ); 411 records.add( retval.createWSBool() ); 412 413 retval.rowBreaks = new PageBreakRecord(PageBreakRecord.HORIZONTAL_SID); 414 records.add(retval.rowBreaks); 415 retval.colBreaks = new PageBreakRecord(PageBreakRecord.VERTICAL_SID); 416 records.add(retval.colBreaks); 417 418 retval.header = (HeaderRecord) retval.createHeader(); 419 records.add( retval.header ); 420 retval.footer = (FooterRecord) retval.createFooter(); 421 records.add( retval.footer ); 422 records.add( retval.createHCenter() ); 423 records.add( retval.createVCenter() ); 424 retval.printSetup = (PrintSetupRecord) retval.createPrintSetup(); 425 records.add( retval.printSetup ); 426 retval.defaultcolwidth = 427 (DefaultColWidthRecord) retval.createDefaultColWidth(); 428 records.add( retval.defaultcolwidth); 429 ColumnInfoRecordsAggregate columns = new ColumnInfoRecordsAggregate(); 430 records.add( columns ); 431 retval.columns = columns; 432 retval.dims = ( DimensionsRecord ) retval.createDimensions(); 433 records.add(retval.dims); 434 retval.dimsloc = records.size()-1; 435 records.add(retval.windowTwo = retval.createWindowTwo()); 436 retval.setLoc(records.size() - 1); 437 retval.selection = 438 (SelectionRecord) retval.createSelection(); 439 records.add(retval.selection); 440 retval.protect = (ProtectRecord) retval.createProtect(); 441 records.add(retval.protect); 442 records.add(retval.createEOF()); 443 444 445 retval.records = records; 446 if (log.check( POILogger.DEBUG )) 447 log.log(POILogger.DEBUG, "Sheet createsheet from scratch exit"); 448 return retval; 449 } 450 451 private void checkCells() 452 { 453 if (cells == null) 454 { 455 cells = new ValueRecordsAggregate(); 456 records.add(getDimsLoc() + 1, cells); 457 } 458 } 459 460 private void checkRows() 461 { 462 if (rows == null) 463 { 464 rows = new RowRecordsAggregate(); 465 records.add(getDimsLoc() + 1, rows); 466 } 467 } 468 469 public int addMergedRegion(int rowFrom, short colFrom, int rowTo, 471 short colTo) 472 { 473 if (merged == null || merged.getNumAreas() == 1027) 474 { 475 merged = ( MergeCellsRecord ) createMergedCells(); 476 mergedRecords.add(merged); 477 records.add(records.size() - 1, merged); 478 } 479 merged.addArea(rowFrom, colFrom, rowTo, colTo); 480 return numMergedRegions++; 481 } 482 483 public void removeMergedRegion(int index) 484 { 485 if (index >= numMergedRegions || mergedRecords.size() == 0) 487 return; 488 489 int pos = 0; 490 int startNumRegions = 0; 491 492 if (numMergedRegions - index < merged.getNumAreas()) 494 { 495 pos = mergedRecords.size() - 1; 496 startNumRegions = numMergedRegions - merged.getNumAreas(); 497 } 498 else 499 { 500 for (int n = 0; n < mergedRecords.size(); n++) 501 { 502 MergeCellsRecord record = (MergeCellsRecord) mergedRecords.get(n); 503 if (startNumRegions + record.getNumAreas() > index) 504 { 505 pos = n; 506 break; 507 } 508 startNumRegions += record.getNumAreas(); 509 } 510 } 511 512 MergeCellsRecord rec = (MergeCellsRecord) mergedRecords.get(pos); 513 rec.removeAreaAt(index - startNumRegions); 514 numMergedRegions--; 515 if (rec.getNumAreas() == 0) 516 { 517 mergedRecords.remove(pos); 518 records.remove(merged); 520 if (merged == rec) { 521 if (mergedRecords.size() > 0) { 524 merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1); 525 } else { 526 merged = null; 527 } 528 } 529 } 530 } 531 532 public MergeCellsRecord.MergedRegion getMergedRegionAt(int index) 533 { 534 if (index >= numMergedRegions || mergedRecords.size() == 0) 536 return null; 537 538 int pos = 0; 539 int startNumRegions = 0; 540 541 if (numMergedRegions - index < merged.getNumAreas()) 543 { 544 pos = mergedRecords.size() - 1; 545 startNumRegions = numMergedRegions - merged.getNumAreas(); 546 } 547 else 548 { 549 for (int n = 0; n < mergedRecords.size(); n++) 550 { 551 MergeCellsRecord record = (MergeCellsRecord) mergedRecords.get(n); 552 if (startNumRegions + record.getNumAreas() > index) 553 { 554 pos = n; 555 break; 556 } 557 startNumRegions += record.getNumAreas(); 558 } 559 } 560 return ((MergeCellsRecord) mergedRecords.get(pos)).getAreaAt(index - startNumRegions); 561 } 562 563 public int getNumMergedRegions() 564 { 565 return numMergedRegions; 566 } 567 568 583 584 public void convertLabelRecords(Workbook wb) 585 { 586 if (log.check( POILogger.DEBUG )) 587 log.log(POILogger.DEBUG, "convertLabelRecords called"); 588 if (containsLabels) 589 { 590 for (int k = 0; k < records.size(); k++) 591 { 592 Record rec = ( Record ) records.get(k); 593 594 if (rec.getSid() == LabelRecord.sid) 595 { 596 LabelRecord oldrec = ( LabelRecord ) rec; 597 598 records.remove(k); 599 LabelSSTRecord newrec = new LabelSSTRecord(); 600 int stringid = 601 wb.addSSTString(oldrec.getValue()); 602 603 newrec.setRow(oldrec.getRow()); 604 newrec.setColumn(oldrec.getColumn()); 605 newrec.setXFIndex(oldrec.getXFIndex()); 606 newrec.setSSTIndex(stringid); 607 records.add(k, newrec); 608 } 609 } 610 } 611 if (log.check( POILogger.DEBUG )) 612 log.log(POILogger.DEBUG, "convertLabelRecords exit"); 613 } 614 615 621 622 public int getNumRecords() 623 { 624 checkCells(); 625 checkRows(); 626 if (log.check( POILogger.DEBUG )) 627 { 628 log.log(POILogger.DEBUG, "Sheet.getNumRecords"); 629 log.logFormatted(POILogger.DEBUG, "returning % + % + % - 2 = %", new int[] 630 { 631 records.size(), cells.getPhysicalNumberOfCells(), 632 rows.getPhysicalNumberOfRows(), 633 records.size() + cells.getPhysicalNumberOfCells() 634 + rows.getPhysicalNumberOfRows() - 2 635 }); 636 } 637 return records.size() + cells.getPhysicalNumberOfCells() 638 + rows.getPhysicalNumberOfRows() - 2; 639 } 640 641 648 649 public void setDimensions(int firstrow, short firstcol, int lastrow, 651 short lastcol) 652 { 653 if (log.check( POILogger.DEBUG )) 654 { 655 log.log(POILogger.DEBUG, "Sheet.setDimensions"); 656 log.log(POILogger.DEBUG, 657 (new StringBuffer ("firstrow")).append(firstrow) 658 .append("firstcol").append(firstcol).append("lastrow") 659 .append(lastrow).append("lastcol").append(lastcol) 660 .toString()); 661 } 662 dims.setFirstCol(firstcol); 663 dims.setFirstRow(firstrow); 664 dims.setLastCol(lastcol); 665 dims.setLastRow(lastrow); 666 if (log.check( POILogger.DEBUG )) 667 log.log(POILogger.DEBUG, "Sheet.setDimensions exiting"); 668 } 669 670 685 686 public void setLoc(int loc) 687 { 688 valueRecIterator = null; 689 if (log.check( POILogger.DEBUG )) 690 log.log(POILogger.DEBUG, "sheet.setLoc(): " + loc); 691 this.loc = loc; 692 } 693 694 698 699 public int getLoc() 700 { 701 if (log.check( POILogger.DEBUG )) 702 log.log(POILogger.DEBUG, "sheet.getLoc():" + loc); 703 return loc; 704 } 705 706 712 713 public void setPreOffset(int offset) 714 { 715 this.preoffset = offset; 716 } 717 718 724 725 public int getPreOffset() 726 { 727 return preoffset; 728 } 729 730 738 739 public int serialize(int offset, byte [] data) 740 { 741 if (log.check( POILogger.DEBUG )) 742 log.log(POILogger.DEBUG, "Sheet.serialize using offsets"); 743 744 int pos = offset; 745 boolean haveSerializedIndex = false; 746 747 for (int k = 0; k < records.size(); k++) 748 { 749 Record record = (( Record ) records.get(k)); 750 751 int startPos = pos; 752 if (record instanceof RowRecordsAggregate) { 755 pos += ((RowRecordsAggregate)record).serialize(pos, data, cells); } else if (record instanceof ValueRecordsAggregate) { 757 } else { 759 pos += record.serialize(pos, data ); } 761 if (record.getSid() == BOFRecord.sid) { 763 if ((rows != null) && (!haveSerializedIndex)) { 766 haveSerializedIndex = true; 767 pos += serializeIndexRecord(k, pos, data); 768 } 769 } 770 771 772 } 773 if (log.check( POILogger.DEBUG )) 774 log.log(POILogger.DEBUG, "Sheet.serialize returning "); 775 return pos-offset; 776 } 777 778 private int serializeIndexRecord(final int BOFRecordIndex, final int offset, byte[] data) { 779 IndexRecord index = new IndexRecord(); 780 index.setFirstRow(rows.getFirstRowNum()); 781 index.setLastRowAdd1(rows.getLastRowNum()+1); 782 int sheetRecSize = 0; 785 for (int j = BOFRecordIndex+1; j < records.size(); j++) 786 { 787 Record tmpRec = (( Record ) records.get(j)); 788 if (tmpRec instanceof RowRecordsAggregate) 789 break; 790 sheetRecSize+= tmpRec.getRecordSize(); 791 } 792 int blockCount = rows.getRowBlockCount(); 794 int indexRecSize = index.getRecordSizeForBlockCount(blockCount); 796 797 int rowBlockOffset = 0; 798 int cellBlockOffset = 0; 799 int dbCellOffset = 0; 800 for (int block=0;block<blockCount;block++) { 801 rowBlockOffset += rows.getRowBlockSize(block); 802 cellBlockOffset += cells.getRowCellBlockSize(rows.getStartRowNumberForBlock(block), 803 rows.getEndRowNumberForBlock(block)); 804 index.addDbcell(offset + indexRecSize + sheetRecSize + dbCellOffset + rowBlockOffset + cellBlockOffset); 807 dbCellOffset += (8 + (rows.getRowCountForBlock(block) * 2)); 809 } 810 return index.serialize(offset, data); 811 } 812 813 814 821 822 public RowRecord createRow(int row) 823 { 824 return RowRecordsAggregate.createRow( row ); 825 } 826 827 836 837 public LabelSSTRecord createLabelSST(int row, short col, int index) 839 { 840 log.logFormatted(POILogger.DEBUG, "create labelsst row,col,index %,%,%", 841 new int[] 842 { 843 row, col, index 844 }); 845 LabelSSTRecord rec = new LabelSSTRecord(); 846 847 rec.setRow(row); 848 rec.setColumn(col); 849 rec.setSSTIndex(index); 850 rec.setXFIndex(( short ) 0x0f); 851 return rec; 852 } 853 854 863 864 public NumberRecord createNumber(int row, short col, double value) 866 { 867 log.logFormatted(POILogger.DEBUG, "create number row,col,value %,%,%", 868 new double[] 869 { 870 row, col, value 871 }); 872 NumberRecord rec = new NumberRecord(); 873 874 rec.setRow(row); 876 rec.setColumn(col); 877 rec.setValue(value); 878 rec.setXFIndex(( short ) 0x0f); 879 return rec; 880 } 881 882 888 889 public BlankRecord createBlank(int row, short col) 891 { 892 log.logFormatted(POILogger.DEBUG, "create blank row,col %,%", new int[] 894 { 895 row, col 896 }); 897 BlankRecord rec = new BlankRecord(); 898 899 rec.setRow(row); 901 rec.setColumn(col); 902 rec.setXFIndex(( short ) 0x0f); 903 return rec; 904 } 905 906 915 916 public FormulaRecord createFormula(int row, short col, String formula) 918 { 919 log.logFormatted(POILogger.DEBUG, "create formula row,col,formula %,%,%", 920 new int[] 922 { 923 row, col 924 }, formula); 925 FormulaRecord rec = new FormulaRecord(); 926 927 rec.setRow(row); 928 rec.setColumn(col); 929 rec.setOptions(( short ) 2); 930 rec.setValue(0); 931 rec.setXFIndex(( short ) 0x0f); 932 FormulaParser fp = new FormulaParser(formula,null); fp.parse(); 934 Ptg[] ptg = fp.getRPNPtg(); 935 int size = 0; 936 937 for (int k = 0; k < ptg.length; k++) 938 { 939 size += ptg[ k ].getSize(); 940 rec.pushExpressionToken(ptg[ k ]); 941 } 942 rec.setExpressionLength(( short ) size); 943 return rec; 944 } 945 946 958 959 public void addValueRecord(int row, CellValueRecordInterface col) 961 { 962 checkCells(); 963 log.logFormatted(POILogger.DEBUG, "add value record row,loc %,%", new int[] 964 { 965 row, loc 966 }); 967 DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc()); 968 969 if (col.getColumn() > d.getLastCol()) 970 { 971 d.setLastCol(( short ) (col.getColumn() + 1)); 972 } 973 if (col.getColumn() < d.getFirstCol()) 974 { 975 d.setFirstCol(col.getColumn()); 976 } 977 cells.insertCell(col); 978 979 1001 } 1002 1003 1012 1013 public void removeValueRecord(int row, CellValueRecordInterface col) 1015 { 1016 checkCells(); 1017 log.logFormatted(POILogger.DEBUG, "remove value record row,dimsloc %,%", 1018 new int[]{row, dimsloc} ); 1019 loc = dimsloc; 1020 cells.removeCell(col); 1021 1022 1042 } 1043 1044 1053 1054 public void replaceValueRecord(CellValueRecordInterface newval) 1055 { 1056 checkCells(); 1057 setLoc(dimsloc); 1058 if (log.check( POILogger.DEBUG )) 1059 log.log(POILogger.DEBUG, "replaceValueRecord "); 1060 cells.insertCell(newval); 1061 1062 1077 } 1078 1079 1091 1092 public void addRow(RowRecord row) 1093 { 1094 checkRows(); 1095 if (log.check( POILogger.DEBUG )) 1096 log.log(POILogger.DEBUG, "addRow "); 1097 DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc()); 1098 1099 if (row.getRowNumber() >= d.getLastRow()) 1100 { 1101 d.setLastRow(row.getRowNumber() + 1); 1102 } 1103 if (row.getRowNumber() < d.getFirstRow()) 1104 { 1105 d.setFirstRow(row.getRowNumber()); 1106 } 1107 RowRecord existingRow = rows.getRow(row.getRowNumber()); 1110 if (existingRow != null) 1111 rows.removeRow(existingRow); 1112 1113 rows.insertRow(row); 1114 1115 1150 if (log.check( POILogger.DEBUG )) 1151 log.log(POILogger.DEBUG, "exit addRow"); 1152 } 1153 1154 1161 1162 public void removeRow(RowRecord row) 1163 { 1164 checkRows(); 1165 1167 setLoc(getDimsLoc()); 1168 rows.removeRow(row); 1169 1170 1192 } 1193 1194 1208 1209 public CellValueRecordInterface getNextValueRecord() 1210 { 1211 if (log.check( POILogger.DEBUG )) 1212 log.log(POILogger.DEBUG, "getNextValue loc= " + loc); 1213 if (valueRecIterator == null) 1214 { 1215 valueRecIterator = cells.getIterator(); 1216 } 1217 if (!valueRecIterator.hasNext()) 1218 { 1219 return null; 1220 } 1221 return ( CellValueRecordInterface ) valueRecIterator.next(); 1222 1223 1239 } 1240 1241 1256 1257 1281 1282 1296 1297 public RowRecord getNextRow() 1298 { 1299 if (log.check( POILogger.DEBUG )) 1300 log.log(POILogger.DEBUG, "getNextRow loc= " + loc); 1301 if (rowRecIterator == null) 1302 { 1303 rowRecIterator = rows.getIterator(); 1304 } 1305 if (!rowRecIterator.hasNext()) 1306 { 1307 return null; 1308 } 1309 return ( RowRecord ) rowRecIterator.next(); 1310 1311 1324 } 1325 1326 1342 1343 public RowRecord getRow(int rownum) 1345 { 1346 if (log.check( POILogger.DEBUG )) 1347 log.log(POILogger.DEBUG, "getNextRow loc= " + loc); 1348 return rows.getRow(rownum); 1349 1350 1368 1369 } 1371 1372 1378 1379 protected Record createBOF() 1380 { 1381 BOFRecord retval = new BOFRecord(); 1382 1383 retval.setVersion(( short ) 0x600); 1384 retval.setType(( short ) 0x010); 1385 1386 retval.setBuild(( short ) 0x0dbb); 1388 retval.setBuildYear(( short ) 1996); 1389 retval.setHistoryBitMask(0xc1); 1390 retval.setRequiredVersion(0x6); 1391 return retval; 1392 } 1393 1394 1400 1401 protected Record createIndex() 1402 { 1403 IndexRecord retval = new IndexRecord(); 1404 1405 retval.setFirstRow(0); retval.setLastRowAdd1(0); 1407 return retval; 1408 } 1409 1410 1416 1417 protected Record createCalcMode() 1418 { 1419 CalcModeRecord retval = new CalcModeRecord(); 1420 1421 retval.setCalcMode(( short ) 1); 1422 return retval; 1423 } 1424 1425 1431 1432 protected Record createCalcCount() 1433 { 1434 CalcCountRecord retval = new CalcCountRecord(); 1435 1436 retval.setIterations(( short ) 0x64); return retval; 1438 } 1439 1440 1446 1447 protected Record createRefMode() 1448 { 1449 RefModeRecord retval = new RefModeRecord(); 1450 1451 retval.setMode(RefModeRecord.USE_A1_MODE); 1452 return retval; 1453 } 1454 1455 1461 1462 protected Record createIteration() 1463 { 1464 IterationRecord retval = new IterationRecord(); 1465 1466 retval.setIteration(false); 1467 return retval; 1468 } 1469 1470 1476 1477 protected Record createDelta() 1478 { 1479 DeltaRecord retval = new DeltaRecord(); 1480 1481 retval.setMaxChange(0.0010); 1482 return retval; 1483 } 1484 1485 1491 1492 protected Record createSaveRecalc() 1493 { 1494 SaveRecalcRecord retval = new SaveRecalcRecord(); 1495 1496 retval.setRecalc(true); 1497 return retval; 1498 } 1499 1500 1506 1507 protected Record createPrintHeaders() 1508 { 1509 PrintHeadersRecord retval = new PrintHeadersRecord(); 1510 1511 retval.setPrintHeaders(false); 1512 return retval; 1513 } 1514 1515 1523 1524 protected Record createPrintGridlines() 1525 { 1526 PrintGridlinesRecord retval = new PrintGridlinesRecord(); 1527 1528 retval.setPrintGridlines(false); 1529 return retval; 1530 } 1531 1532 1538 1539 protected Record createGridset() 1540 { 1541 GridsetRecord retval = new GridsetRecord(); 1542 1543 retval.setGridset(true); 1544 return retval; 1545 } 1546 1547 1553 1554 protected Record createGuts() 1555 { 1556 GutsRecord retval = new GutsRecord(); 1557 1558 retval.setLeftRowGutter(( short ) 0); 1559 retval.setTopColGutter(( short ) 0); 1560 retval.setRowLevelMax(( short ) 0); 1561 retval.setColLevelMax(( short ) 0); 1562 return retval; 1563 } 1564 1565 1571 1572 protected Record createDefaultRowHeight() 1573 { 1574 DefaultRowHeightRecord retval = new DefaultRowHeightRecord(); 1575 1576 retval.setOptionFlags(( short ) 0); 1577 retval.setRowHeight(( short ) 0xff); 1578 return retval; 1579 } 1580 1581 1587 1588 protected Record createWSBool() 1589 { 1590 WSBoolRecord retval = new WSBoolRecord(); 1591 1592 retval.setWSBool1(( byte ) 0x4); 1593 retval.setWSBool2(( byte ) 0xffffffc1); 1594 return retval; 1595 } 1596 1597 1603 1604 protected Record createHeader() 1605 { 1606 HeaderRecord retval = new HeaderRecord(); 1607 1608 retval.setHeaderLength(( byte ) 0); 1609 retval.setHeader(null); 1610 return retval; 1611 } 1612 1613 1619 1620 protected Record createFooter() 1621 { 1622 FooterRecord retval = new FooterRecord(); 1623 1624 retval.setFooterLength(( byte ) 0); 1625 retval.setFooter(null); 1626 return retval; 1627 } 1628 1629 1635 1636 protected Record createHCenter() 1637 { 1638 HCenterRecord retval = new HCenterRecord(); 1639 1640 retval.setHCenter(false); 1641 return retval; 1642 } 1643 1644 1650 1651 protected Record createVCenter() 1652 { 1653 VCenterRecord retval = new VCenterRecord(); 1654 1655 retval.setVCenter(false); 1656 return retval; 1657 } 1658 1659 1665 1666 protected Record createPrintSetup() 1667 { 1668 PrintSetupRecord retval = new PrintSetupRecord(); 1669 1670 retval.setPaperSize(( short ) 1); 1671 retval.setScale(( short ) 100); 1672 retval.setPageStart(( short ) 1); 1673 retval.setFitWidth(( short ) 1); 1674 retval.setFitHeight(( short ) 1); 1675 retval.setOptions(( short ) 2); 1676 retval.setHResolution(( short ) 300); 1677 retval.setVResolution(( short ) 300); 1678 retval.setHeaderMargin( 0.5); 1679 retval.setFooterMargin( 0.5); 1680 retval.setCopies(( short ) 0); 1681 return retval; 1682 } 1683 1684 1690 1691 protected Record createDefaultColWidth() 1692 { 1693 DefaultColWidthRecord retval = new DefaultColWidthRecord(); 1694 1695 retval.setColWidth(( short ) 8); 1696 return retval; 1697 } 1698 1699 1704 1705 protected Record createColInfo() 1706 { 1707 return ColumnInfoRecordsAggregate.createColInfo(); 1708 } 1709 1710 1714 1715 public short getDefaultColumnWidth() 1716 { 1717 return defaultcolwidth.getColWidth(); 1718 } 1719 1720 1724 1725 public boolean isGridsPrinted() 1726 { 1727 return !gridset.getGridset(); 1728 } 1729 1730 1734 1735 public void setGridsPrinted(boolean value) 1736 { 1737 gridset.setGridset(!value); 1738 } 1739 1740 1744 1745 public void setDefaultColumnWidth(short dcw) 1746 { 1747 defaultcolwidth.setColWidth(dcw); 1748 } 1749 1750 1753 1754 public void setDefaultRowHeight(short dch) 1755 { 1756 defaultrowheight.setRowHeight(dch); 1757 } 1758 1759 1763 1764 public short getDefaultRowHeight() 1765 { 1766 return defaultrowheight.getRowHeight(); 1767 } 1768 1769 1777 1778 public short getColumnWidth(short column) 1779 { 1780 short retval = 0; 1781 ColumnInfoRecord ci = null; 1782 1783 if (columns != null) 1784 { 1785 for ( Iterator iterator = columns.getIterator(); iterator.hasNext(); ) 1786 { 1787 ci = ( ColumnInfoRecord ) iterator.next(); 1788 if ((ci.getFirstColumn() <= column) 1789 && (column <= ci.getLastColumn())) 1790 { 1791 break; 1792 } 1793 ci = null; 1794 } 1795 } 1796 if (ci != null) 1797 { 1798 retval = ci.getColumnWidth(); 1799 } 1800 else 1801 { 1802 retval = defaultcolwidth.getColWidth(); 1803 } 1804 return retval; 1805 } 1806 1807 1812 public void setColumnWidth(short column, short width) 1813 { 1814 setColumn( column, new Short (width), null, null, null); 1815 } 1816 1817 public void setColumn(short column, Short width, Integer level, Boolean hidden, Boolean collapsed) 1818 { 1819 if (columns == null) 1820 columns = new ColumnInfoRecordsAggregate(); 1821 1822 columns.setColumn( column, width, level, hidden, collapsed ); 1823 } 1824 1825 1832 public void groupColumnRange(short fromColumn, short toColumn, boolean indent) 1833 { 1834 1835 columns.groupColumnRange( fromColumn, toColumn, indent); 1837 1838 int maxLevel = 0; 1840 for ( Iterator iterator = columns.getIterator(); iterator.hasNext(); ) 1841 { 1842 ColumnInfoRecord columnInfoRecord = (ColumnInfoRecord) iterator.next(); 1843 maxLevel = Math.max(columnInfoRecord.getOutlineLevel(), maxLevel); 1844 } 1845 1846 GutsRecord guts = (GutsRecord) findFirstRecordBySid( GutsRecord.sid ); 1847 guts.setColLevelMax( (short) ( maxLevel+1 ) ); 1848 if (maxLevel == 0) 1849 guts.setTopColGutter( (short)0 ); 1850 else 1851 guts.setTopColGutter( (short) ( 29 + (12 * (maxLevel-1)) ) ); 1852 } 1853 1854 1861 1862 protected Record createDimensions() 1863 { 1864 DimensionsRecord retval = new DimensionsRecord(); 1865 1866 retval.setFirstCol(( short ) 0); 1867 retval.setLastRow(1); retval.setFirstRow(0); 1869 retval.setLastCol(( short ) 1); return retval; 1871 } 1872 1873 1885 1886 protected WindowTwoRecord createWindowTwo() 1887 { 1888 WindowTwoRecord retval = new WindowTwoRecord(); 1889 1890 retval.setOptions(( short ) 0x6b6); 1891 retval.setTopRow(( short ) 0); 1892 retval.setLeftCol(( short ) 0); 1893 retval.setHeaderColor(0x40); 1894 retval.setPageBreakZoom(( short ) 0); 1895 retval.setNormalZoom(( short ) 0); 1896 return retval; 1897 } 1898 1899 1906 1907 protected Record createSelection() 1908 { 1909 SelectionRecord retval = new SelectionRecord(); 1910 1911 retval.setPane(( byte ) 0x3); 1912 retval.setActiveCellCol(( short ) 0x0); 1913 retval.setActiveCellRow(( short ) 0x0); 1914 retval.setNumRefs(( short ) 0x0); 1915 return retval; 1916 } 1917 1918 1924 public int getActiveCellRow() 1925 { 1926 if (selection == null) 1927 { 1928 return 0; 1929 } 1930 return selection.getActiveCellRow(); 1931 } 1932 1933 1939 public void setActiveCellRow(int row) 1940 { 1941 if (selection != null) 1943 { 1944 selection.setActiveCellRow(row); 1945 } 1946 } 1947 1948 1954 public short getActiveCellCol() 1955 { 1956 if (selection == null) 1957 { 1958 return (short) 0; 1959 } 1960 return selection.getActiveCellCol(); 1961 } 1962 1963 1969 public void setActiveCellCol(short col) 1970 { 1971 if (selection != null) 1973 { 1974 selection.setActiveCellCol(col); 1975 } 1976 } 1977 1978 protected Record createMergedCells() 1979 { 1980 MergeCellsRecord retval = new MergeCellsRecord(); 1981 retval.setNumAreas(( short ) 0); 1982 return retval; 1983 } 1984 1985 1991 1992 protected Record createEOF() 1993 { 1994 return new EOFRecord(); 1995 } 1996 1997 2001 2002 public int getDimsLoc() 2003 { 2004 if (log.check( POILogger.DEBUG )) 2005 log.log(POILogger.DEBUG, "getDimsLoc dimsloc= " + dimsloc); 2006 return dimsloc; 2007 } 2008 2009 2012 2013 public void checkDimsLoc(Record rec, int recloc) 2014 { 2015 if (rec.getSid() == DimensionsRecord.sid) 2016 { 2017 loc = recloc; 2018 dimsloc = recloc; 2019 } 2020 } 2021 2022 public int getSize() 2023 { 2024 int retval = 0; 2025 2026 for (int k = 0; k < records.size(); k++) 2027 { 2028 retval += (( Record ) records.get(k)).getRecordSize(); 2029 } 2030 if (rows != null) { 2032 final int blocks = rows.getRowBlockCount(); 2033 retval += IndexRecord.getRecordSizeForBlockCount(blocks); 2034 2035 int startRetVal = retval; 2040 retval += (8 * blocks); 2041 for (Iterator itr = rows.getIterator(); itr.hasNext();) { 2042 RowRecord row = (RowRecord)itr.next(); 2043 if (cells.rowHasCells(row.getRowNumber())) 2044 retval += 2; 2045 } 2046 } 2047 return retval; 2048 } 2049 2050 public List getRecords() 2051 { 2052 return records; 2053 } 2054 2055 2058 2059 public GridsetRecord getGridsetRecord() 2060 { 2061 return gridset; 2062 } 2063 2064 2067 2068 public Record findFirstRecordBySid(short sid) 2069 { 2070 for (Iterator iterator = records.iterator(); iterator.hasNext(); ) 2071 { 2072 Record record = ( Record ) iterator.next(); 2073 2074 if (record.getSid() == sid) 2075 { 2076 return record; 2077 } 2078 } 2079 return null; 2080 } 2081 2082 2088 public void setSCLRecord(SCLRecord sclRecord) 2089 { 2090 int oldRecordLoc = findFirstRecordLocBySid(SCLRecord.sid); 2091 if (oldRecordLoc == -1) 2092 { 2093 int windowRecordLoc = findFirstRecordLocBySid(WindowTwoRecord.sid); 2095 records.add(windowRecordLoc+1, sclRecord); 2096 } 2097 else 2098 { 2099 records.set(oldRecordLoc, sclRecord); 2100 } 2101 2102 } 2103 2104 2111 public int findFirstRecordLocBySid( short sid ) 2112 { 2113 int index = 0; 2114 for (Iterator iterator = records.iterator(); iterator.hasNext(); ) 2115 { 2116 Record record = ( Record ) iterator.next(); 2117 2118 if (record.getSid() == sid) 2119 { 2120 return index; 2121 } 2122 index++; 2123 } 2124 return -1; 2125 } 2126 2127 2131 public HeaderRecord getHeader () 2132 { 2133 return header; 2134 } 2135 2136 2140 public void setHeader (HeaderRecord newHeader) 2141 { 2142 header = newHeader; 2143 } 2144 2145 2149 public FooterRecord getFooter () 2150 { 2151 return footer; 2152 } 2153 2154 2158 public void setFooter (FooterRecord newFooter) 2159 { 2160 footer = newFooter; 2161 } 2162 2163 2167 public PrintSetupRecord getPrintSetup () 2168 { 2169 return printSetup; 2170 } 2171 2172 2176 public void setPrintSetup (PrintSetupRecord newPrintSetup) 2177 { 2178 printSetup = newPrintSetup; 2179 } 2180 2181 2185 public PrintGridlinesRecord getPrintGridlines () 2186 { 2187 return printGridlines; 2188 } 2189 2190 2194 public void setPrintGridlines (PrintGridlinesRecord newPrintGridlines) 2195 { 2196 printGridlines = newPrintGridlines; 2197 } 2198 2199 2203 public void setSelected(boolean sel) { 2204 windowTwo.setSelected(sel); 2205 } 2206 2207 2212 public double getMargin(short margin) { 2213 if (getMargins()[margin] != null) 2214 return margins[margin].getMargin(); 2215 else { 2216 switch ( margin ) 2217 { 2218 case LeftMargin: 2219 return .75; 2220 case RightMargin: 2221 return .75; 2222 case TopMargin: 2223 return 1.0; 2224 case BottomMargin: 2225 return 1.0; 2226 default : 2227 throw new RuntimeException ( "Unknown margin constant: " + margin ); 2228 } 2229 } 2230 } 2231 2232 2237 public void setMargin(short margin, double size) { 2238 Margin m = getMargins()[margin]; 2239 if (m == null) { 2240 switch ( margin ) 2241 { 2242 case LeftMargin: 2243 m = new LeftMarginRecord(); 2244 records.add( getDimsLoc() + 1, m ); 2245 break; 2246 case RightMargin: 2247 m = new RightMarginRecord(); 2248 records.add( getDimsLoc() + 1, m ); 2249 break; 2250 case TopMargin: 2251 m = new TopMarginRecord(); 2252 records.add( getDimsLoc() + 1, m ); 2253 break; 2254 case BottomMargin: 2255 m = new BottomMarginRecord(); 2256 records.add( getDimsLoc() + 1, m ); 2257 break; 2258 default : 2259 throw new RuntimeException ( "Unknown margin constant: " + margin ); 2260 } 2261 margins[margin] = m; 2262 } 2263 m.setMargin( size ); 2264 } 2265 2266 public int getEofLoc() 2267 { 2268 return eofLoc; 2269 } 2270 2271 2278 public void createFreezePane(int colSplit, int rowSplit, int topRow, int leftmostColumn ) 2279 { 2280 int loc = findFirstRecordLocBySid(WindowTwoRecord.sid); 2281 PaneRecord pane = new PaneRecord(); 2282 pane.setX((short)colSplit); 2283 pane.setY((short)rowSplit); 2284 pane.setTopRow((short) topRow); 2285 pane.setLeftColumn((short) leftmostColumn); 2286 if (rowSplit == 0) 2287 { 2288 pane.setTopRow((short)0); 2289 pane.setActivePane((short)1); 2290 } 2291 else if (colSplit == 0) 2292 { 2293 pane.setLeftColumn((short)64); 2294 pane.setActivePane((short)2); 2295 } 2296 else 2297 { 2298 pane.setActivePane((short)0); 2299 } 2300 records.add(loc+1, pane); 2301 2302 windowTwo.setFreezePanes(true); 2303 windowTwo.setFreezePanesNoSplit(true); 2304 2305 SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid); 2306 sel.setPane((byte)pane.getActivePane()); 2307 2308 } 2309 2310 2323 public void createSplitPane(int xSplitPos, int ySplitPos, int topRow, int leftmostColumn, int activePane ) 2324 { 2325 int loc = findFirstRecordLocBySid(WindowTwoRecord.sid); 2326 PaneRecord r = new PaneRecord(); 2327 r.setX((short)xSplitPos); 2328 r.setY((short)ySplitPos); 2329 r.setTopRow((short) topRow); 2330 r.setLeftColumn((short) leftmostColumn); 2331 r.setActivePane((short) activePane); 2332 records.add(loc+1, r); 2333 2334 windowTwo.setFreezePanes(false); 2335 windowTwo.setFreezePanesNoSplit(false); 2336 2337 SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid); 2338 sel.setPane(PANE_LOWER_RIGHT); 2339 2340 } 2341 2342 public SelectionRecord getSelection() 2343 { 2344 return selection; 2345 } 2346 2347 public void setSelection( SelectionRecord selection ) 2348 { 2349 this.selection = selection; 2350 } 2351 2352 2358 protected Record createProtect() 2359 { 2360 if (log.check( POILogger.DEBUG )) 2361 log.log(POILogger.DEBUG, "create protect record with protection disabled"); 2362 ProtectRecord retval = new ProtectRecord(); 2363 2364 retval.setProtect(false); 2365 return retval; 2367 } 2368 2369 public ProtectRecord getProtect() 2370 { 2371 return protect; 2372 } 2373 2374 2378 public void setDisplayGridlines(boolean show) { 2379 windowTwo.setDisplayGridlines(show); 2380 } 2381 2382 2386 public boolean isDisplayGridlines() { 2387 return windowTwo.getDisplayGridlines(); 2388 } 2389 2390 2394 public void setDisplayFormulas(boolean show) { 2395 windowTwo.setDisplayFormulas(show); 2396 } 2397 2398 2402 public boolean isDisplayFormulas() { 2403 return windowTwo.getDisplayFormulas(); 2404 } 2405 2406 2410 public void setDisplayRowColHeadings(boolean show) { 2411 windowTwo.setDisplayRowColHeadings(show); 2412 } 2413 2414 2418 public boolean isDisplayRowColHeadings() { 2419 return windowTwo.getDisplayRowColHeadings(); 2420 } 2421 2422 2427 protected Margin[] getMargins() { 2428 if (margins == null) 2429 margins = new Margin[4]; 2430 return margins; 2431 } 2432 2433 public int aggregateDrawingRecords(DrawingManager drawingManager) 2434 { 2435 int loc = findFirstRecordLocBySid(DrawingRecord.sid); 2436 boolean noDrawingRecordsFound = loc == -1; 2437 if (noDrawingRecordsFound) 2438 { 2439 EscherAggregate aggregate = new EscherAggregate( drawingManager ); 2440 loc = findFirstRecordLocBySid(EscherAggregate.sid); 2441 if (loc == -1) 2442 { 2443 loc = findFirstRecordLocBySid( WindowTwoRecord.sid ); 2444 } 2445 else 2446 { 2447 getRecords().remove(loc); 2448 } 2449 getRecords().add( loc, aggregate ); 2450 return loc; 2451 } 2452 else 2453 { 2454 List records = getRecords(); 2455 EscherAggregate r = EscherAggregate.createAggregate( records, loc, drawingManager ); 2456 int startloc = loc; 2457 while ( loc + 1 < records.size() 2458 && records.get( loc ) instanceof DrawingRecord 2459 && records.get( loc + 1 ) instanceof ObjRecord ) 2460 { 2461 loc += 2; 2462 } 2463 int endloc = loc-1; 2464 for(int i = 0; i < (endloc - startloc + 1); i++) 2465 records.remove(startloc); 2466 records.add(startloc, r); 2467 2468 return startloc; 2469 } 2470 } 2471 2472 2477 public void preSerialize() 2478 { 2479 for ( Iterator iterator = getRecords().iterator(); iterator.hasNext(); ) 2480 { 2481 Record r = (Record) iterator.next(); 2482 if (r instanceof EscherAggregate) 2483 r.getRecordSize(); } 2485 } 2486 2487 2494 public void shiftBreaks(PageBreakRecord breaks, short start, short stop, int count) { 2495 2496 if(rowBreaks == null) 2497 return; 2498 Iterator iterator = breaks.getBreaksIterator(); 2499 List shiftedBreak = new ArrayList (); 2500 while(iterator.hasNext()) 2501 { 2502 PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); 2503 short breakLocation = breakItem.main; 2504 boolean inStart = (breakLocation >= start); 2505 boolean inEnd = (breakLocation <= stop); 2506 if(inStart && inEnd) 2507 shiftedBreak.add(breakItem); 2508 } 2509 2510 iterator = shiftedBreak.iterator(); 2511 while (iterator.hasNext()) { 2512 PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next(); 2513 breaks.removeBreak(breakItem.main); 2514 breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo); 2515 } 2516 } 2517 2518 2522 public void setRowBreak(int row, short fromCol, short toCol) { 2523 rowBreaks.addBreak((short)row, fromCol, toCol); 2524 } 2525 2526 2530 public void removeRowBreak(int row) { 2531 rowBreaks.removeBreak((short)row); 2532 } 2533 2534 2539 public boolean isRowBroken(int row) { 2540 return rowBreaks.getBreak((short)row) != null; 2541 } 2542 2543 2547 public void setColumnBreak(short column, short fromRow, short toRow) { 2548 colBreaks.addBreak(column, fromRow, toRow); 2549 } 2550 2551 2555 public void removeColumnBreak(short column) { 2556 colBreaks.removeBreak(column); 2557 } 2558 2559 2564 public boolean isColumnBroken(short column) { 2565 return colBreaks.getBreak(column) != null; 2566 } 2567 2568 2574 public void shiftRowBreaks(int startingRow, int endingRow, int count) { 2575 shiftBreaks(rowBreaks, (short)startingRow, (short)endingRow, (short)count); 2576 } 2577 2578 2584 public void shiftColumnBreaks(short startingCol, short endingCol, short count) { 2585 shiftBreaks(colBreaks, startingCol, endingCol, count); 2586 } 2587 2588 2592 public Iterator getRowBreaks() { 2593 return rowBreaks.getBreaksIterator(); 2594 } 2595 2596 2600 public int getNumRowBreaks(){ 2601 return (int)rowBreaks.getNumBreaks(); 2602 } 2603 2604 2608 public Iterator getColumnBreaks(){ 2609 return colBreaks.getBreaksIterator(); 2610 } 2611 2612 2616 public int getNumColumnBreaks(){ 2617 return (int)colBreaks.getNumBreaks(); 2618 } 2619 2620 public void setColumnGroupCollapsed( short columnNumber, boolean collapsed ) 2621 { 2622 if (collapsed) 2623 { 2624 columns.collapseColumn( columnNumber ); 2625 } 2626 else 2627 { 2628 columns.expandColumn( columnNumber ); 2629 } 2630 } 2631 2632 2648 2686 2697 2749 2754 2780 2806 public void groupRowRange(int fromRow, int toRow, boolean indent) 2807 { 2808 checkRows(); 2809 for (int rowNum = fromRow; rowNum <= toRow; rowNum++) 2810 { 2811 RowRecord row = getRow( rowNum ); 2812 if (row == null) 2813 { 2814 row = createRow( rowNum ); 2815 addRow( row ); 2816 } 2817 int level = row.getOutlineLevel(); 2818 if (indent) level++; else level--; 2819 level = Math.max(0, level); 2820 level = Math.min(7, level); 2821 row.setOutlineLevel((short) ( level )); 2822 } 2823 2824 recalcRowGutter(); 2825 } 2826 2827 private void recalcRowGutter() 2828 { 2829 int maxLevel = 0; 2830 Iterator iterator = rows.getIterator(); 2831 while ( iterator.hasNext() ) 2832 { 2833 RowRecord rowRecord = (RowRecord) iterator.next(); 2834 maxLevel = Math.max(rowRecord.getOutlineLevel(), maxLevel); 2835 } 2836 2837 GutsRecord guts = (GutsRecord) findFirstRecordBySid( GutsRecord.sid ); 2838 guts.setRowLevelMax( (short) ( maxLevel + 1 ) ); 2839 guts.setLeftRowGutter( (short) ( 29 + (12 * (maxLevel)) ) ); 2840 } 2841 2842 public void setRowGroupCollapsed( int row, boolean collapse ) 2843 { 2844 if (collapse) 2845 { 2846 rows.collapseRow( row ); 2847 } 2848 else 2849 { 2850 rows.expandRow( row ); 2851 } 2852 } 2853 2854 2855 2878 2895 2907 2922 2932 2933 2975} 2976 | Popular Tags |