private Biff GetCorrectRecord(GenericBiff record, Stream stream, SstRecord sst) { Biff ret = record; switch (record.Id) { case (ushort)RecordType.Bof: BofRecord bof = new BofRecord(record); if (bof.Version < 0x0600) throw new Exception("Versions below Excel 97/2000 are currently not supported."); ret = bof; break; case (ushort)RecordType.Boundsheet: ret = new BoundSheetRecord(record); break; case (ushort)RecordType.Index: ret = new IndexRecord(record); break; case (ushort)RecordType.DbCell: ret = new DbCellRecord(record); break; case (ushort)RecordType.Row: ret = new RowRecord(record); break; case (ushort)RecordType.Continue: ret = new ContinueRecord(record); break; case (ushort)RecordType.Blank: ret = new BlankRecord(record); break; case (ushort)RecordType.BoolErr: ret = new BoolErrRecord(record); break; case (ushort)RecordType.Formula: ret = new FormulaRecord(record, stream); break; case (ushort)RecordType.Label: ret = new LabelRecord(record); break; case (ushort)RecordType.LabelSst: ret = new LabelSstRecord(record, sst); break; case (ushort)RecordType.MulBlank: ret = new MulBlankRecord(record); break; case (ushort)RecordType.MulRk: ret = new MulRkRecord(record); break; case (ushort)RecordType.String: ret = new StringValueRecord(record); break; case (ushort)RecordType.Xf: ret = new XfRecord(record); break; case (ushort)RecordType.Rk: ret = new RkRecord(record); break; case (ushort)RecordType.Number: ret = new NumberRecord(record); break; case (ushort)RecordType.Array: ret = new ArrayRecord(record); break; case (ushort)RecordType.ShrFmla: ret = new SharedFormulaRecord(record); break; case (ushort)RecordType.Table: ret = new TableRecord(record); break; case (ushort)RecordType.Sst: ret = new SstRecord(record, stream); break; case (ushort)RecordType.Eof: ret = new EofRecord(record); break; case (ushort)RecordType.Font: ret = new FontRecord(record); break; case (ushort)RecordType.Format: ret = new Net.SourceForge.Koogra.Excel.Records.FormatRecord(record); break; case (ushort)RecordType.Palette: ret = new PaletteRecord(record); break; case (ushort)RecordType.Hyperlink: ret = new HyperLinkRecord(record); break; } return ret; }
internal Worksheet(Workbook wb, BoundSheetRecord sheet, SortedList<long, Biff> records) : base(wb) { _name = sheet.Name; int idx = records.IndexOfKey((long)sheet.BofPos); _hyperlinks = new HyperLinkCollection(wb); for (int i = idx + 1; i < records.Count; ++i) { Biff biff = records.Values[i]; if (biff is HyperLinkRecord) _hyperlinks.Add((HyperLinkRecord)biff); else if (biff is EofRecord) break; } BofRecord bof = (BofRecord)records.Values[idx++]; Biff seeker = records.Values[idx++]; while (!(seeker is IndexRecord)) seeker = records.Values[idx++]; IndexRecord index = (IndexRecord)seeker; _rows = new RowCollection(wb); foreach (uint indexPos in index.Rows) { long dbCellPos = indexPos; int dbCellIdx = records.IndexOfKey(dbCellPos); DbCellRecord dbCell = (DbCellRecord)records[dbCellPos]; if (dbCell.RowOffset > 0) { long rowPos = dbCellPos - dbCell.RowOffset; int recIndex = records.IndexOfKey(rowPos); Debug.Assert(recIndex != -1); Biff record = records.Values[recIndex++]; while (record is RowRecord) { RowRecord row = (RowRecord)record; Row currentRow = new Row(Workbook, row); _rows.Add(row.RowNumber, currentRow); record = records.Values[recIndex++]; } while (recIndex <= dbCellIdx) { if (!(record is CellRecord)) { record = records.Values[recIndex++]; continue; } CellRecord thecell = (CellRecord)record; Row currentRow = _rows[thecell.Row]; if (thecell is SingleColCellRecord) { SingleColCellRecord cell = (SingleColCellRecord)thecell; object val = cell.Value; Cell newCell = new Cell(Workbook, val); if (cell is RowColXfCellRecord) { RowColXfCellRecord xfCell = (RowColXfCellRecord)cell; Style style = Workbook.Styles[xfCell.Xf]; Debug.Assert(style != null); newCell.Style = style; } currentRow.Cells.Add((byte)cell.Col, newCell); } else { MultipleColCellRecord cells = (MultipleColCellRecord)thecell; for (ushort i = cells.FirstCol; i <= cells.LastCol; ++i) { object val = cells.GetValue(i); if (val != null) { Cell newCell = null; if (val is RkRec) { RkRec rk = (RkRec)val; newCell = new Cell(Workbook, rk.Value); Style style = Workbook.Styles[rk.Xf]; Debug.Assert(style != null); newCell.Style = style; } else newCell = new Cell(Workbook, val); currentRow.Cells.Add((byte)i, newCell); } } } record = records.Values[recIndex++]; } } } }