示例#1
0
        public static void ReadFromXml(string filePath)
        {
            XLWorkbook   wb = new XLWorkbook(filePath);
            IXLWorksheet ws = wb.Worksheets.First();

            IXLTable table = ws.Range(ws.FirstCellUsed(), ws.LastCellUsed()).AsTable();

            /*string s = "";
             * table.DataRange.CellsUsed().Count();
             * table.DataRange.Rows().ForEach(row =>
             * {
             *  s += "\n";
             *  row.Cells().ToList().ForEach(cell =>
             *  {
             *      s += cell.GetString()+"\t|||\t";
             *  });
             * });
             * if (true)
             * {
             *
             * }*/

            TimeTable orar      = new TimeTable();
            IXLCell   grupaCell = null;

            #region grupa

            //cauta coloana care contine grupa
            IXLRangeColumn grupaColoana = table.DataRange.FindColumn(column =>
            {
                grupaCell = column.Cells()?.FirstOrDefault(cell => cell.GetString().Equals("Grupa"));
                return(grupaCell != null);
                //return column.Cells().Any(cell => cell.GetString().Equals("Grupa"));
            });
            int id = 1;
            //insereaza grupele care apar in excel in orar
            grupaColoana.CellsUsed().Where(cell => !cell.GetString().Equals("Grupa")).ForEach(cell =>
            {
                orar.Groups.Add(new GroupDto(id++, cell.GetString()));
            });

            #endregion

            table.Range(grupaCell.Address.RowNumber + 1, grupaCell.Address.ColumnNumber + 2,
                        table.LastCellUsed().Address.RowNumber, table.LastCellUsed().Address.ColumnNumber)
            .CellsUsed().Where(cell => !table.Cell(cell.Address.RowNumber, 3).IsEmpty()).ForEach(cell =>
            {
                string[] split = cell.GetString().Split(",".ToCharArray());
                //Programare prog = new Programare();

                string materie    = split[0];
                string tipMaterie = split[1];
                string sala       = split[2];
                string profesor   = split[3];
            });
        }
示例#2
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 }
            });
        }