예제 #1
0
파일: ExcelTable.cs 프로젝트: kysect/SeaInk
        public void FormatCellsAt(TableIndexRange range, ICellStyle style)
        {
            var cellsRange = _workbook.Worksheet(range.Name).Range
                             (
                range.From.Row + 1,
                range.From.Column + 1,
                range.To.Row + 1,
                range.To.Column + 1
                             );

            var worksheet = _workbook.Worksheet(range.Name);

            foreach (int columnIndex in range.EnumerateColumnsIndices())
            {
                worksheet.Column(columnIndex).Width = style.Width;
            }

            foreach (int rowIndex in range.EnumerateRowsIndices())
            {
                worksheet.Row(rowIndex).Height = style.Height;
            }

            cellsRange.Style.Fill.SetBackgroundColor(XLColor.FromColor(style.BackgroundColor));
            foreach (var cellIndex in range)
            {
                worksheet.Cell(cellIndex.Row, cellIndex.Column).Hyperlink = new XLHyperlink(style.HyperLink);
            }

            cellsRange.Style.Border.SetLeftBorder(style.BorderStyle.Left.Style.ToExcelLineStyle());
            cellsRange.Style.Border.SetLeftBorderColor(XLColor.FromColor(style.BorderStyle.Left.Color));

            cellsRange.Style.Border.SetRightBorder(style.BorderStyle.Right.Style.ToExcelLineStyle());
            cellsRange.Style.Border.SetRightBorderColor(XLColor.FromColor(style.BorderStyle.Right.Color));

            cellsRange.Style.Border.SetTopBorder(style.BorderStyle.Top.Style.ToExcelLineStyle());
            cellsRange.Style.Border.SetTopBorderColor(XLColor.FromColor(style.BorderStyle.Top.Color));

            cellsRange.Style.Border.SetBottomBorder(style.BorderStyle.Bottom.Style.ToExcelLineStyle());
            cellsRange.Style.Border.SetBottomBorderColor(XLColor.FromColor(style.BorderStyle.Bottom.Color));

            cellsRange.Style.Alignment.SetHorizontal(style.HorizontalAlignment.ToExcelHorizontalAlignment());
            cellsRange.Style.Alignment.SetVertical(style.VerticalAlignment.ToExcelVerticalAlignment());

            cellsRange.Style.Font.SetFontName(style.FontName);
            cellsRange.Style.Font.SetFontSize(style.FontSize);
            cellsRange.Style.Font.SetFontColor(XLColor.FromColor(style.FontColor));

            cellsRange.Style.Alignment.WrapText = style.TextWrapping.ToExcelTextWrapping();
        }
예제 #2
0
파일: ExcelTable.cs 프로젝트: kysect/SeaInk
        public List <List <T> > GetValuesForCellsAt <T>(TableIndexRange range)
        {
            var values = new List <List <T> >();

            foreach (int rowIndex in range.EnumerateRowsIndices())
            {
                var newRow = new List <T>();
                foreach (int columnIndex in range.EnumerateColumnsIndices())
                {
                    newRow.Add(GetValueForCellAt <T>(new TableIndex(range, columnIndex + 1, rowIndex + 1)));
                }

                values.Add(newRow);
            }

            return(values);
        }