Пример #1
0
        private IRow CreateRow(int index, int firstColumnIndex, int lastColumnIndex, ExcelCellStyle cellStyle)
        {
            IRow row = _currentSheet.GetRow(index);

            //ExcelCellStyle tempStyle = cellStyle == null ? _defaultExcelCellStyle : cellStyle;
            if (row == null)
            {
                row = this._currentSheet.CreateRow(index);

                for (int i = firstColumnIndex; i <= lastColumnIndex; i++)
                {
                    row.CreateCell(i);
                    row.GetCell(i).CellStyle = cellStyle == null?_defaultExcelCellStyle.GetCellStyle(this.WorkBook) : cellStyle.GetCellStyle(this.WorkBook);
                }
            }
            else
            {
                for (int i = firstColumnIndex; i <= lastColumnIndex; i++)
                {
                    if (row.GetCell(i) == null)
                    {
                        row.CreateCell(i);
                    }
                    row.GetCell(i).CellStyle = cellStyle == null?_defaultExcelCellStyle.GetCellStyle(this.WorkBook) : cellStyle.GetCellStyle(this.WorkBook);
                }
            }
            int kk = this.WorkBook.NumCellStyles;

            return(row);
        }
Пример #2
0
 /// <summary>
 /// 设置格式
 /// </summary>
 /// <param name="firstRowIndex"></param>
 /// <param name="lastRowIndex"></param>
 /// <param name="firstColumnIndex"></param>
 /// <param name="lastColumnIndex"></param>
 /// <param name="cellStyle"></param>
 public void SetRowCellStyle(int firstRowIndex, int lastRowIndex, int firstColumnIndex, int lastColumnIndex, ExcelCellStyle cellStyle)
 {
     for (int rIndex = firstRowIndex; rIndex <= lastRowIndex; rIndex++)
     {
         IRow row = GetRow(rIndex);
         for (int cIndex = firstColumnIndex; cIndex <= lastColumnIndex; cIndex++)
         {
             row.GetCell(cIndex).CellStyle = cellStyle.GetCellStyle(this.WorkBook);
         }
     }
 }