Beispiel #1
0
        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.LABEL:
                    LABEL label = record as LABEL;
                    cells.CreateCell(label.RowIndex, label.ColIndex, label.Value, label.XFIndex);
                    break;

                case RecordType.LABELSST:
                    LABELSST labelsst = record as LABELSST;
                    Cell     cell     = cells.CreateCell(labelsst.RowIndex, labelsst.ColIndex, sharedResource.GetStringFromSST(labelsst.SSTIndex), labelsst.XFIndex);
                    cell.Style.RichTextFormat = sharedResource.SharedStringTable.RichTextFormatting[labelsst.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);
        }
Beispiel #2
0
        private static CellValue EncodeCell(Cell cell, SharedResource sharedResource)
        {
            object value = cell.Value;

            if (value is int || value is short || value is uint || value is byte)
            {
                RK rk = new RK();
                rk.Value = (uint)(Convert.ToInt32(value) << 2 | 2);
                return(rk);
            }
            else if (value is decimal)
            {
                if (Math.Abs((decimal)value) <= (decimal)5368709.11)
                {
                    RK rk = new RK();
                    rk.Value = (uint)((int)((decimal)value * 100) << 2 | 3); // integer and mul
                    return(rk);
                }
                else
                {
                    NUMBER number = new NUMBER();
                    number.Value = (double)(decimal)value;
                    return(number);
                }
            }
            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.");
            }
        }