Exemplo n.º 1
0
        private Worksheet Read(int? sheetNumber = null, string sheetName = null, int existingHeadingRows = 0)
        {
            CheckFiles();
            PrepareArchive();

            Worksheet worksheet = new Worksheet();
            worksheet.ExistingHeadingRows = existingHeadingRows;
            worksheet.GetWorksheetProperties(this, sheetNumber, sheetName);

            IEnumerable<Row> rows = null;

            List<string> headings = new List<string>();
            using (Stream stream = this.Archive.GetEntry(worksheet.FileName).Open())
            {
                XDocument document = XDocument.Load(stream);
                int skipRows = 0;

                Row possibleHeadingRow = new Row(document.Descendants().Where(d => d.Name.LocalName == "row").FirstOrDefault(), this.SharedStrings);
                if (worksheet.ExistingHeadingRows == 1 && possibleHeadingRow.RowNumber == 1)
                {
                    foreach (Cell headerCell in possibleHeadingRow.Cells)
                    {
                        headings.Add(headerCell.Value.ToString());
                    }
                }
                rows = GetRows(document.Descendants().Where(d => d.Name.LocalName == "row").Skip(skipRows));
            }

            worksheet.Headings = headings;
            worksheet.Rows = rows;

            return worksheet;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Merge this row and the passed one togeather
        /// </summary>
        /// <param name="row">Row to be merged into this one</param>
        internal void Merge(Row row)
        {
            // Merge cells
            List<Cell> outputList = new List<Cell>();
            foreach (var cell in this.Cells.Union(row.Cells).GroupBy(c => c.ColumnNumber))
            {
                int count = cell.Count();
                if (count == 1)
                {
                    outputList.Add(cell.First());
                }
                else
                {
                    cell.First().Merge(cell.Skip(1).First());

                    outputList.Add(cell.First());
                }
            }

            // Sort
            this.Cells = (from c in outputList
                          orderby c.ColumnNumber
                          select c);
        }