private static CellCollection PopulateCells(List <Record> records, SharedResource sharedResource) { CellCollection cells = new CellCollection(); cells.SharedResource = sharedResource; foreach (Record record in records) { record.Decode(); switch (record.Type) { //case RecordType.DIMENSIONS: // DIMENSIONS dimensions = record as DIMENSIONS; // cells.FirstRowIndex = dimensions.FirstRow; // cells.FirstColIndex = dimensions.FirstColumn; // cells.LastRowIndex = dimensions.LastRow-1; // cells.LastColIndex = dimensions.LastColumn-1; // break; case RecordType.BOOLERR: BOOLERR boolerr = record as BOOLERR; cells.CreateCell(boolerr.RowIndex, boolerr.ColIndex, boolerr.GetValue(), boolerr.XFIndex); break; case RecordType.LABELSST: LABELSST label = record as LABELSST; Cell cell = cells.CreateCell(label.RowIndex, label.ColIndex, sharedResource.GetStringFromSST(label.SSTIndex), label.XFIndex); cell.Style.RichTextFormat = sharedResource.SharedStringTable.RichTextFormatting[label.SSTIndex]; break; case RecordType.NUMBER: NUMBER number = record as NUMBER; cells.CreateCell(number.RowIndex, number.ColIndex, number.Value, number.XFIndex); break; case RecordType.RK: RK rk = record as RK; cells.CreateCell(rk.RowIndex, rk.ColIndex, Record.DecodeRK(rk.Value), rk.XFIndex); break; case RecordType.MULRK: MULRK mulrk = record as MULRK; int row = mulrk.RowIndex; for (int col = mulrk.FirstColIndex; col <= mulrk.LastColIndex; col++) { int index = col - mulrk.FirstColIndex; object value = Record.DecodeRK(mulrk.RKList[index]); int XFindex = mulrk.XFList[index]; cells.CreateCell(row, col, value, XFindex); } break; case RecordType.FORMULA: FORMULA formula = record as FORMULA; cells.CreateCell(formula.RowIndex, formula.ColIndex, formula.DecodeResult(), formula.XFIndex); break; } } return(cells); }
private static CellValue EncodeCell(Cell cell, SharedResource sharedResource) { object value = cell.Value; if (value is int) { RK rk = new RK(); rk.Value = (uint)((int)value << 2 | 2); return(rk); } else if (value is decimal) { RK rk = new RK(); rk.Value = (uint)((decimal)value * 100) << 2 | 3; // integer and mul return(rk); } else if (value is double) { //RK rk = new RK(); //Int64 data = BitConverter.DoubleToInt64Bits((double)value); //rk.Value = (uint)(data >> 32) & 0xFFFFFFFC; //return rk; NUMBER number = new NUMBER(); number.Value = (double)value; return(number); } else if (value is string) { LABELSST label = new LABELSST(); label.SSTIndex = sharedResource.GetSSTIndex((string)value); return(label); } else if (value is DateTime) { NUMBER number = new NUMBER(); number.Value = sharedResource.EncodeDateTime((DateTime)value); return(number); } else if (value is bool) { BOOLERR boolerr = new BOOLERR(); boolerr.ValueType = 0; boolerr.Value = Convert.ToByte((bool)value); return(boolerr); } else if (value is ErrorCode) { BOOLERR boolerr = new BOOLERR(); boolerr.ValueType = 1; boolerr.Value = ((ErrorCode)value).Code; return(boolerr); } else { throw new Exception("Invalid cell value."); } }