public void OnCellRead(object sender, VirtualCellReadEventArgs e)
        {
            if (Only50Rows && e.Cell.Row > 50)
            {
                e.NextSheet = null; //Stop reading all sheets.
                return;
            }

            if (e.Cell.Sheet != SheetToRead)
            {
                e.NextSheet = null; //Stop reading all sheets.
                return;
            }

            if (FormatValues)
            {
                TUIColor Clr = Color.Empty;
                CellData.AddValue(e.Cell.Row, e.Cell.Col,
                                  TFlxNumberFormat.FormatValue(e.Cell.Value,
                                                               ((ExcelFile)sender).GetFormat(e.Cell.XF).Format, ref Clr, ((ExcelFile)sender)));
            }
            else
            {
                CellData.AddValue(e.Cell.Row, e.Cell.Col, Convert.ToString(e.Cell.Value));
            }
        }
Example #2
0
        private void AnalizeFile(string FileName, int Row, int Col)
        {
            XlsFile xls = new XlsFile();

            xls.Open(FileName);

            int XF = 0;

            MessageBox.Show("Active sheet is \"" + xls.ActiveSheetByName + "\"");
            object v = xls.GetCellValue(Row, Col, ref XF);

            if (v == null)
            {
                MessageBox.Show("Cell A1 is empty");
                return;
            }

            //Here we have all the kind of objects FlexCel can return.
            switch (Type.GetTypeCode(v.GetType()))
            {
            case TypeCode.Boolean:
                MessageBox.Show("Cell A1 is a boolean: " + (bool)v);
                return;

            case TypeCode.Double:      //Remember, dates are doubles with date format.
                TUIColor CellColor = Color.Empty;
                bool     HasDate, HasTime;
                String   CellValue = TFlxNumberFormat.FormatValue(v, xls.GetFormat(XF).Format, ref CellColor, xls, out HasDate, out HasTime).ToString();

                if (HasDate || HasTime)
                {
                    MessageBox.Show("Cell A1 is a DateTime value: " + FlxDateTime.FromOADate((double)v, xls.OptionsDates1904).ToString() + "\n" +
                                    "The value is displayed as: " + CellValue);
                }
                else
                {
                    MessageBox.Show("Cell A1 is a double: " + (double)v + "\n" +
                                    "The value is displayed as: " + CellValue + "\n");
                }
                return;

            case TypeCode.String:
                MessageBox.Show("Cell A1 is a string: " + v.ToString());
                return;
            }

            TFormula Fmla = v as TFormula;

            if (Fmla != null)
            {
                MessageBox.Show("Cell A1 is a formula: " + Fmla.Text + "   Value: " + Convert.ToString(Fmla.Result));
                return;
            }

            TRichString RSt = v as TRichString;

            if (RSt != null)
            {
                MessageBox.Show("Cell A1 is a formatted string: " + RSt.Value);
                return;
            }

            if (v is TFlxFormulaErrorValue)
            {
                MessageBox.Show("Cell A1 is an error: " + TFormulaMessages.ErrString((TFlxFormulaErrorValue)v));
                return;
            }

            throw new Exception("Unexpected value on cell");
        }