예제 #1
0
        public ExcelRow GetHeaderColumns(ExcelRange row)
        {
            ExcelRow tempRow = new ExcelRow();

            foreach (ExcelRangeBase firstRowCell in row)
            {
                ExcelCell cell = new ExcelCell(
                    firstRowCell.Address,
                    firstRowCell.Text,
                    "#" + firstRowCell.Style.Fill.BackgroundColor.Rgb);
                tempRow.Add(cell);
            }
            return(tempRow);
        }
예제 #2
0
        public ExcelTable ReadFullTable(int startRow = 0, int startColumn = 0, int endRow = -1, int endColumn = -1)
        {
            ExcelTable table = new ExcelTable();
            ExcelRange range = GetExcelCells();

            if (range == null)
            {
                return(null);
            }
            int rows    = GetRowRange();
            int columns = GetColumnRange();

            if (m_currentWorkSheet.Dimension != null)
            {
                ExcelCellAddress start = m_currentWorkSheet.Dimension.Start;
                ExcelCellAddress end   = m_currentWorkSheet.Dimension.End;
                int endrow             = 0;
                int endcolumn          = 0;
                endrow    = endRow == -1 ? end.Row : start.Row + endRow;
                endcolumn = endColumn == -1 ? end.Column :
                            (endColumn < 0 ? end.Column + endColumn : start.Column + endColumn);
                for (int row = start.Row + startRow; row <= endrow; ++row)   // Row by row...
                {
                    ExcelRow tempRow = new ExcelRow {
                        Row = row
                    };
                    for (int col = start.Column + startColumn; col <= endcolumn; col++)  // ... Cell by cell...
                    {
                        string    cellText    = m_currentWorkSheet.Cells[row, col].Text; // This got me the actual value I needed.
                        string    cellColor   = m_currentWorkSheet.Cells[row, col].Style.Fill.BackgroundColor.Rgb;
                        string    cellAddress = m_currentWorkSheet.Cells[row, col].Address;
                        ExcelCell tempCell    = new ExcelCell {
                            Address = cellAddress,
                            Column  = col,
                            Row     = row,
                            Value   = cellText
                        };
                        if (cellColor != null && cellColor.Length > 0)
                        {
                            tempCell.Color = "#" + cellColor;
                        }

                        switch (cellText.ToLowerInvariant())
                        {
                        case "green":
                        case "grün":
                            tempCell.Color = "#00FF00";
                            tempCell.Value = "";
                            break;

                        case "red":
                        case "Rot":
                            tempCell.Color = "#FF0000";
                            tempCell.Value = "";
                            break;

                        case "blue":
                        case "blau":
                            tempCell.Color = "#0000FF";
                            tempCell.Value = "";
                            break;

                        case "yellow":
                        case "gelb":
                            tempCell.Color = "#FFFF00";
                            tempCell.Value = "";
                            break;

                        case "violet":
                        case "violett":
                        case "pink":
                        case "Rosa":
                        case "lilac":
                        case "lila":
                        case "magenta":
                            tempCell.Color = "#FF00FF";
                            tempCell.Value = "";
                            break;

                        case "cyan":
                        case "türkis":
                        case "aqua":
                            tempCell.Color = "#00FFFF";
                            tempCell.Value = "";
                            break;

                        default:
                            break;
                        }
                        tempRow.Add(tempCell);
                    }
                    table.Add(tempRow);
                }
                if (startRow - 1 < 0)
                {
                    startRow = 1;
                }
                table.Headers =
                    GetHeaderColumns(
                        m_currentWorkSheet.Cells[
                            start.Row + (startRow - 1),
                            start.Column,
                            1 + (startRow - 1),
                            endcolumn]);
            }
            return(table);
        }