NPOI导出真正的电子表格,支持 自定义多行表头(表头风格设置),支持多个sheet页面导出_nopi 导出固定表头-程序员宅基地

技术标签: C#  NPOI多行表头  

  NPOI导出真正的电子表格,支持自定义多行表头(表头风格设置),支持多个片页面导出,效果如下

多行表头效果演示

DEMO资源下载  https://download.csdn.net/download/shunlu/10749942

代码如下:

 using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using NPOI.HSSF.UserModel;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
//using log4net;

namespace Test.Models {

    /* 
     * 调用实例
     *  Dictionary<string, List<NpoiHeadCfg>> dicHeads = new Dictionary<string, List<NpoiHeadCfg>>();
       
        DataSet ds = new DataSet();
        DataTable dt1 = new DataTable("测试表格1");
        ds.Tables.Add(dt1); //你的数据源 dt1 自己补充数据

        List<NpoiHeadCfg> heads = new List<NpoiHeadCfg>();
        heads.Add(new NpoiHeadCfg("rownumber", "行号"));
        heads.Add(new NpoiHeadCfg("dateid", "日期"));

        NpoiHeadCfg hc3 = new NpoiHeadCfg("", "10月1号", 20); 
        hc3.Childs.Add(new NpoiHeadCfg("day1_zb1", "完工总数"));
        hc3.Childs.Add(new NpoiHeadCfg("day1_zb2", "回复总数"));
        hc3.Childs.Add(new NpoiHeadCfg("day1_zb3", "回复率"));
        //
        dicHeads.Add(dt1.TableName, heads);
        string fileName = "调查_" + DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".xls";
        //调用,从服务端下载前面加 return 
        NpoiExcelExport.ExporXSSFExcel(ds, dicHeads, fileName);
     * */

    /// <summary>
    ///  NPOI导出真正的电子表格,支持 自定义多行表头(表头风格设置),支持多个sheet页面导出 
    /// </summary>
    /// <remarks>
    /// 创建:shunlu 2018-10-24 
    /// </remarks>
    public class NpoiExcelExport {

        // static ILog log = LogManager.GetLogger(typeof(NpoiExcelExport));

       
        /// <summary>
        /// 导出真正的电子表格
        /// </summary>
        /// <param name="ds">数据源</param>
        /// <param name="heads">表头设置列表</param>
        /// <param name="fileName">文件名称</param>
        /// <param name="downLoad">是否从网络下载 true 下载,false 不下载</param>
        /// <param name="savePath">保存到本地路径(不含文件名称),savePath为空不保存本地文件</param>
        /// <remarks>
        /// 创建:shunlu 2018-10-24 
        /// </remarks>
        public static dynamic ExporXSSFExcel(DataSet ds, Dictionary<string, List<NpoiHeadCfg>> heads, string fileName, bool downLoad = true, string savePath = "") {
            //创建 电子表格文件
            XSSFWorkbook book = new XSSFWorkbook();

            try {
                for (int i = 0; i < ds.Tables.Count; i++) {

                    // log.Debug("ExporXSSFExcel " + i + ":表名:" + ds.Tables[i].TableName);

                    if (heads.ContainsKey(ds.Tables[i].TableName)) {
                        //
                        var _heads = heads[ds.Tables[i].TableName];
                        //
                        CreateSheet(book, i, ds.Tables[i], _heads);
                    }
                }
                //保存文件
                if (!string.IsNullOrEmpty(savePath)) {
                    SaveExcel(book, fileName, savePath);
                }
                // 
                // 服务端下载文件
                if (downLoad) {
                    return DownXssfFile(book, fileName);
                } else {
                    return null;
                }
            } catch (Exception ex) {
                throw ex;
            } finally {
                book.Close();
            }
        }

        /// <summary>
        /// 创建 sheet
        /// </summary>
        /// <param name="book"></param>
        /// <param name="index"></param>
        /// <param name="dt"></param>
        /// <param name="heads"></param>
        /// <remarks>
        /// 创建:shunlu 2018-10-24 
        /// </remarks>
        private static void CreateSheet(XSSFWorkbook book, int index, DataTable dt, List<NpoiHeadCfg> heads) {
            //创建该sheet页
            ISheet sheet = book.CreateSheet(dt.TableName);

            //创建 表格头部
            CreadHeader(book, ref sheet, dt, heads);

            //创建 表格数据
            CreadDataRows(book, ref sheet, dt, heads);
        }

        /// <summary>
        /// 创建表头,支持多行
        /// </summary>
        /// <param name="book"></param>
        /// <param name="sheet"></param>
        /// <param name="dt"></param>
        /// <param name="heads"></param>
        /// <remarks>
        /// 创建:shunlu 2018-10-24 
        /// </remarks>
        private static void CreadHeader(XSSFWorkbook book, ref ISheet sheet, DataTable dt, List<NpoiHeadCfg> heads) {
            //创建 表格头部
            if (heads != null && heads.Count > 0) {
                //使用自定义表头(可以支持多行表头)

                IRow headRow = sheet.CreateRow(0);//创建空行
                headRow.Height = (short)(heads[0].Height * 20);  //设置行高 为25

                //遍历自定义列头
                int maxHeadRowNum = 0;//多行最大行号
                                      //

                int newColIndex = 0;
                //记录当前列最多变成几列
                Dictionary<int, int[]> mgs = new Dictionary<int, int[]>();
                //
                for (int i = 0; i < heads.Count; i++) {
                    if (heads[i].Childs.Count == 0) {
                        #region 无子节点
                        ICell cell = headRow.CreateCell(newColIndex); //创建单元格 
                        cell.SetCellValue(heads[i].FieldLable);    //设置单元格内容

                        var style = GetCellStyle(book, heads[i]);
                        cell.CellStyle = style;
                        // 设置列宽
                        if (heads[i].Width > 0) {
                            sheet.SetColumnWidth(cell.ColumnIndex, heads[i].Width * 256);
                        } else {
                            sheet.SetColumnWidth(cell.ColumnIndex, 13 * 256);
                        }
                        // 
                        mgs.Add(i, new int[] { newColIndex, 1 });
                        newColIndex += 1;
                        #endregion
                    } else {
                        #region 多个子节点
                        int rowIndex = 0;
                        int outRowIndex = 0;
                        int old_colIndex = newColIndex;
                        int new_colIndex = CreateHeadCell(headRow, newColIndex, rowIndex, out outRowIndex, heads[i]);    // 返回最大列数 
                        //
                        for (int j = old_colIndex; j < new_colIndex; j++) {
                            if (headRow.GetCell(j) == null) {
                                ICell _cell = headRow.CreateCell(j); //创建单元格   
                                _cell.SetCellValue(heads[i].FieldLable);  //设置单元格内容  
                                var style = GetCellStyle(book, heads[i]);
                                _cell.CellStyle = style;
                            }
                        }
                        mgs.Add(i, new int[] { old_colIndex, new_colIndex - old_colIndex });
                        // 
                        //合并单元格
                        //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列  
                        CellRangeAddress region1 = new CellRangeAddress(headRow.RowNum, headRow.RowNum, (short)old_colIndex, (short)new_colIndex - 1);
                        headRow.Sheet.AddMergedRegion(region1);
                        //
                        newColIndex = new_colIndex;
                        //
                        if (outRowIndex > maxHeadRowNum) {
                            maxHeadRowNum = outRowIndex;//更新多行最大行号
                        }
                        #endregion
                    }
                }
                var fullstyle = GetCellStyle(book, heads[0]); 
                //合并 列
                #region 合并列
                if (maxHeadRowNum > 0) {
                    foreach (var mg in mgs) {

                        var values = mg.Value;
                        int cIndex = values[0];
                        int cCount = values[1];
                        if (cCount == 1) {
                            for (int j = headRow.RowNum; j <= maxHeadRowNum; j++) {
                                ICell cell = sheet.GetRow(j).GetCell(cIndex);
                                if (cell == null) {
                                    cell = sheet.GetRow(j).CreateCell(cIndex);
                                    cell.CellStyle = fullstyle;
                                }
                            }
                            CellRangeAddress region1 = new CellRangeAddress(headRow.RowNum, maxHeadRowNum, (short)cIndex, (short)cIndex);
                            headRow.Sheet.AddMergedRegion(region1);
                        } else {
                            for (int j = maxHeadRowNum; j >= headRow.RowNum; j--) {
                                IRow row = sheet.GetRow(j);
                                ICell cell = row.GetCell(cIndex);
                                if (cell == null) {
                                    for (int y = 0; y < cCount; y++) {
                                        cell = row.CreateCell(cIndex + y);
                                        cell.CellStyle = fullstyle;
                                        //向上行合并
                                        CellRangeAddress region1 = new CellRangeAddress(j - 1, maxHeadRowNum, (short)(cIndex + y), (short)(cIndex + y));
                                        headRow.Sheet.AddMergedRegion(region1);
                                    }
                                } else {
                                    for (int y = 0; y < cCount; y++) {
                                        cell = row.GetCell(cIndex + y);
                                        if (cell == null) {
                                            cell = row.CreateCell(cIndex + y);
                                            cell.CellStyle = fullstyle;
                                            //判断上一行是否空
                                            for (int x = j - 1; x >= headRow.RowNum; x--) {
                                                IRow preRow = sheet.GetRow(x);
                                                var precell = preRow.GetCell(cIndex + y);
                                                if (precell == null) {
                                                    var newcell = preRow.CreateCell(cIndex + y);
                                                    newcell.CellStyle = fullstyle;
                                                } else {
                                                    //向下行合并
                                                    CellRangeAddress region1 = new CellRangeAddress(x, maxHeadRowNum, (short)(cIndex + y), (short)(cIndex + y));
                                                    headRow.Sheet.AddMergedRegion(region1);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                #endregion
            } else {
                //使用数据源列名作表头(只支持单行表头)
                IRow headRow = sheet.CreateRow(0);//创建空行
                var style = GetCellStyle(book, null);
                //遍历列
                for (int i = 0; i < dt.Columns.Count; i++) {
                    ICell cell = headRow.CreateCell(i);
                    cell.CellStyle = style;
                    if (!string.IsNullOrEmpty(dt.Columns[i].Caption)) {
                        cell.SetCellValue(dt.Columns[i].Caption);
                    } else {
                        cell.SetCellValue(dt.Columns[i].ColumnName);
                    }
                }
            }

        }

        /// <summary>
        /// 创建表头单元格,(支持递归调用)
        /// </summary>
        /// <param name="preHeadRow">上一行</param>
        /// <param name="startColIndex">开始列索引</param>
        /// <param name="rowIndex">行索引</param>
        /// <param name="outRowIndex">输出最新行索引</param>
        /// <param name="headCfg">表头配置</param>
        /// <returns>返回最新的列索引</returns>
        /// <remarks>
        /// 创建:shunlu 2018-10-24 
        /// </remarks>
        private static int CreateHeadCell(IRow preHeadRow, int startColIndex, int rowIndex, out int outRowIndex, NpoiHeadCfg headCfg) {
            // int colCount = headCfg.Childs.Count;
            int preRowIndex = rowIndex;
            rowIndex += 1;
            outRowIndex = rowIndex;
            var sheet = preHeadRow.Sheet;
            XSSFWorkbook book = (XSSFWorkbook)sheet.Workbook;
            var style = GetCellStyle(book, headCfg);
            //
            IRow curHeadRow = null;
            if (sheet.LastRowNum >= rowIndex) {
                curHeadRow = sheet.GetRow(rowIndex);
            } else {
                curHeadRow = sheet.CreateRow(rowIndex);//创建空行
                for (int i = 0; i < startColIndex; i++) {
                    ICell cell = curHeadRow.CreateCell(i); //创建单元格 
                    cell.CellStyle = style;
                    
                    ICell mycell = preHeadRow.GetCell(i); //获取单元格 
                    if (mycell != null)
                        cell.SetCellValue(mycell.StringCellValue);//设置单元格内容 

                }
            }
            int newColIndex = startColIndex;
            for (int i = 0; i < headCfg.Childs.Count; i++) {
                if (headCfg.Childs[i].Childs.Count > 0) {
                    //Console.Write("递归调用\r\n");
                    //
                    int _outRowIndex = 0;
                    int old_ColIndex = newColIndex;
                    //
                    int new_ColIndex = CreateHeadCell(curHeadRow, newColIndex, rowIndex, out _outRowIndex, headCfg.Childs[i]);//递归调用 
                    // 
                    for (int j = old_ColIndex; j < new_ColIndex; j++) {
                        if (curHeadRow.GetCell(j) == null) {
                            ICell _cell = curHeadRow.CreateCell(j); //创建单元格  
                            _cell.SetCellValue(headCfg.Childs[i].FieldLable);  //设置单元格内容  
                            _cell.CellStyle = style;
                        }
                    }
                    //合并单元格
                    //参数1:起始行 参数2:终止行 参数3:起始列 参数4:终止列  
                    CellRangeAddress region1 = new CellRangeAddress(curHeadRow.RowNum, curHeadRow.RowNum, (short)old_ColIndex, (short)(new_ColIndex - 1));
                    sheet.AddMergedRegion(region1);
                    //
                    if (_outRowIndex > outRowIndex) {
                        outRowIndex = _outRowIndex;
                    }
                    newColIndex = new_ColIndex;
                } else {
                    ICell _cell = curHeadRow.CreateCell(newColIndex); //创建单元格 
                    _cell.SetCellValue(headCfg.Childs[i].FieldLable);//设置单元格内容 
                    _cell.CellStyle = style;
                    // 设置列宽
                    if (headCfg.Width > 0) {
                        sheet.SetColumnWidth(_cell.ColumnIndex, headCfg.Width * 256);
                    } else {
                        sheet.SetColumnWidth(_cell.ColumnIndex, 13 * 256);
                    }
                    //
                    newColIndex += 1;
                }
            }
            //
            return newColIndex;
        }

        /// <summary>
        /// 创建 表格数据
        /// </summary>
        /// <param name="book"></param>
        /// <param name="sheet"></param>
        /// <param name="dt">数据源</param>
        /// <param name="heads">表头配置</param>
        /// <remarks>
        /// 创建:shunlu 2018-10-24 
        /// </remarks>
        private static void CreadDataRows(XSSFWorkbook book, ref ISheet sheet, DataTable dt, List<NpoiHeadCfg> heads) {
            // 
            if (dt == null || dt.Rows.Count == 0) {
                return;
            }
            if (heads != null && heads.Count > 0) {

                 List<NpoiHeadCfg> curhds = new List<NpoiHeadCfg>();
                //遍历所有顶层节点
                for (int x = 0; x < heads.Count; x++) {
                    List<NpoiHeadCfg> hds = GetAllLeafNode(heads[x]);//获取所有叶子子节点 
                    curhds.AddRange(hds);
                }
                //遍历所有数据行
                for (int i = 0; i < dt.Rows.Count; i++) {
                    IRow row = sheet.CreateRow(sheet.LastRowNum + 1);//创建空行   
                    int colIndex = 0;
                    //遍历所有叶子子节点
                    for (var y = 0; y < curhds.Count; y++) {
                        var colname = curhds[y].FieldName;
                        if (dt.Columns.Contains(colname)) {//数据源列是否含有配置列
                            ICell cell = row.CreateCell(colIndex);
                            if (dt.Rows[i][colname] != DBNull.Value) {
                                //所有数据类型统统 ToString()
                                cell.SetCellValue(dt.Rows[i][colname].ToString());
                            }
                            colIndex++;
                        }
                    } 
                }
            } else {
                //遍历行 
                for (int x = 0; x < dt.Rows.Count; x++) {
                    IRow row = sheet.CreateRow(sheet.LastRowNum + 1);//创建行  
                    //遍历列 
                    for (int i = 0; i < dt.Columns.Count; i++) {
                        var colname = dt.Columns[i].ColumnName;
                        ICell cell = row.CreateCell(i);
                        if (dt.Rows[x][i] != DBNull.Value) {
                            cell.SetCellValue(dt.Rows[x][i].ToString());
                        }
                    }
                } 
            } 
        }
        /// <summary>
        /// 获取当前节点所有的叶子节点
        /// </summary>
        /// <param name="headcfg">配置</param> 
        /// <returns></returns>
        /// <remarks>
        /// 创建:shunlu 2018-10-28
        /// </remarks>
        private static List<NpoiHeadCfg> GetAllLeafNode(NpoiHeadCfg headcfg) {
            List<NpoiHeadCfg> heads = new List<NpoiHeadCfg>();
            if (headcfg != null) {
                if (headcfg.Childs.Count > 0) {
                    for (int i = 0; i < headcfg.Childs.Count; i++) {
                        var hds = GetAllLeafNode(headcfg.Childs[i]);//递归调用
                        if (hds.Count > 0) {
                            heads.AddRange(hds);
                        }
                    }
                    return heads;
                } else {
                    heads.Add(headcfg);
                    return heads;
                }
            } else {
                return heads;
            }
        }

        /// <summary>
        /// 判断是否指定名称的叶子节点
        /// </summary>
        /// <param name="heads">配置列表</param>
        /// <param name="colname">目标列名称</param>
        /// <returns></returns>
        /// <remarks>
        /// 创建:shunlu 2018-10-26
        /// </remarks>
        private static bool HasTargetNode(List<NpoiHeadCfg> heads, string colname) {
            if (heads != null) {
                var bhav = heads.Exists(w => w.Childs.Count == 0 && w.FieldName.ToLower() == colname.ToLower()); // 只查叶子节点,忽略大小写
                if (bhav) {
                    return bhav;
                } else {
                    for (int i = 0; i < heads.Count; i++) {
                        bhav = HasTargetNode(heads[i].Childs, colname);//递归调用
                        if (bhav) {
                            return true;
                        }
                    }
                    return false;
                }
            } else {
                return false;
            }
        }

        /// <summary>
        /// 设置单元格样式
        /// 风格请自己按headCfg参数编写
        /// </summary>
        /// <param name="book"></param>
        /// <param name="headCfg">表头配置</param>
        /// <returns></returns>
        /// <remarks>
        /// 创建:shunlu 2018-10-24 
        /// </remarks>
        private static ICellStyle GetCellStyle(XSSFWorkbook book, NpoiHeadCfg headCfg) {
            ICellStyle style0 = book.CreateCellStyle();
            // 2、行高
            //     row.Height = 30 * 20;    //行高为30
            // excelRow.Height = 25 * 20;
            //    单元格 列宽:
            //if (headCfg.Width > 0) {
            //    cell.Row.Sheet.SetColumnWidth(cell.ColumnIndex, headCfg.Width * 256);
            //}
            //三、设置居中: 
            //cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中    
            style0.Alignment = HorizontalAlignment.Left;
            style0.VerticalAlignment = VerticalAlignment.Center;
            //四、设置字体: 
            IFont font = book.CreateFont();
            font.FontName = "黑体";//.SetFontName("黑体");
            font.FontHeightInPoints = (short)11.5;//.SetFontHeightInPoints((short)16);//设置字体大小    
            style0.SetFont(font);//选择需要用到的字体格式 

            //大坑,大坑,大坑,shunlu 2018-10-10
            //必须设置单元格背景色 FillForegroundColor 和 FillPattern 的值才能正确显示背景色
            style0.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.LightCornflowerBlue.Index; //(short)1灰色  NPOI.HSSF.Util.HSSFColor.LightBlue.Index; 
            style0.FillPattern = FillPattern.SolidForeground; // CellStyle.SOLID_FOREGROUND

            //二、设置边框:
            //cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框    cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框    cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框    cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框    三、设置居中:      cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中    

            style0.BorderBottom = BorderStyle.Medium;// CellStyle.SOLID_FOREGROUND
            style0.BorderRight = BorderStyle.Medium;

            //三、设置居中: 
            //cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中    
            style0.Alignment = HorizontalAlignment.Left;
            style0.VerticalAlignment = VerticalAlignment.Center;

            //
            return style0;
        }

        /// <summary>
        /// 保存电子表格
        /// </summary>
        /// <param name="book"></param>
        /// <param name="fileName">文件名称</param>
        /// <param name="savePath">保存物理路径(不含文件名)</param>
        /// <remarks>
        /// 创建:shunlu 2018-10-24 
        /// </remarks>
        private static void SaveExcel(XSSFWorkbook book, string fileName, string savePath = "") {
            string fullpath = fileName;
            if (!string.IsNullOrEmpty(savePath)) {
                if (!savePath.EndsWith("\\"))
                    savePath += "\\";
                fullpath = savePath + fileName;
            }
            if (File.Exists(fullpath)) {
                File.Delete(fullpath);
            }
            FileStream fsOut = new FileStream(fullpath, FileMode.Create);
            book.Write(fsOut);
            fsOut.Close();
            fsOut.Dispose();
        }

        /// <summary>
        /// 下载电子表格文件
        /// </summary>
        /// <param name="book"></param>
        /// <param name="saveFileName">文件名称</param>
        /// <returns></returns>
        /// <remarks>
        /// 创建:shunlu 2018-10-24 
        /// </remarks>
        private static HttpResponseMessage DownXssfFile(XSSFWorkbook book, string saveFileName) { 
            var exportData = new NpoiMemoryStream(); 
            HttpResponseMessage response = new HttpResponseMessage(System.Net.HttpStatusCode.OK); 
            exportData.AllowClose = false;
            book.Write(exportData);
            exportData.Flush();
            exportData.Seek(0, SeekOrigin.Begin);
            exportData.AllowClose = true;
            response.Content = new StreamContent(exportData);
         
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") {
                FileName = saveFileName
            };
            if (response.Content.Headers.ContentDisposition.Parameters.Count > 0) {
                response.Content.Headers.ContentDisposition.FileName = saveFileName;
                var fn = response.Content.Headers.ContentDisposition.Parameters.ElementAt(0).Value;// = saveFileName;
            }
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/ms-excel"); 
            response.StatusCode = System.Net.HttpStatusCode.OK;

            return response;

        }
    }

    /// <summary>
    ///  电子表格的表头设置(支持多行表头设置)
    /// </summary>
    /// <remarks>
    /// 创建:shunlu 2018-10-24 
    /// </remarks>
    public class NpoiHeadCfg {

        /// <summary>
        /// 表头格式设置(支持多行表头)
        /// </summary>
        public NpoiHeadCfg() {
            Childs = new List<NpoiHeadCfg>();
        }

        /// <summary>
        /// 重载构造函数
        /// </summary> 
        /// <param name="FieldName">数据源列名</param>
        /// <param name="FieldLable">电子表格列名</param>
        /// <param name="Height">行高</param>
        /// <param name="Width">列宽</param>
        public NpoiHeadCfg(string FieldName, string FieldLable, int Width = 10, int Height = 13) {

            this.FieldName = FieldName;
            this.FieldLable = FieldLable;
            this.Height = Height;
            this.Width = Width;
            this.IsBold = true;
            //
            Childs = new List<NpoiHeadCfg>();
        }

        /// <summary>
        /// 字段名称
        /// </summary>
        public string FieldName { get; set; }

        /// <summary>
        /// 字段标签(表格行头标题)
        /// </summary>
        public string FieldLable { get; set; }
        /// <summary>
        /// 高度
        /// </summary>
        public int Height { get; set; }
        /// <summary>
        /// 宽度
        /// </summary>
        public int Width { get; set; }
        /// <summary>
        /// 背景颜色
        /// </summary>
        public string BackColor { get; set; }

        /// <summary>
        /// 文本颜色
        /// </summary>
        public string FontColor { get; set; }
        /// <summary>
        /// 是否粗体显示
        /// </summary>
        public bool IsBold { get; set; }

        /// <summary>
        /// 子节点
        /// </summary>
        public List<NpoiHeadCfg> Childs { get; set; }


    }

    /// <summary>
    /// 内存字节流
    /// </summary>
    public class NpoiMemoryStream : MemoryStream {
        /// <summary>
        /// 
        /// </summary>
        public NpoiMemoryStream() {
            AllowClose = true;
        }
        /// <summary>
        /// 
        /// </summary>
        public bool AllowClose { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public override void Close() {
            if (AllowClose)
                base.Close();
        }
    }
}

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/shunlu/article/details/83480012

智能推荐

while循环&CPU占用率高问题深入分析与解决方案_main函数使用while(1)循环cpu占用99-程序员宅基地

文章浏览阅读3.8k次,点赞9次,收藏28次。直接上一个工作中碰到的问题,另外一个系统开启多线程调用我这边的接口,然后我这边会开启多线程批量查询第三方接口并且返回给调用方。使用的是两三年前别人遗留下来的方法,放到线上后发现确实是可以正常取到结果,但是一旦调用,CPU占用就直接100%(部署环境是win server服务器)。因此查看了下相关的老代码并使用JProfiler查看发现是在某个while循环的时候有问题。具体项目代码就不贴了,类似于下面这段代码。​​​​​​while(flag) {//your code;}这里的flag._main函数使用while(1)循环cpu占用99

【无标题】jetbrains idea shift f6不生效_idea shift +f6快捷键不生效-程序员宅基地

文章浏览阅读347次。idea shift f6 快捷键无效_idea shift +f6快捷键不生效

node.js学习笔记之Node中的核心模块_node模块中有很多核心模块,以下不属于核心模块,使用时需下载的是-程序员宅基地

文章浏览阅读135次。Ecmacript 中没有DOM 和 BOM核心模块Node为JavaScript提供了很多服务器级别,这些API绝大多数都被包装到了一个具名和核心模块中了,例如文件操作的 fs 核心模块 ,http服务构建的http 模块 path 路径操作模块 os 操作系统信息模块// 用来获取机器信息的var os = require('os')// 用来操作路径的var path = require('path')// 获取当前机器的 CPU 信息console.log(os.cpus._node模块中有很多核心模块,以下不属于核心模块,使用时需下载的是

数学建模【SPSS 下载-安装、方差分析与回归分析的SPSS实现(软件概述、方差分析、回归分析)】_化工数学模型数据回归软件-程序员宅基地

文章浏览阅读10w+次,点赞435次,收藏3.4k次。SPSS 22 下载安装过程7.6 方差分析与回归分析的SPSS实现7.6.1 SPSS软件概述1 SPSS版本与安装2 SPSS界面3 SPSS特点4 SPSS数据7.6.2 SPSS与方差分析1 单因素方差分析2 双因素方差分析7.6.3 SPSS与回归分析SPSS回归分析过程牙膏价格问题的回归分析_化工数学模型数据回归软件

利用hutool实现邮件发送功能_hutool发送邮件-程序员宅基地

文章浏览阅读7.5k次。如何利用hutool工具包实现邮件发送功能呢?1、首先引入hutool依赖<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.19</version></dependency>2、编写邮件发送工具类package com.pc.c..._hutool发送邮件

docker安装elasticsearch,elasticsearch-head,kibana,ik分词器_docker安装kibana连接elasticsearch并且elasticsearch有密码-程序员宅基地

文章浏览阅读867次,点赞2次,收藏2次。docker安装elasticsearch,elasticsearch-head,kibana,ik分词器安装方式基本有两种,一种是pull的方式,一种是Dockerfile的方式,由于pull的方式pull下来后还需配置许多东西且不便于复用,个人比较喜欢使用Dockerfile的方式所有docker支持的镜像基本都在https://hub.docker.com/docker的官网上能找到合..._docker安装kibana连接elasticsearch并且elasticsearch有密码

随便推点

Python 攻克移动开发失败!_beeware-程序员宅基地

文章浏览阅读1.3w次,点赞57次,收藏92次。整理 | 郑丽媛出品 | CSDN(ID:CSDNnews)近年来,随着机器学习的兴起,有一门编程语言逐渐变得火热——Python。得益于其针对机器学习提供了大量开源框架和第三方模块,内置..._beeware

Swift4.0_Timer 的基本使用_swift timer 暂停-程序员宅基地

文章浏览阅读7.9k次。//// ViewController.swift// Day_10_Timer//// Created by dongqiangfei on 2018/10/15.// Copyright 2018年 飞飞. All rights reserved.//import UIKitclass ViewController: UIViewController { ..._swift timer 暂停

元素三大等待-程序员宅基地

文章浏览阅读986次,点赞2次,收藏2次。1.硬性等待让当前线程暂停执行,应用场景:代码执行速度太快了,但是UI元素没有立马加载出来,造成两者不同步,这时候就可以让代码等待一下,再去执行找元素的动作线程休眠,强制等待 Thread.sleep(long mills)package com.example.demo;import org.junit.jupiter.api.Test;import org.openqa.selenium.By;import org.openqa.selenium.firefox.Firefox.._元素三大等待

Java软件工程师职位分析_java岗位分析-程序员宅基地

文章浏览阅读3k次,点赞4次,收藏14次。Java软件工程师职位分析_java岗位分析

Java:Unreachable code的解决方法_java unreachable code-程序员宅基地

文章浏览阅读2k次。Java:Unreachable code的解决方法_java unreachable code

标签data-*自定义属性值和根据data属性值查找对应标签_如何根据data-*属性获取对应的标签对象-程序员宅基地

文章浏览阅读1w次。1、html中设置标签data-*的值 标题 11111 222222、点击获取当前标签的data-url的值$('dd').on('click', function() { var urlVal = $(this).data('ur_如何根据data-*属性获取对应的标签对象

推荐文章

热门文章

相关标签