Пример #1
0
 public SourceDataEntry GetSourceDataEntry(string columnReference)
 {
     if (dataEntries.ContainsKey(columnReference))
     {
         return(dataEntries[columnReference]);
     }
     else
     {
         return(SourceDataEntry.CreateDataEntry("", DataType.Null, columnReference));
     }
 }
Пример #2
0
        private SourceDataEntry getcellDataEntry(WorkbookPart workbookPart, Cell cell, SortedDictionary <string, string> headers)
        {
            DataType dataType = DataType.Null;

            string value = cell.InnerText;

            if (value.Length > 0)
            {
                dataType = DataType.Number;
            }

            if (cell.DataType != null)
            {
                switch (cell.DataType.Value)
                {
                case CellValues.Boolean:
                    value    = cell.CellValue.ToString() == "0" ? "0" : "1";
                    dataType = DataType.Bool;
                    break;

                case CellValues.SharedString:
                    SharedStringTablePart stringTable = workbookPart.GetPartsOfType <SharedStringTablePart>().FirstOrDefault();
                    value    = stringTable.SharedStringTable.ElementAt(int.Parse(cell.InnerText)).InnerText;
                    dataType = DataType.String;
                    break;

                case CellValues.InlineString:
                    value    = cell.InnerText;
                    dataType = DataType.String;
                    break;

                case CellValues.String:
                    value    = cell.CellValue.InnerText;
                    dataType = DataType.String;
                    break;

                case CellValues.Error:
                    value    = "";
                    dataType = DataType.Error;
                    break;

                default:
                    break;
                }
            }
            else if (cell.StyleIndex != null &&
                     styleIndexIsDate(workbookPart.WorkbookStylesPart.Stylesheet, (int)cell.StyleIndex.Value))
            {
                double d = Double.Parse(value, CultureInfo.InvariantCulture);
                value    = DateTime.FromOADate(d).ToString(CultureInfo.InvariantCulture);
                dataType = DataType.DateTime;
            }
            else if (cell.CellFormula != null)
            {
                double v;
                if (Double.TryParse(cell.CellValue.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture, out v))
                {
                    value    = v.ToString(CultureInfo.InvariantCulture);
                    dataType = DataType.Number;
                }
                else
                {
                    value    = cell.CellValue.InnerText;
                    dataType = DataType.String;
                }
            }

            string columnName      = getColumnName(cell.CellReference);
            string columnReference = headers.ContainsKey(columnName) ? headers[getColumnName(cell.CellReference)] : columnName;

            return(SourceDataEntry.CreateDataEntry(value, dataType, columnReference));
        }