public void AddCell(BaseCell cell) { _cellList.Add(cell); }
private void ApplyCellValueAndLayout(ICell cell, BaseCell celObj, int curRow, int curColumn, int sectionColumnCount) { //set cell value if (!string.IsNullOrEmpty(celObj.Value)) { cell.SetCellValue(celObj.Value); } //call layout set var layoutSet = celObj.LayoutSet; CellRangeAddress mergeRange = null; if (layoutSet != null) { if (layoutSet.RowSpan > 1 || layoutSet.ColumnSpan > 1 || layoutSet.HorizontalStretch) { var lastRow = layoutSet.RowSpan > 1 ? curRow + layoutSet.RowSpan - 1 : curRow; var lastColumn = layoutSet.HorizontalStretch ? curColumn + sectionColumnCount - 1 : (layoutSet.ColumnSpan > 1 ? curColumn + layoutSet.ColumnSpan - 1 : curColumn); if (curRow != lastRow || curColumn != lastColumn) { mergeRange = new CellRangeAddress(curRow, lastRow, curColumn, lastColumn); cell.Sheet.AddMergedRegion(mergeRange); } } if (layoutSet.ColumnWidth > 0) { cell.Sheet.SetColumnWidth(cell.ColumnIndex, celObj.LayoutSet.ColumnWidth * 256); } if (layoutSet.RowHeight > 0) { cell.Row.HeightInPoints = layoutSet.RowHeight; } } //cell style set var styleSet = celObj.LayoutStyle; if (styleSet != null) { cell.CellStyle = cell.Sheet.Workbook.GetCellStyleAt(styleSet.StoreIndex); if (styleSet.ApplyToColumn && cell.CellStyle != null) { var aplStyle = cell.CellStyle; if (styleSet.HasBorder || !string.IsNullOrEmpty(styleSet.BackgroundColor)) //边框和颜色不应用到列 { aplStyle = cell.Sheet.Workbook.CreateCellStyle(); aplStyle.CloneStyleFrom(cell.CellStyle); aplStyle.FillPattern = FillPattern.NoFill; aplStyle.BorderLeft = aplStyle.BorderTop = aplStyle.BorderRight = aplStyle.BorderBottom = BorderStyle.None; } cell.Sheet.SetDefaultColumnStyle(cell.ColumnIndex, aplStyle); } //修复合并单元格样式 if (mergeRange != null) { SetMergeCellStyle(cell, mergeRange); } } }