Пример #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.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);
        }
Пример #2
0
        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.");
            }
        }
Пример #3
0
        private static CellValue EncodeCell(Cell cell, SharedResource sharedResource)
        {
            object    value = cell.Value;
            CellValue result;

            if (value is int)
            {
                result = new RK
                {
                    Value = checked ((uint)((int)value << 2 | 2))
                };
            }
            else
            {
                if (value is decimal)
                {
                    result = new RK
                    {
                        Value = (uint)((decimal)value * 100m) << 2 | 3u
                    };
                }
                else
                {
                    if (value is double)
                    {
                        result = new NUMBER
                        {
                            Value = (double)value
                        };
                    }
                    else
                    {
                        if (value is string)
                        {
                            result = new LABELSST
                            {
                                SSTIndex = sharedResource.GetSSTIndex((string)value)
                            };
                        }
                        else
                        {
                            if (value is DateTime)
                            {
                                result = new NUMBER
                                {
                                    Value = sharedResource.EncodeDateTime((DateTime)value)
                                };
                            }
                            else
                            {
                                if (value is bool)
                                {
                                    result = new BOOLERR
                                    {
                                        ValueType = 0,
                                        Value     = Convert.ToByte((bool)value)
                                    };
                                }
                                else
                                {
                                    if (!(value is ErrorCode))
                                    {
                                        throw new Exception("Invalid cell value.");
                                    }
                                    result = new BOOLERR
                                    {
                                        ValueType = 1,
                                        Value     = ((ErrorCode)value).Code
                                    };
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Пример #4
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.");
     }
 }
Пример #5
0
        public static Record Read(Stream stream)
        {
            Record record = Record.ReadBase(stream);
            ushort type   = record.Type;
            Record result;

            if (type <= 146)
            {
                if (type <= 49)
                {
                    if (type <= 13)
                    {
                        if (type == 6)
                        {
                            result = new FORMULA(record);
                            return(result);
                        }
                        switch (type)
                        {
                        case 10:
                            result = new EOF(record);
                            return(result);

                        case 12:
                            result = new CALCCOUNT(record);
                            return(result);

                        case 13:
                            result = new CALCMODE(record);
                            return(result);
                        }
                    }
                    else
                    {
                        if (type == 34)
                        {
                            result = new DATEMODE(record);
                            return(result);
                        }
                        if (type == 41)
                        {
                            result = new BOTTOMMARGIN(record);
                            return(result);
                        }
                        if (type == 49)
                        {
                            result = new FONT(record);
                            return(result);
                        }
                    }
                }
                else
                {
                    if (type <= 93)
                    {
                        switch (type)
                        {
                        case 60:
                            result = new CONTINUE(record);
                            return(result);

                        case 61:
                            result = new WINDOW1(record);
                            return(result);

                        case 62:
                        case 63:
                        case 65:
                            break;

                        case 64:
                            result = new BACKUP(record);
                            return(result);

                        case 66:
                            result = new CODEPAGE(record);
                            return(result);

                        default:
                            if (type == 85)
                            {
                                result = new DEFCOLWIDTH(record);
                                return(result);
                            }
                            if (type == 93)
                            {
                                result = new OBJ(record);
                                return(result);
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (type == 125)
                        {
                            result = new COLINFO(record);
                            return(result);
                        }
                        if (type == 133)
                        {
                            result = new BOUNDSHEET(record);
                            return(result);
                        }
                        if (type == 146)
                        {
                            result = new PALETTE(record);
                            return(result);
                        }
                    }
                }
            }
            else
            {
                if (type <= 237)
                {
                    if (type <= 190)
                    {
                        if (type == 153)
                        {
                            result = new STANDARDWIDTH(record);
                            return(result);
                        }
                        switch (type)
                        {
                        case 189:
                            result = new MULRK(record);
                            return(result);

                        case 190:
                            result = new MULBLANK(record);
                            return(result);
                        }
                    }
                    else
                    {
                        switch (type)
                        {
                        case 214:
                            result = new RSTRING(record);
                            return(result);

                        case 215:
                            result = new DBCELL(record);
                            return(result);

                        case 216:
                        case 217:
                            break;

                        case 218:
                            result = new BOOKBOOL(record);
                            return(result);

                        default:
                            if (type == 224)
                            {
                                result = new XF(record);
                                return(result);
                            }
                            switch (type)
                            {
                            case 233:
                                result = new BITMAP(record);
                                return(result);

                            case 235:
                                result = new MSODRAWINGGROUP(record);
                                return(result);

                            case 236:
                                result = new MSODRAWING(record);
                                return(result);

                            case 237:
                                result = new MSODRAWINGSELECTION(record);
                                return(result);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    if (type <= 545)
                    {
                        switch (type)
                        {
                        case 252:
                            result = new SST(record);
                            return(result);

                        case 253:
                            result = new LABELSST(record);
                            return(result);

                        case 254:
                            break;

                        case 255:
                            result = new EXTSST(record);
                            return(result);

                        default:
                            switch (type)
                            {
                            case 512:
                                result = new DIMENSIONS(record);
                                return(result);

                            case 513:
                                result = new BLANK(record);
                                return(result);

                            case 514:
                            case 516:
                            case 518:
                                break;

                            case 515:
                                result = new NUMBER(record);
                                return(result);

                            case 517:
                                result = new BOOLERR(record);
                                return(result);

                            case 519:
                                result = new STRING(record);
                                return(result);

                            case 520:
                                result = new ROW(record);
                                return(result);

                            default:
                                if (type == 545)
                                {
                                    result = new ARRAY(record);
                                    return(result);
                                }
                                break;
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (type == 638)
                        {
                            result = new RK(record);
                            return(result);
                        }
                        if (type == 1054)
                        {
                            result = new FORMAT(record);
                            return(result);
                        }
                        if (type == 2057)
                        {
                            result = new BOF(record);
                            return(result);
                        }
                    }
                }
            }
            result = record;
            return(result);
        }
Пример #6
0
        private static CellCollection PopulateCells(List <Record> records, SharedResource sharedResource)
        {
            CellCollection cellCollection = new CellCollection();

            cellCollection.SharedResource = sharedResource;
            checked
            {
                foreach (Record current in records)
                {
                    current.Decode();
                    ushort type = current.Type;
                    if (type <= 189)
                    {
                        if (type != 6)
                        {
                            if (type == 189)
                            {
                                MULRK mULRK    = current as MULRK;
                                int   rowIndex = (int)mULRK.RowIndex;
                                for (int i = (int)mULRK.FirstColIndex; i <= (int)mULRK.LastColIndex; i++)
                                {
                                    int    index   = i - (int)mULRK.FirstColIndex;
                                    object value   = Record.DecodeRK(mULRK.RKList[index]);
                                    int    xFindex = (int)mULRK.XFList[index];
                                    cellCollection.CreateCell(rowIndex, i, value, xFindex);
                                }
                            }
                        }
                        else
                        {
                            FORMULA fORMULA = current as FORMULA;
                            cellCollection.CreateCell((int)fORMULA.RowIndex, (int)fORMULA.ColIndex, fORMULA.DecodeResult(), (int)fORMULA.XFIndex);
                        }
                    }
                    else
                    {
                        if (type != 253)
                        {
                            switch (type)
                            {
                            case 515:
                            {
                                NUMBER nUMBER = current as NUMBER;
                                cellCollection.CreateCell((int)nUMBER.RowIndex, (int)nUMBER.ColIndex, nUMBER.Value, (int)nUMBER.XFIndex);
                                break;
                            }

                            case 516:
                                break;

                            case 517:
                            {
                                BOOLERR bOOLERR = current as BOOLERR;
                                cellCollection.CreateCell((int)bOOLERR.RowIndex, (int)bOOLERR.ColIndex, bOOLERR.GetValue(), (int)bOOLERR.XFIndex);
                                break;
                            }

                            default:
                                if (type == 638)
                                {
                                    RK rK = current as RK;
                                    cellCollection.CreateCell((int)rK.RowIndex, (int)rK.ColIndex, Record.DecodeRK(rK.Value), (int)rK.XFIndex);
                                }
                                break;
                            }
                        }
                        else
                        {
                            LABELSST lABELSST = current as LABELSST;
                            Cell     cell     = cellCollection.CreateCell((int)lABELSST.RowIndex, (int)lABELSST.ColIndex, sharedResource.GetStringFromSST(lABELSST.SSTIndex), (int)lABELSST.XFIndex);
                            cell.Style.RichTextFormat = sharedResource.SharedStringTable.RichTextFormatting[lABELSST.SSTIndex];
                        }
                    }
                }
                return(cellCollection);
            }
        }