private static void CreateRowHeader(this ISheet target, IWorkbook workbook, DataTable dataSource)
        {
            string[] columnInfo = null;
            IRow row = target.CreateRow(0);
            ICell cell = null;
            ICellStyle cellStyle = null;

            for (int columnIndex = 0; columnIndex < dataSource.Columns.Count; columnIndex++)
            {
                columnInfo = dataSource.Columns[columnIndex].ColumnName.Split('_');

                cell = row.CreateCell(columnIndex);
                cellStyle = workbook.CreateCellStyle();

                cell.SetCellValue(columnInfo[0]);
                cellStyle.Alignment = HorizontalAlignment.CENTER;
                cellStyle.VerticalAlignment = VerticalAlignment.CENTER;
                cell.CellStyle = cellStyle;

                target.SetColumnWidth(columnIndex, 256 * columnInfo[1].ToInt());
            }

            target.CreateFreezePane(0, 1, 0, 1);
        }
Exemple #2
0
 /// <summary>
 /// 冻结表格
 /// </summary>
 /// <param name="sheet">sheet</param>
 /// <param name="colCount">冻结的列数</param>
 /// <param name="rowCount">冻结的行数</param>
 /// <param name="startCol">右边区域可见的首列序号,从1开始计算</param>
 /// <param name="startRow">下边区域可见的首行序号,也是从1开始计算</param>
 /// <example>
 /// sheet1.CreateFreezePane(0, 1, 0, 1); 冻结首行
 /// sheet1.CreateFreezePane(1, 0, 1, 0);冻结首列
 /// </example>
 public static void FreezePane(this ISheet sheet, int colCount, int rowCount, int startCol, int startRow)
 {
     sheet.CreateFreezePane(colCount, rowCount, startCol, startRow);
 }
 public static ISheet FreezeTopRow(this ISheet sheet)
 {
     sheet.CreateFreezePane(0, 1, 0, 1);
     return sheet;
 }