Ejemplo n.º 1
0
        protected SheetItem GetSheetItem(OpenXmlElement source, IEnumerable <string> nameCells, int nameIndex, int dataStartIndex, int step)
        {
            var cells = GetCellFromRow(source, 0).ToArray();

            var name = GeneralParsing.GetCellValue(WorkbookPart, cells.Skip(nameIndex).First());
            var data = nameCells.Select(
                (x, i) =>
                new
            {
                Name = x,
                Data =
                    cells.Skip(dataStartIndex)
                    .Where((y, j) => j % step == i)
                    .Select(z => GeneralParsing.GetCellValue(WorkbookPart, z))
                    .ToArray()
            }).ToDictionary(dataKey => dataKey.Name, dataCheck => dataCheck.Data);


            var item = new SheetItem
            {
                Name = name,
                Data = data
            };

            return(item);
        }
        private static PlanSheetItem GetDataRow(IReadOnlyList <Cell> cells, SpreadsheetDocument document, ICollection <int> years, ICollection <int> monthes)
        {
            var planItem = new PlanSheetItem
            {
                Subject      = GeneralParsing.GetCellValue(document.WorkbookPart, cells[4]),
                TimelineData = GetData(cells, document, 17, years, monthes)
            };

            return(planItem);
        }
        private static ICollection <int> ParseYears(IEnumerable <Cell> cells, SpreadsheetDocument document, int startIndex)
        {
            var cellsData = cells.Skip(startIndex).Select(x => GeneralParsing.GetCellValue(document.WorkbookPart, x)).ToArray();

            var knownCell = cellsData[0];

            for (var i = 1; i < cellsData.Length; i++)
            {
                if (cellsData[i].IsNullOrEmpty())
                {
                    cellsData[i] = knownCell;
                }
                else
                {
                    knownCell = cellsData[i];
                }
            }

            return(cellsData.Select(int.Parse).ToArray());
        }
        private static ICollection <PlanTimelineData> GetData(IReadOnlyList <Cell> cells, SpreadsheetDocument document, int startIndex, ICollection <int> years, ICollection <int> monthes)
        {
            var list = new List <PlanTimelineData>();

            for (var j = startIndex; j <= cells.Count - 3; j = j + 3)
            {
                var timeLine = new PlanTimelineData
                {
                    Year               = years.ElementAt(j - startIndex),
                    Month              = monthes.ElementAt(j - startIndex),
                    Plan               = GeneralParsing.GetCellValue(document.WorkbookPart, cells[j]),
                    AccumulatedPlan    = GeneralParsing.GetCellValue(document.WorkbookPart, cells[j + 1]),
                    SupervisorComments = GeneralParsing.GetCellValue(document.WorkbookPart, cells[j + 2])
                };

                list.Add(timeLine);
            }

            return(list);
        }
Ejemplo n.º 5
0
        private IEnumerable <int> GetMonthInts(IEnumerable <Cell> cells)
        {
            var cellsData =
                cells.Skip(DataStartIndex).Select(x => GeneralParsing.GetCellValue(WorkbookPart, x)).ToArray();

            var knownCell = cellsData[0];

            for (var i = 1; i < cellsData.Length; i++)
            {
                if (cellsData[i].IsNullOrEmpty())
                {
                    cellsData[i] = knownCell;
                }
                else
                {
                    knownCell = cellsData[i];
                }
            }

            return(cellsData.Select(int.Parse).ToArray());
        }
Ejemplo n.º 6
0
        protected ICollection <int> ParseYears(IEnumerable <Row> rows)
        {
            var cellsData =
                GetYearCells(rows)
                .Skip(DataStartIndex)
                .Select(x => GeneralParsing.GetCellValue(WorkbookPart, x))
                .ToArray();

            var knownCell = cellsData[0];

            for (var i = 1; i < cellsData.Length; i++)
            {
                if (cellsData[i].IsNullOrEmpty())
                {
                    cellsData[i] = knownCell;
                }
                else
                {
                    knownCell = cellsData[i];
                }
            }

            return(cellsData.Select(x => DateTime.FromOADate(int.Parse(x)).Year).Where((x, i) => (i % Step) == 0).ToArray());
        }
Ejemplo n.º 7
0
        protected IEnumerable <SheetItem> GetElements(ICollection <Row> rows)
        {
            var nameCells = GetCellsFrom(rows, DataStartIndex, TitlesIndex).Take(Step).Select(x => GeneralParsing.GetCellValue(WorkbookPart, x)).ToArray();

            var elements = new List <SheetItem>();

            foreach (var source in rows.Skip(ItemStartIndex))
            {
                elements.Add(GetSheetItem(source, nameCells, NameIndex, DataStartIndex, Step));
            }

            return(elements);
        }