Пример #1
0
        public IDictionary <ExcelDataType, object> ReadTable(IXLTable table)
        {
            int rows        = table.RowCount();
            int columns     = table.ColumnCount();
            var numericData = new double?[rows, columns];
            var textData    = new string[rows, columns];
            var formula     = new string[rows, columns];

            for (int i = 1; i <= rows; i++)
            {
                for (int j = 1; j <= columns; j++)
                {
                    IXLCell cell = table.Cell(i, j);
                    switch (cell.DataType)
                    {
                    case XLDataType.Number:
                        numericData[i - 1, j - 1] = cell.GetDouble();
                        break;

                    case XLDataType.Text:
                    {
                        string textValue = GetSingleCellTextValue(cell);
                        KeyValuePair <ExcelDataType, object> parsed = ParseString(textValue);

                        switch (parsed.Key)
                        {
                        case ExcelDataType.Numeric:
                            numericData[i - 1, j - 1] = (double)parsed.Value;
                            break;

                        case ExcelDataType.Text:
                            textData[i - 1, j - 1] = textValue;
                            break;

                        default:
                            throw new NotImplementedException("I haven't implemented formulas yet");
                        }
                        break;
                    }
                    }

                    if (cell.HasFormula)
                    {
                        formula[i - 1, j - 1] = cell.FormulaA1;
                    }
                }
            }
            return(new Dictionary <ExcelDataType, object>
            {
                { ExcelDataType.Numeric, numericData },
                { ExcelDataType.Formulae, formula },
                { ExcelDataType.Text, textData }
            });
        }