示例#1
0
        internal void ParseWorkSheet()
        {
            var headerTableFound = false;
            var usedRange        = WorkSheet.GetUsedRange();

            ColumnsCount = usedRange.RightColumnIndex - usedRange.LeftColumnIndex;

            for (var rowIndex = usedRange.TopRowIndex; rowIndex < usedRange.BottomRowIndex; rowIndex++)
            {
                AddNewRow();
                for (var columnIndex = usedRange.LeftColumnIndex; columnIndex <= usedRange.RightColumnIndex; columnIndex++)
                {
                    CurrentRowInfo.AddCell(WorkSheet.Cells[rowIndex, columnIndex]);
                }

                if (headerTableFound || !GetStatisticForRow())
                {
                    continue;
                }

                headerTableFound = true;
                for (var headerColumnIndex = usedRange.LeftColumnIndex; headerColumnIndex <= usedRange.RightColumnIndex; headerColumnIndex++)
                {
                    if (WorkSheet.Cells[rowIndex, headerColumnIndex].Value.Type != CellValueType.Text)
                    {
                        continue;
                    }
                    var cellValue   = WorkSheet.Cells[rowIndex, headerColumnIndex].Value.ToString().ToLower();
                    var columnRange = new Thickness {
                        Left = headerColumnIndex, Top = usedRange.TopRowIndex, Right = headerColumnIndex, Bottom = usedRange.BottomRowIndex
                    };

                    var pattern = new Regex("[:_,.\\*/\n]|[ ]{2,}");
                    cellValue = pattern.Replace(cellValue, " ");

                    var columnHeaderValue = new ColumnHeaderValue {
                        HeaderTableRowIndex = rowIndex, Caption = cellValue, RangeInWorksheet = columnRange
                    };

                    if (ColumnHeaderList.Exists(c => c.Caption == columnHeaderValue.Caption))
                    {
                        continue;
                    }
                    CompareWithGoodColumns(columnHeaderValue);
                    ColumnHeaderList.Add(columnHeaderValue);
                }
            }
        }