winform npoi excel 样式设置

        IWorkbook excel = new HSSFWorkbook();//创建.xls文件
            ISheet sheet = excel.CreateSheet("sheet1"); //创建sheet
            int rowindex = 0;
            IRow row = sheet.CreateRow(rowindex++);//创建一行
            ICell cell = row.CreateCell(0);//创建一列
            cell.SetCellValue(linkLabel1.Text);
            ICellStyle style = excel.CreateCellStyle();
            //设置单元格的样式:水平对齐居中
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
            //新建一个字体样式对象
            IFont font = excel.CreateFont();
            //设置字体加粗样式
            //font.Boldweight = short.MaxValue;
            //设置字体大小
            font.FontHeightInPoints = 15;
            //使用SetFont方法将字体样式添加到单元格样式中 
            style.SetFont(font);
            //将新的样式赋给单元格
            cell.CellStyle = style;
            //设置单元格的高度
            //row.Height = 20 * 20;
            ////设置单元格的宽度
            //sheet.SetColumnWidth(0, 30 * 256);
            sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, strArr.Length-1));

猜你喜欢

转载自www.cnblogs.com/aj407blogs/p/9780454.html
今日推荐