/** * Sets the size of the margin in inches. * @param margin which margin to Get * @param size the size of the margin */ public void SetMargin(MarginType margin, double size) { IMargin m = GetMarginRec(margin); if (m == null) { switch (margin) { case MarginType.LeftMargin: _leftMargin = new LeftMarginRecord(); m = _leftMargin; break; case MarginType.RightMargin: _rightMargin = new RightMarginRecord(); m = _rightMargin; break; case MarginType.TopMargin: _topMargin = new TopMarginRecord(); m = _topMargin; break; case MarginType.BottomMargin: _bottomMargin = new BottomMarginRecord(); m = _bottomMargin; break; default: throw new InvalidOperationException("Unknown margin constant: " + margin); } } m.Margin = size; }
private static IMargin CreateMarginRecord(MarginType margin, double size) { IMargin m; switch (margin) { case MarginType.LeftMargin: m = new LeftMarginRecord(); break; case MarginType.RightMargin: m = new RightMarginRecord(); break; case MarginType.TopMargin: m = new TopMarginRecord(); break; case MarginType.BottomMargin: m = new BottomMarginRecord(); break; default: throw new InvalidOperationException("Unknown margin constant: " + margin); } m.Margin = size; return(m); }
public override void Dispose() { _rowBreaksRecord = null; _columnBreaksRecord = null; header = null; footer = null; _hCenter = null; _vCenter = null; _leftMargin = null; _rightMargin = null; _topMargin = null; _bottomMargin = null; _pls = null; printSetup = null; _bitmap = null; }
public InternalChart(RecordStream rs) { _plsRecords = new List <PLSAggregate>(); records = new List <RecordBase>(128); if (rs.PeekNextSid() != BOFRecord.sid) { throw new Exception("BOF record expected"); } BOFRecord bof = (BOFRecord)rs.GetNext(); if (bof.Type != BOFRecordType.Chart) { throw new RuntimeException("Bad BOF record type"); } records.Add(bof); while (rs.HasNext()) { int recSid = rs.PeekNextSid(); Record.Record rec = rs.GetNext(); if (recSid == EOFRecord.sid) { records.Add(rec); break; } if (recSid == ChartRecord.sid) { continue; } if (recSid == ChartFRTInfoRecord.sid) { _chartFrtInfo = (ChartFRTInfoRecord)rec; } else if (recSid == HeaderRecord.sid) { header = (HeaderRecord)rec; } else if (recSid == FooterRecord.sid) { footer = (FooterRecord)rec; } else if (recSid == HCenterRecord.sid) { _hCenter = (HCenterRecord)rec; } else if (recSid == VCenterRecord.sid) { _vCenter = (VCenterRecord)rec; } else if (recSid == LeftMarginRecord.sid) { _leftMargin = (LeftMarginRecord)rec; } else if (recSid == RightMarginRecord.sid) { _rightMargin = (RightMarginRecord)rec; } else if (recSid == TopMarginRecord.sid) { _topMargin = (TopMarginRecord)rec; } else if (recSid == BottomMarginRecord.sid) { _bottomMargin = (BottomMarginRecord)rec; } else if (recSid == UnknownRecord.PLS_004D) // PLS { PLSAggregate pls = new PLSAggregate(rs); PLSAggregateVisitor rv = new PLSAggregateVisitor(records); pls.VisitContainedRecords(rv); _plsRecords.Add(pls); continue; } else if (recSid == PrintSetupRecord.sid) { printSetup = (PrintSetupRecord)rec; } else if (recSid == PrintSizeRecord.sid) { _printSize = (PrintSizeRecord)rec; } else if (recSid == HeaderFooterRecord.sid) { HeaderFooterRecord hf = (HeaderFooterRecord)rec; if (hf.IsCurrentSheet) { _headerFooter = hf; } else { _sviewHeaderFooters.Add(hf); } } else if (recSid == ProtectRecord.sid) { _protect = (ProtectRecord)rec; } records.Add(rec); } }
private bool ReadARecord(RecordStream rs) { switch (rs.PeekNextSid()) { case HorizontalPageBreakRecord.sid: CheckNotPresent(_rowBreaksRecord); _rowBreaksRecord = (PageBreakRecord)rs.GetNext(); break; case VerticalPageBreakRecord.sid: CheckNotPresent(_columnBreaksRecord); _columnBreaksRecord = (PageBreakRecord)rs.GetNext(); break; case HeaderRecord.sid: CheckNotPresent(header); header = (HeaderRecord)rs.GetNext(); break; case FooterRecord.sid: CheckNotPresent(footer); footer = (FooterRecord)rs.GetNext(); break; case HCenterRecord.sid: CheckNotPresent(_hCenter); _hCenter = (HCenterRecord)rs.GetNext(); break; case VCenterRecord.sid: CheckNotPresent(_vCenter); _vCenter = (VCenterRecord)rs.GetNext(); break; case LeftMarginRecord.sid: CheckNotPresent(_leftMargin); _leftMargin = (LeftMarginRecord)rs.GetNext(); break; case RightMarginRecord.sid: CheckNotPresent(_rightMargin); _rightMargin = (RightMarginRecord)rs.GetNext(); break; case TopMarginRecord.sid: CheckNotPresent(_topMargin); _topMargin = (TopMarginRecord)rs.GetNext(); break; case BottomMarginRecord.sid: CheckNotPresent(_bottomMargin); _bottomMargin = (BottomMarginRecord)rs.GetNext(); break; case UnknownRecord.PLS_004D: // PLS _plsRecords.Add(new PLSAggregate(rs)); break; case PrintSetupRecord.sid: CheckNotPresent(printSetup); printSetup = (PrintSetupRecord)rs.GetNext(); break; case UnknownRecord.BITMAP_00E9: // BITMAP CheckNotPresent(_bitmap); _bitmap = rs.GetNext(); break; case UnknownRecord.PRINTSIZE_0033: CheckNotPresent(_printSize); _printSize = rs.GetNext(); break; case HeaderFooterRecord.sid: HeaderFooterRecord hf = (HeaderFooterRecord)rs.GetNext(); if (hf.IsCurrentSheet) { _headerFooter = hf; } else { _sviewHeaderFooters.Add(hf); } break; default: // all other record types are not part of the PageSettingsBlock return(false); } return(true); }
private bool ReadARecord(RecordStream rs) { switch (rs.PeekNextSid()) { case HorizontalPageBreakRecord.sid: _rowBreaksRecord = (PageBreakRecord)rs.GetNext(); _rowRecords.Add(_rowBreaksRecord); break; case VerticalPageBreakRecord.sid: _columnBreaksRecord = (PageBreakRecord)rs.GetNext(); _rowRecords.Add(_columnBreaksRecord); break; case HeaderRecord.sid: header = (HeaderRecord)rs.GetNext(); _rowRecords.Add(header); break; case FooterRecord.sid: footer = (FooterRecord)rs.GetNext(); _rowRecords.Add(footer); break; case HCenterRecord.sid: _hCenter = (HCenterRecord)rs.GetNext(); _rowRecords.Add(_hCenter); break; case VCenterRecord.sid: _vCenter = (VCenterRecord)rs.GetNext(); _rowRecords.Add(_vCenter); break; case LeftMarginRecord.sid: _leftMargin = (LeftMarginRecord)rs.GetNext(); _rowRecords.Add(_leftMargin); break; case RightMarginRecord.sid: _rightMargin = (RightMarginRecord)rs.GetNext(); _rowRecords.Add(_rightMargin); break; case TopMarginRecord.sid: _topMargin = (TopMarginRecord)rs.GetNext(); _rowRecords.Add(_topMargin); break; case BottomMarginRecord.sid: _bottomMargin = (BottomMarginRecord)rs.GetNext(); _rowRecords.Add(_bottomMargin); break; case 0x004D: // PLS _pls = rs.GetNext(); _rowRecords.Add(_pls); break; case PrintSetupRecord.sid: printSetup = (PrintSetupRecord)rs.GetNext(); _rowRecords.Add(printSetup); break; case 0x00E9: // BITMAP _bitmap = rs.GetNext(); _rowRecords.Add(_bitmap); break; default: // all other record types are not part of the PageSettingsBlock return(false); } return(true); }
/** * Writes out this sheet. First writes out the standard sheet * information then writes out each row in turn. * Once all the rows have been written out, it retrospectively adjusts * the offset references in the file * * @exception IOException */ public void write() { Assert.verify(rows != null); // This worksheet consists of just one chart, so write it and return if (chartOnly) { drawingWriter.write(outputFile); return; } BOFRecord bof = new BOFRecord(BOFRecord.sheet); outputFile.write(bof); // Compute the number of blocks of 32 rows that will be needed int numBlocks = numRows / 32; if (numRows - numBlocks * 32 != 0) numBlocks++; int indexPos = outputFile.getPos(); // Write the index record out now in order to serve as a place holder // The bof passed in is the bof of the workbook, not this sheet IndexRecord indexRecord = new IndexRecord(0, numRows, numBlocks); outputFile.write(indexRecord); if (settings.getAutomaticFormulaCalculation()) { CalcModeRecord cmr = new CalcModeRecord(CalcModeRecord.automatic); outputFile.write(cmr); } else { CalcModeRecord cmr = new CalcModeRecord(CalcModeRecord.manual); outputFile.write(cmr); } CalcCountRecord ccr = new CalcCountRecord(0x64); outputFile.write(ccr); RefModeRecord rmr = new RefModeRecord(); outputFile.write(rmr); IterationRecord itr = new IterationRecord(false); outputFile.write(itr); DeltaRecord dtr = new DeltaRecord(0.001); outputFile.write(dtr); SaveRecalcRecord srr = new SaveRecalcRecord(settings.getRecalculateFormulasBeforeSave()); outputFile.write(srr); PrintHeadersRecord phr = new PrintHeadersRecord(settings.getPrintHeaders()); outputFile.write(phr); PrintGridLinesRecord pglr = new PrintGridLinesRecord(settings.getPrintGridLines()); outputFile.write(pglr); GridSetRecord gsr = new GridSetRecord(true); outputFile.write(gsr); GuttersRecord gutr = new GuttersRecord(); gutr.setMaxColumnOutline(maxColumnOutlineLevel + 1); gutr.setMaxRowOutline(maxRowOutlineLevel + 1); outputFile.write(gutr); DefaultRowHeightRecord drhr = new DefaultRowHeightRecord (settings.getDefaultRowHeight(), settings.getDefaultRowHeight() != SheetSettings.DEFAULT_DEFAULT_ROW_HEIGHT); outputFile.write(drhr); if (maxRowOutlineLevel > 0) workspaceOptions.setRowOutlines(true); if (maxColumnOutlineLevel > 0) workspaceOptions.setColumnOutlines(true); workspaceOptions.setFitToPages(settings.getFitToPages()); outputFile.write(workspaceOptions); if (rowBreaks.Count > 0) { int[] rb = new int[rowBreaks.Count]; for (int i = 0; i < rb.Length; i++) rb[i] = (int)rowBreaks[i]; HorizontalPageBreaksRecord hpbr = new HorizontalPageBreaksRecord(rb); outputFile.write(hpbr); } if (columnBreaks.Count > 0) { int[] rb = new int[columnBreaks.Count]; for (int i = 0; i < rb.Length; i++) rb[i] = (int)columnBreaks[i]; VerticalPageBreaksRecord hpbr = new VerticalPageBreaksRecord(rb); outputFile.write(hpbr); } HeaderRecord header = new HeaderRecord(settings.getHeader().ToString()); outputFile.write(header); FooterRecord footer = new FooterRecord(settings.getFooter().ToString()); outputFile.write(footer); HorizontalCentreRecord hcr = new HorizontalCentreRecord(settings.isHorizontalCentre()); outputFile.write(hcr); VerticalCentreRecord vcr = new VerticalCentreRecord(settings.isVerticalCentre()); outputFile.write(vcr); // Write out the margins if they don't equal the default if (settings.getLeftMargin() != settings.getDefaultWidthMargin()) { MarginRecord mr = new LeftMarginRecord(settings.getLeftMargin()); outputFile.write(mr); } if (settings.getRightMargin() != settings.getDefaultWidthMargin()) { MarginRecord mr = new RightMarginRecord(settings.getRightMargin()); outputFile.write(mr); } if (settings.getTopMargin() != settings.getDefaultHeightMargin()) { MarginRecord mr = new TopMarginRecord(settings.getTopMargin()); outputFile.write(mr); } if (settings.getBottomMargin() != settings.getDefaultHeightMargin()) { MarginRecord mr = new BottomMarginRecord(settings.getBottomMargin()); outputFile.write(mr); } if (plsRecord != null) outputFile.write(plsRecord); SetupRecord setup = new SetupRecord(settings); outputFile.write(setup); if (settings.isProtected()) { ProtectRecord pr = new ProtectRecord(settings.isProtected()); outputFile.write(pr); ScenarioProtectRecord spr = new ScenarioProtectRecord(settings.isProtected()); outputFile.write(spr); ObjectProtectRecord opr = new ObjectProtectRecord(settings.isProtected()); outputFile.write(opr); if (settings.getPassword() != null) { PasswordRecord pw = new PasswordRecord(settings.getPassword()); outputFile.write(pw); } else if (settings.getPasswordHash() != 0) { PasswordRecord pw = new PasswordRecord(settings.getPasswordHash()); outputFile.write(pw); } } indexRecord.setDataStartPosition(outputFile.getPos()); DefaultColumnWidth dcw = new DefaultColumnWidth(settings.getDefaultColumnWidth()); outputFile.write(dcw); // Get a handle to the normal styles WritableCellFormat normalStyle = sheet.getWorkbook().getStyles().getNormalStyle(); WritableCellFormat defaultDateFormat = sheet.getWorkbook().getStyles().getDefaultDateFormat(); // Write out all the column formats foreach (ColumnInfoRecord cir in columnFormats) { // Writing out the column info with index 0x100 causes excel to crash if (cir.getColumn() < 0x100) outputFile.write(cir); XFRecord xfr = cir.getCellFormat(); if (xfr != normalStyle && cir.getColumn() < 0x100) { // Make this the format for every cell in the column Cell[] cells = getColumn(cir.getColumn()); for (int i = 0; i < cells.Length; i++) { if (cells[i] != null && (cells[i].getCellFormat() == normalStyle || cells[i].getCellFormat() == defaultDateFormat)) { // The cell has no overriding format specified, so // set it to the column default ((WritableCell)cells[i]).setCellFormat(xfr); } } } } // Write out the auto filter if (autoFilter != null) autoFilter.write(outputFile); DimensionRecord dr = new DimensionRecord(numRows, numCols); outputFile.write(dr); // Write out all the rows, in blocks of 32 for (int block = 0; block < numBlocks; block++) { DBCellRecord dbcell = new DBCellRecord(outputFile.getPos()); int blockRows = System.Math.Min(32, numRows - block * 32); bool firstRow = true; // First write out all the row records for (int i = block * 32; i < block * 32 + blockRows; i++) { if (rows[i] != null) { rows[i].write(outputFile); if (firstRow) { dbcell.setCellOffset(outputFile.getPos()); firstRow = false; } } } // Now write out all the cells for (int i = block * 32; i < block * 32 + blockRows; i++) { if (rows[i] != null) { dbcell.addCellRowPosition(outputFile.getPos()); rows[i].writeCells(outputFile); } } // Now set the current file position in the index record indexRecord.addBlockPosition(outputFile.getPos()); // Set the position of the file pointer and write out the DBCell // record dbcell.setPosition(outputFile.getPos()); outputFile.write(dbcell); } // Do the drawings and charts if enabled if (!workbookSettings.getDrawingsDisabled()) drawingWriter.write(outputFile); Window2Record w2r = new Window2Record(settings); outputFile.write(w2r); // Handle the frozen panes if (settings.getHorizontalFreeze() != 0 || settings.getVerticalFreeze() != 0) { PaneRecord pr = new PaneRecord(settings.getHorizontalFreeze(),settings.getVerticalFreeze()); outputFile.write(pr); // Handle the selection record. First, there will always be a top left SelectionRecord sr = new SelectionRecord(SelectionRecord.upperLeft, 0, 0); outputFile.write(sr); // Top right if (settings.getHorizontalFreeze() != 0) { sr = new SelectionRecord(SelectionRecord.upperRight, settings.getHorizontalFreeze(), 0); outputFile.write(sr); } // Bottom left if (settings.getVerticalFreeze() != 0) { sr = new SelectionRecord(SelectionRecord.lowerLeft, 0, settings.getVerticalFreeze()); outputFile.write(sr); } // Bottom right if (settings.getHorizontalFreeze() != 0 && settings.getVerticalFreeze() != 0) { sr = new SelectionRecord(SelectionRecord.lowerRight,settings.getHorizontalFreeze(),settings.getVerticalFreeze()); outputFile.write(sr); } Weird1Record w1r = new Weird1Record(); outputFile.write(w1r); } else { // No frozen panes - just write out the selection record for the // whole sheet SelectionRecord sr = new SelectionRecord(SelectionRecord.upperLeft, 0, 0); outputFile.write(sr); } // Handle the zoom factor if (settings.getZoomFactor() != 100) { SCLRecord sclr = new SCLRecord(settings.getZoomFactor()); outputFile.write(sclr); } // Now write out all the merged cells mergedCells.write(outputFile); // Write out all the hyperlinks foreach (WritableHyperlink hlr in hyperlinks) outputFile.write(hlr); if (buttonPropertySet != null) outputFile.write(buttonPropertySet); // Write out the data validations if (dataValidation != null || validatedCells.Count > 0) writeDataValidation(); // Write out the conditional formats if (conditionalFormats != null && conditionalFormats.Count > 0) { foreach (ConditionalFormat cf in conditionalFormats) cf.write(outputFile); } EOFRecord eof = new EOFRecord(); outputFile.write(eof); // Now the various cross reference offsets have been calculated, // retrospectively set the values in the output file outputFile.setData(indexRecord.getData(), indexPos + 4); }