protected byte calc_crc_read(byte slave_addr, byte reg_addr, UInt16 data)
        {
            byte[] pdata = new byte[5];

            pdata[0] = slave_addr;
            pdata[1] = reg_addr;
            pdata[2] = (byte)(slave_addr | 0x01);
            pdata[3] = SharedFormula.HiByte(data);
            pdata[4] = SharedFormula.LoByte(data);

            return(crc8_calc(ref pdata, 5));
        }
Ejemplo n.º 2
0
        /**
         * @return the equivalent {@link Ptg} array that the formula would have, were it not shared.
         */
        public Ptg[] GetFormulaTokens(FormulaRecord formula)
        {
            int formulaRow    = formula.Row;
            int formulaColumn = formula.Column;

            //Sanity checks
            if (!IsInRange(formulaRow, formulaColumn))
            {
                throw new Exception("Shared Formula Conversion: Coding Error");
            }
            SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97);

            return(sf.ConvertSharedFormulas(field_7_parsed_expr.Tokens, formulaRow, formulaColumn));
            //return ConvertSharedFormulas(field_7_parsed_expr.Tokens, formulaRow, formulaColumn);
        }
Ejemplo n.º 3
0
        private string ConvertSharedFormula(int si)
        {
            XSSFSheet      sheet         = (XSSFSheet)this.Sheet;
            CT_CellFormula sharedFormula = sheet.GetSharedFormula(si);

            if (sharedFormula == null)
            {
                throw new InvalidOperationException("Master cell of a shared formula with sid=" + (object)si + " was not found");
            }
            string           formula          = sharedFormula.Value;
            CellRangeAddress cellRangeAddress = CellRangeAddress.ValueOf(sharedFormula.@ref);
            int sheetIndex = sheet.Workbook.GetSheetIndex((ISheet)sheet);
            XSSFEvaluationWorkbook evaluationWorkbook = XSSFEvaluationWorkbook.Create(sheet.Workbook);

            Ptg[] ptgs = new SharedFormula(SpreadsheetVersion.EXCEL2007).ConvertSharedFormulas(FormulaParser.Parse(formula, (IFormulaParsingWorkbook)evaluationWorkbook, FormulaType.CELL, sheetIndex), this.RowIndex - cellRangeAddress.FirstRow, this.ColumnIndex - cellRangeAddress.FirstColumn);
            return(FormulaRenderer.ToFormulaString((IFormulaRenderingWorkbook)evaluationWorkbook, ptgs));
        }
        protected UInt32 OnWriteWord(byte reg, UInt16 val)
        {
#if debug
            UInt32 ret = LibErrorCode.IDS_ERR_SUCCESSFUL;
#if functiontimeout
            ret = LibErrorCode.IDS_ERR_DEM_FUN_TIMEOUT;
#else
#if pec
            ret = LibErrorCode.IDS_ERR_BUS_DATA_PEC_ERROR;
#endif
#endif
            return(ret);
#else
            UInt16 DataOutLen = 0;
            byte[] sendbuf    = new byte[5];
            byte[] receivebuf = new byte[2];
            UInt32 ret        = LibErrorCode.IDS_ERR_SUCCESSFUL;

            try
            {
                sendbuf[0] = (byte)parent.m_busoption.GetOptionsByGuid(BusOptions.I2CAddress_GUID).SelectLocation.Code;
            }
            catch (System.Exception ex)
            {
                return(ret = LibErrorCode.IDS_ERR_DEM_LOST_PARAMETER);
            }
            sendbuf[1] = reg;
            sendbuf[2] = SharedFormula.HiByte(val);
            sendbuf[3] = SharedFormula.LoByte(val);
            sendbuf[4] = calc_crc_write(sendbuf[0], sendbuf[1], val);
            for (int i = 0; i < ElementDefine.RETRY_COUNTER; i++)
            {
                if (parent.m_Interface.WriteDevice(sendbuf, ref receivebuf, ref DataOutLen, 3))
                {
                    ret = LibErrorCode.IDS_ERR_SUCCESSFUL;
                    break;
                }
                ret = LibErrorCode.IDS_ERR_DEM_FUN_TIMEOUT;
                Thread.Sleep(10);
            }
            //m_Interface.GetLastErrorCode(ref ret);
            return(ret);
#endif
        }
Ejemplo n.º 5
0
        public bool AddSharedFormula(int sheet, int rowFirst, int rowLast, short colFirst, short colLast, byte[] formula, byte[] extra, string baseFormula, LinkTable linkTable)
        {
            SharedFormula formula2 = new SharedFormula(sheet, rowFirst, rowLast, colFirst, colLast, formula, extra, baseFormula);
            Vector <Vector <List <SharedFormula> > > vector = null;

            if (!this._sharedFormulas.ContainsKey(sheet))
            {
                this._sharedFormulas.Add(sheet, new Vector <Vector <List <SharedFormula> > >());
            }
            vector = this._sharedFormulas[sheet];
            for (int i = rowFirst; i <= rowLast; i++)
            {
                if (vector[i] == null)
                {
                    vector[i] = new Vector <List <SharedFormula> >();
                }
                Vector <List <SharedFormula> > vector2 = vector[i];
                for (int j = colFirst; j <= colLast; j++)
                {
                    if (vector2[j] == null)
                    {
                        vector2[j] = new List <SharedFormula>();
                    }
                    vector2[j].Add(formula2);
                }
            }
            if (this._unfoundFormulaRefList.Count > 0)
            {
                int num3 = this._unfoundFormulaRefList.Count;
                for (int k = 0; k < num3; k++)
                {
                    TriCoord coord = (TriCoord)this._unfoundFormulaRefList[k];
                    if (((coord.Col >= colFirst) && (coord.Row >= rowFirst)) && ((coord.Row <= rowLast) && (coord.Col <= colLast)))
                    {
                        MemoryStream stream = new MemoryStream(formula);
                        new BinaryReader((Stream)stream).Close();
                        this._unfoundFormulaRefList.RemoveAt(k);
                        break;
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
        public void TestConvertSharedFormulasOperandClasses_bug45123()
        {
            ILittleEndianInput in1 = TestcaseRecordInputStream.CreateLittleEndian(SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
            int encodedLen         = in1.ReadUShort();

            Ptg[] sharedFormula = Ptg.ReadTokens(encodedLen, in1);

            SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97);

            Ptg[] ConvertedFormula = sf.ConvertSharedFormulas(sharedFormula, 100, 200);

            RefPtg refPtg = (RefPtg)ConvertedFormula[1];

            Assert.AreEqual("$C101", refPtg.ToFormulaString());
            if (refPtg.PtgClass == Ptg.CLASS_REF)
            {
                throw new AssertionException("Identified bug 45123");
            }

            ConfirmOperandClasses(sharedFormula, ConvertedFormula);
        }
Ejemplo n.º 7
0
        public void TestConvertSharedFormulas()
        {
            IWorkbook wb = new HSSFWorkbook();
            HSSFEvaluationWorkbook fpb = HSSFEvaluationWorkbook.Create(wb);

            Ptg[] sharedFormula, ConvertedFormula;

            SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97);

            sharedFormula    = FormulaParser.Parse("A2", fpb, FormulaType.Cell, -1, -1);
            ConvertedFormula = sf.ConvertSharedFormulas(sharedFormula, 0, 0);
            ConfirmOperandClasses(sharedFormula, ConvertedFormula);
            //conversion relative to [0,0] should return the original formula
            Assert.AreEqual(FormulaRenderer.ToFormulaString(fpb, ConvertedFormula), "A2");

            ConvertedFormula = sf.ConvertSharedFormulas(sharedFormula, 1, 0);
            ConfirmOperandClasses(sharedFormula, ConvertedFormula);
            //one row down
            Assert.AreEqual(FormulaRenderer.ToFormulaString(fpb, ConvertedFormula), "A3");

            ConvertedFormula = sf.ConvertSharedFormulas(sharedFormula, 1, 1);
            ConfirmOperandClasses(sharedFormula, ConvertedFormula);
            //one row down and one cell right
            Assert.AreEqual(FormulaRenderer.ToFormulaString(fpb, ConvertedFormula), "B3");

            sharedFormula    = FormulaParser.Parse("SUM(A1:C1)", fpb, FormulaType.Cell, -1, -1);
            ConvertedFormula = sf.ConvertSharedFormulas(sharedFormula, 0, 0);
            ConfirmOperandClasses(sharedFormula, ConvertedFormula);
            Assert.AreEqual(FormulaRenderer.ToFormulaString(fpb, ConvertedFormula), "SUM(A1:C1)");

            ConvertedFormula = sf.ConvertSharedFormulas(sharedFormula, 1, 0);
            ConfirmOperandClasses(sharedFormula, ConvertedFormula);
            Assert.AreEqual(FormulaRenderer.ToFormulaString(fpb, ConvertedFormula), "SUM(A2:C2)");

            ConvertedFormula = sf.ConvertSharedFormulas(sharedFormula, 1, 1);
            ConfirmOperandClasses(sharedFormula, ConvertedFormula);
            Assert.AreEqual(FormulaRenderer.ToFormulaString(fpb, ConvertedFormula), "SUM(B2:D2)");
        }
Ejemplo n.º 8
0
        public double ResistToTemp(double resist)
        {
            int index = 0;
            Dictionary <Int32, double> m_TempVals   = new Dictionary <int, double>();
            Dictionary <Int32, double> m_ResistVals = new Dictionary <int, double>();

            if (parent.tempParamlist == null)
            {
                return(0);
            }

            foreach (Parameter p in parent.tempParamlist.parameterlist)
            {
                //利用温度参数属性下subtype区分内部/外部温度
                //0:内部温度参数 1: 外部温度参数
                if ((ElementDefine.SUBTYPE)p.subtype == ElementDefine.SUBTYPE.EXT_TEMP_TABLE)
                {
                    m_TempVals.Add(index, p.key);
                    m_ResistVals.Add(index, p.phydata);
                    index++;
                }
            }
            return(SharedFormula.ResistToTemp(resist, m_TempVals, m_ResistVals));
        }
Ejemplo n.º 9
0
        private void ReadSheet(string sheetPath, Sheet sheet)
        {
            Dictionary<uint, SharedFormula> sharedFormulas = new Dictionary<uint, SharedFormula>();
            try
            {
                var xml = ReadFile<CT_Worksheet>(sheetPath);

                if (xml.sheetFormatPr != null)
                {
                    if (xml.sheetFormatPr.customHeight)
                        sheet.DefaultRowHeight = xml.sheetFormatPr.defaultRowHeight;

                    if (xml.sheetFormatPr.defaultColWidthSpecified)
                        sheet.DefaultColumnWidth = xml.sheetFormatPr.defaultColWidth;
                }

                if (xml.sheetViews!=null && xml.sheetViews.sheetView!=null)
                    foreach (var sheetView in xml.sheetViews.sheetView)
                        if (sheetView.workbookViewId == 0) //default view
                        {
                            sheet.ShowGridLines = sheetView.showGridLines;

                            if (sheetView.selection != null && sheetView.selection.Length == 1)
                            {
                                if (sheetView.selection[0].activeCell != null)
                                    sheet.ActiveCell = Cell.Parse(sheetView.selection[0].activeCell);
                            }
                        }

                if (xml.cols != null)
                {
                    foreach (var col in xml.cols)
                    {
                        sheet.Columns.AppendRange((int)col.min - 1, (int)col.max - 1, new SheetColumn
                        {
                            BestFit = col.bestFit,
                            Width = col.customWidth && col.widthSpecified ? col.width : (double?)null,
                            style = GetStyle(col.style),
                            Phonetic = col.phonetic,
                            OutlineLevel = col.outlineLevel,
                            Hidden = col.hidden
                        });
                    }
                }

                if (xml.colBreaks != null)
                    foreach (var b in xml.colBreaks.brk)
                        if (b.man)
                            sheet.ColumnBreaks.Add((int)b.id - 1);

                if (xml.mergeCells!=null && xml.mergeCells.mergeCell != null)
                    foreach (var mc in xml.mergeCells.mergeCell)
                    {
                        var range = Range.Parse(mc.@ref);
                        sheet[range].Merge();
                    }

                if (xml.sheetData!=null)
                    foreach (var rd in xml.sheetData)
                    {
                        var row = sheet[(int)rd.r - 1];

                        if (rd.customFormat)
                            row.Style = GetStyle(rd.s);

                        if (rd.customHeight && rd.htSpecified)
                            row.Height = rd.ht;

                        row.Phonetic = rd.ph;
                        row.Collapsed = rd.collapsed;
                        row.Hidden = rd.hidden;

                        if (rd.c != null)
                            foreach (var c in rd.c)
                            {
                                var cell = Cell.Parse(c.r);
                                var data = row[cell.Col];

                                data.Style = GetStyle(c.s);

                                if (c.v != null)
                                {
                                    object value = null;
                                    switch (c.t)
                                    {
                                        case ST_CellType.n:
                                            var n = Convert.ToDouble(c.v, CultureInfo.InvariantCulture);
                                            value = data.style != null && NumberFormat.IsDateTimeFormat(data.style.format) ? value = XlioUtil.ToDateTime(n) : n;
                                            break;

                                        case ST_CellType.str:
                                        case ST_CellType.inlineStr:
                                            value = c.v;
                                            break;

                                        case ST_CellType.s:
                                            value = sharedStrings[Convert.ToInt32(c.v, CultureInfo.InvariantCulture)];
                                            break;

                                        case ST_CellType.b:
                                            value = c.v != null && c.v.Length > 0 && (c.v[0] == 'T' || c.v[0] == 't' || c.v[0] == '1');
                                            break;
                                    }
                                    row[cell.Col].Value = value;
                                }

                                if (c.f != null)
                                {
                                    switch (c.f.t)
                                    {
                                        case ST_CellFormulaType.normal:
                                            row[cell.Col].Formula = c.f.Value;
                                            break;
                                        case ST_CellFormulaType.shared:
                                            if (c.f.siSpecified)
                                            {
                                                SharedFormula sharedFormula = null;
                                                if (c.f.@ref != null && c.f.Value != null) //shared formula definition
                                                {
                                                    var range = Range.Parse(c.f.@ref);
                                                    var origin = cell;
                                                    var formula = c.f.Value;
                                                    sharedFormula = new SharedFormula(formula, range, origin);
                                                    sharedFormulas[c.f.si] = sharedFormula;
                                                }
                                                else
                                                    sharedFormulas.TryGetValue(c.f.si, out sharedFormula);

                                                row[cell.Col].SharedFormula = sharedFormula;
                                            }
                                            break;
                                        case ST_CellFormulaType.array:
                                            row[cell.Col].Formula = "{" + c.f.Value + "}";
                                            break;
                                    }
                                }

                            }

                        if (xml.rowBreaks != null)
                            foreach (var brk in xml.rowBreaks.brk)
                                if (brk.man)
                                    sheet.RowBreaks.Add((int)brk.id - 1);

                        if (xml.pageSetup != null)
                        {
                            switch (xml.pageSetup.orientation)
                            {
                                case ST_Orientation.portrait:
                                    sheet.Page.Orientation = PageOrientation.Portrait;
                                    break;
                                case ST_Orientation.landscape:
                                    sheet.Page.Orientation = PageOrientation.Landscape;
                                    break;
                            }

                            if (xml.pageSetup.scale > 0)
                                sheet.Page.Scale = (int)xml.pageSetup.scale;
                        }

                        if (xml.pageMargins != null)
                        {
                            if (xml.pageMargins != null)
                                sheet.Page.Margins = new PageMargins
                                {
                                    Bottom = xml.pageMargins.bottom,
                                    Footer = xml.pageMargins.footer,
                                    Header = xml.pageMargins.header,
                                    Left = xml.pageMargins.left,
                                    Right = xml.pageMargins.right,
                                    Top = xml.pageMargins.top
                                };
                        }
                    }

                //conditional formatting
                if (xml.conditionalFormatting != null)
                foreach (CT_ConditionalFormatting conditionalFormatting in xml.conditionalFormatting)
                {
                    var rules = new List<CFRule>();
                    if (conditionalFormatting.cfRule !=null)
                        foreach (var cfRule in conditionalFormatting.cfRule)
                        {
                            var rule = GetConditionalFormattingRule(cfRule);
                            rules.Add(rule);
                        }
                    ConditionalFormatting cf = new ConditionalFormatting
                    {
                        Ranges = conditionalFormatting.sqref.ToList(),
                        Rules = rules
                    };
                    sheet.ConditionalFormatting.Add(cf);
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                throw;
            }
        }
Ejemplo n.º 10
0
        private void ReadSheet(string sheetPath, Sheet sheet)
        {
            Dictionary<uint, SharedFormula> sharedFormulas = new Dictionary<uint, SharedFormula>();
            try
            {
                var xml = ReadFile<CT_Worksheet>(sheetPath);

                if (xml.sheetFormatPr != null)
                {
                    if (xml.sheetFormatPr.customHeight)
                        sheet.DefaultRowHeight = xml.sheetFormatPr.defaultRowHeight;

                    if (xml.sheetFormatPr.defaultColWidthSpecified)
                        sheet.DefaultColumnWidth = xml.sheetFormatPr.defaultColWidth;
                }

                if (xml.sheetViews!=null && xml.sheetViews.sheetView!=null)
                    foreach (var sheetView in xml.sheetViews.sheetView)
                        if (sheetView.workbookViewId == 0) //default view
                        {
                            sheet.ShowGridLines = sheetView.showGridLines;

                            if (sheetView.selection != null && sheetView.selection.Length == 1)
                                sheet.ActiveCell = Cell.Parse(sheetView.selection[0].activeCell);
                        }

                if (xml.cols != null)
                {
                    foreach (var col in xml.cols)
                    {
                        sheet.Columns.AppendRange((int)col.min - 1, (int)col.max - 1, new SheetColumn
                        {
                            BestFit = col.bestFit,
                            Width = col.customWidth && col.widthSpecified ? col.width : (double?)null,
                            style = GetStyle(col.style),
                            Phonetic = col.phonetic,
                            OutlineLevel = col.outlineLevel,
                            Hidden = col.hidden
                        });
                    }
                }

                if (xml.mergeCells!=null && xml.mergeCells.mergeCell != null)
                    foreach (var mc in xml.mergeCells.mergeCell)
                    {
                        var range = Range.Parse(mc.@ref);
                        sheet[range].Merge();
                    }

                if (xml.sheetData!=null)
                foreach (var rd in xml.sheetData)
                {
                    var row = sheet[(int)rd.r - 1];

                    if (rd.customFormat)
                        row.Style = GetStyle(rd.s);

                    if (rd.customHeight && rd.htSpecified)
                        row.Height = rd.ht;

                    row.Phonetic = rd.ph;
                    row.Collapsed = rd.collapsed;
                    row.Hidden = rd.hidden;

                    if (rd.c!=null)
                        foreach (var c in rd.c)
                        {
                            var cell = Cell.Parse(c.r);
                            var data = row[cell.Col];

                            data.Style = GetStyle(c.s);

                            if (c.v != null)
                            {
                                object value = null;
                                switch (c.t)
                                {
                                    case ST_CellType.n:
                                        var n = Convert.ToDouble(c.v, CultureInfo.InvariantCulture);
                                        value = data.style != null && NumberFormat.IsDateTimeFormat(data.style.format) ? value = XlioUtil.ToDateTime(n) : n;
                                        break;
                                    case ST_CellType.inlineStr:
                                        value = c.v;
                                        break;
                                    case ST_CellType.s:
                                        value = sharedStrings[Convert.ToInt32(c.v, CultureInfo.InvariantCulture)];
                                        break;
                                    case ST_CellType.b:
                                        value = c.v != null && c.v.Length > 0 && (c.v[0] == 'T' || c.v[0] == 't' || c.v[0] == '1');
                                        break;
                                }
                                row[cell.Col].Value = value;
                            }

                            if (c.f != null)
                            {
                                switch (c.f.t)
                                {
                                    case ST_CellFormulaType.normal:
                                        row[cell.Col].Formula = c.f.Value;
                                        break;
                                    case ST_CellFormulaType.shared:
                                        if (c.f.siSpecified)
                                        {
                                            SharedFormula sharedFormula = null;
                                            if (c.f.@ref != null && c.f.Value != null) //shared formula definition
                                            {
                                                var range = Range.Parse(c.f.@ref);
                                                var origin = cell;
                                                var formula = c.f.Value;
                                                sharedFormula = new SharedFormula(formula, range, origin);
                                                sharedFormulas[c.f.si] = sharedFormula;
                                            }
                                            else
                                                sharedFormulas.TryGetValue(c.f.si, out sharedFormula);

                                            row[cell.Col].SharedFormula = sharedFormula;
                                        }
                                        break;
                                    case ST_CellFormulaType.array:
                                        row[cell.Col].Formula = "{" + c.f.Value + "}";
                                        break;
                                }
                            }

                        }
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
            }
        }
Ejemplo n.º 11
0
        private void ReadSheet(string sheetPath, Sheet sheet)
        {
            Dictionary <uint, SharedFormula> sharedFormulas = new Dictionary <uint, SharedFormula>();

            try
            {
                var xml = ReadFile <CT_Worksheet>(sheetPath);

                if (xml.sheetFormatPr != null)
                {
                    if (xml.sheetFormatPr.customHeight)
                    {
                        sheet.DefaultRowHeight = xml.sheetFormatPr.defaultRowHeight;
                    }

                    if (xml.sheetFormatPr.defaultColWidthSpecified)
                    {
                        sheet.DefaultColumnWidth = xml.sheetFormatPr.defaultColWidth;
                    }
                }

                if (xml.sheetViews != null && xml.sheetViews.sheetView != null)
                {
                    foreach (var sheetView in xml.sheetViews.sheetView)
                    {
                        if (sheetView.workbookViewId == 0) //default view
                        {
                            sheet.ShowGridLines = sheetView.showGridLines;

                            if (sheetView.selection != null && sheetView.selection.Length == 1)
                            {
                                if (sheetView.selection[0].activeCell != null)
                                {
                                    sheet.ActiveCell = Cell.Parse(sheetView.selection[0].activeCell);
                                }
                            }
                        }
                    }
                }

                if (xml.cols != null)
                {
                    foreach (var col in xml.cols)
                    {
                        sheet.Columns.AppendRange((int)col.min - 1, (int)col.max - 1, new SheetColumn
                        {
                            BestFit      = col.bestFit,
                            Width        = col.customWidth && col.widthSpecified ? col.width : (double?)null,
                            style        = GetStyle(col.style),
                            Phonetic     = col.phonetic,
                            OutlineLevel = col.outlineLevel,
                            Hidden       = col.hidden
                        });
                    }
                }

                if (xml.colBreaks != null)
                {
                    foreach (var b in xml.colBreaks.brk)
                    {
                        if (b.man)
                        {
                            sheet.ColumnBreaks.Add((int)b.id - 1);
                        }
                    }
                }

                if (xml.mergeCells != null && xml.mergeCells.mergeCell != null)
                {
                    foreach (var mc in xml.mergeCells.mergeCell)
                    {
                        var range = Range.Parse(mc.@ref);
                        sheet[range].Merge();
                    }
                }

                if (xml.sheetData != null)
                {
                    foreach (var rd in xml.sheetData)
                    {
                        var row = sheet[(int)rd.r - 1];

                        if (rd.customFormat)
                        {
                            row.Style = GetStyle(rd.s);
                        }

                        if (rd.customHeight && rd.htSpecified)
                        {
                            row.Height = rd.ht;
                        }

                        row.Phonetic  = rd.ph;
                        row.Collapsed = rd.collapsed;
                        row.Hidden    = rd.hidden;

                        if (rd.c != null)
                        {
                            foreach (var c in rd.c)
                            {
                                var cell = Cell.Parse(c.r);
                                var data = row[cell.Col];

                                data.Style = GetStyle(c.s);

                                if (c.v != null)
                                {
                                    object value = null;
                                    switch (c.t)
                                    {
                                    case ST_CellType.n:
                                        var n = Convert.ToDouble(c.v, CultureInfo.InvariantCulture);
                                        value = data.style != null && NumberFormat.IsDateTimeFormat(data.style.format) ? value = XlioUtil.ToDateTime(n) : n;
                                        break;

                                    case ST_CellType.str:
                                    case ST_CellType.inlineStr:
                                        value = c.v;
                                        break;

                                    case ST_CellType.s:
                                        value = sharedStrings[Convert.ToInt32(c.v, CultureInfo.InvariantCulture)];
                                        break;

                                    case ST_CellType.b:
                                        value = c.v != null && c.v.Length > 0 && (c.v[0] == 'T' || c.v[0] == 't' || c.v[0] == '1');
                                        break;
                                    }
                                    row[cell.Col].Value = value;
                                }

                                if (c.f != null)
                                {
                                    switch (c.f.t)
                                    {
                                    case ST_CellFormulaType.normal:
                                        row[cell.Col].Formula = c.f.Value;
                                        break;

                                    case ST_CellFormulaType.shared:
                                        if (c.f.siSpecified)
                                        {
                                            SharedFormula sharedFormula = null;
                                            if (c.f.@ref != null && c.f.Value != null)     //shared formula definition
                                            {
                                                var range   = Range.Parse(c.f.@ref);
                                                var origin  = cell;
                                                var formula = c.f.Value;
                                                sharedFormula          = new SharedFormula(formula, range, origin);
                                                sharedFormulas[c.f.si] = sharedFormula;
                                            }
                                            else
                                            {
                                                sharedFormulas.TryGetValue(c.f.si, out sharedFormula);
                                            }

                                            row[cell.Col].SharedFormula = sharedFormula;
                                        }
                                        break;

                                    case ST_CellFormulaType.array:
                                        row[cell.Col].Formula = "{" + c.f.Value + "}";
                                        break;
                                    }
                                }
                            }
                        }

                        if (xml.rowBreaks != null)
                        {
                            foreach (var brk in xml.rowBreaks.brk)
                            {
                                if (brk.man)
                                {
                                    sheet.RowBreaks.Add((int)brk.id - 1);
                                }
                            }
                        }

                        if (xml.pageSetup != null)
                        {
                            switch (xml.pageSetup.orientation)
                            {
                            case ST_Orientation.portrait:
                                sheet.Page.Orientation = PageOrientation.Portrait;
                                break;

                            case ST_Orientation.landscape:
                                sheet.Page.Orientation = PageOrientation.Landscape;
                                break;
                            }

                            if (xml.pageSetup.scale > 0)
                            {
                                sheet.Page.Scale = (int)xml.pageSetup.scale;
                            }
                        }

                        if (xml.pageMargins != null)
                        {
                            if (xml.pageMargins != null)
                            {
                                sheet.Page.Margins = new PageMargins
                                {
                                    Bottom = xml.pageMargins.bottom,
                                    Footer = xml.pageMargins.footer,
                                    Header = xml.pageMargins.header,
                                    Left   = xml.pageMargins.left,
                                    Right  = xml.pageMargins.right,
                                    Top    = xml.pageMargins.top
                                }
                            }
                            ;
                        }
                    }
                }

                //conditional formatting
                if (xml.conditionalFormatting != null)
                {
                    foreach (CT_ConditionalFormatting conditionalFormatting in xml.conditionalFormatting)
                    {
                        var rules = new List <CFRule>();
                        if (conditionalFormatting.cfRule != null)
                        {
                            foreach (var cfRule in conditionalFormatting.cfRule)
                            {
                                var rule = GetConditionalFormattingRule(cfRule);
                                rules.Add(rule);
                            }
                        }
                        ConditionalFormatting cf = new ConditionalFormatting
                        {
                            Ranges = conditionalFormatting.sqref.ToList(),
                            Rules  = rules
                        };
                        sheet.ConditionalFormatting.Add(cf);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                Debug.WriteLine(ex.StackTrace);
                throw;
            }
        }