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

智能推荐

分布式光纤传感器的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告_预计2026年中国分布式传感器市场规模有多大-程序员宅基地

文章浏览阅读3.2k次。本文研究全球与中国市场分布式光纤传感器的发展现状及未来发展趋势,分别从生产和消费的角度分析分布式光纤传感器的主要生产地区、主要消费地区以及主要的生产商。重点分析全球与中国市场的主要厂商产品特点、产品规格、不同规格产品的价格、产量、产值及全球和中国市场主要生产商的市场份额。主要生产商包括:FISO TechnologiesBrugg KabelSensor HighwayOmnisensAFL GlobalQinetiQ GroupLockheed MartinOSENSA Innovati_预计2026年中国分布式传感器市场规模有多大

07_08 常用组合逻辑电路结构——为IC设计的延时估计铺垫_基4布斯算法代码-程序员宅基地

文章浏览阅读1.1k次,点赞2次,收藏12次。常用组合逻辑电路结构——为IC设计的延时估计铺垫学习目的:估计模块间的delay,确保写的代码的timing 综合能给到多少HZ,以满足需求!_基4布斯算法代码

OpenAI Manager助手(基于SpringBoot和Vue)_chatgpt网页版-程序员宅基地

文章浏览阅读3.3k次,点赞3次,收藏5次。OpenAI Manager助手(基于SpringBoot和Vue)_chatgpt网页版

关于美国计算机奥赛USACO,你想知道的都在这_usaco可以多次提交吗-程序员宅基地

文章浏览阅读2.2k次。USACO自1992年举办,到目前为止已经举办了27届,目的是为了帮助美国信息学国家队选拔IOI的队员,目前逐渐发展为全球热门的线上赛事,成为美国大学申请条件下,含金量相当高的官方竞赛。USACO的比赛成绩可以助力计算机专业留学,越来越多的学生进入了康奈尔,麻省理工,普林斯顿,哈佛和耶鲁等大学,这些同学的共同点是他们都参加了美国计算机科学竞赛(USACO),并且取得过非常好的成绩。适合参赛人群USACO适合国内在读学生有意向申请美国大学的或者想锻炼自己编程能力的同学,高三学生也可以参加12月的第_usaco可以多次提交吗

MySQL存储过程和自定义函数_mysql自定义函数和存储过程-程序员宅基地

文章浏览阅读394次。1.1 存储程序1.2 创建存储过程1.3 创建自定义函数1.3.1 示例1.4 自定义函数和存储过程的区别1.5 变量的使用1.6 定义条件和处理程序1.6.1 定义条件1.6.1.1 示例1.6.2 定义处理程序1.6.2.1 示例1.7 光标的使用1.7.1 声明光标1.7.2 打开光标1.7.3 使用光标1.7.4 关闭光标1.8 流程控制的使用1.8.1 IF语句1.8.2 CASE语句1.8.3 LOOP语句1.8.4 LEAVE语句1.8.5 ITERATE语句1.8.6 REPEAT语句。_mysql自定义函数和存储过程

半导体基础知识与PN结_本征半导体电流为0-程序员宅基地

文章浏览阅读188次。半导体二极管——集成电路最小组成单元。_本征半导体电流为0

随便推点

【Unity3d Shader】水面和岩浆效果_unity 岩浆shader-程序员宅基地

文章浏览阅读2.8k次,点赞3次,收藏18次。游戏水面特效实现方式太多。咱们这边介绍的是一最简单的UV动画(无顶点位移),整个mesh由4个顶点构成。实现了水面效果(左图),不动代码稍微修改下参数和贴图可以实现岩浆效果(右图)。有要思路是1,uv按时间去做正弦波移动2,在1的基础上加个凹凸图混合uv3,在1、2的基础上加个水流方向4,加上对雾效的支持,如没必要请自行删除雾效代码(把包含fog的几行代码删除)S..._unity 岩浆shader

广义线性模型——Logistic回归模型(1)_广义线性回归模型-程序员宅基地

文章浏览阅读5k次。广义线性模型是线性模型的扩展,它通过连接函数建立响应变量的数学期望值与线性组合的预测变量之间的关系。广义线性模型拟合的形式为:其中g(μY)是条件均值的函数(称为连接函数)。另外,你可放松Y为正态分布的假设,改为Y 服从指数分布族中的一种分布即可。设定好连接函数和概率分布后,便可以通过最大似然估计的多次迭代推导出各参数值。在大部分情况下,线性模型就可以通过一系列连续型或类别型预测变量来预测正态分布的响应变量的工作。但是,有时候我们要进行非正态因变量的分析,例如:(1)类别型.._广义线性回归模型

HTML+CSS大作业 环境网页设计与实现(垃圾分类) web前端开发技术 web课程设计 网页规划与设计_垃圾分类网页设计目标怎么写-程序员宅基地

文章浏览阅读69次。环境保护、 保护地球、 校园环保、垃圾分类、绿色家园、等网站的设计与制作。 总结了一些学生网页制作的经验:一般的网页需要融入以下知识点:div+css布局、浮动、定位、高级css、表格、表单及验证、js轮播图、音频 视频 Flash的应用、ul li、下拉导航栏、鼠标划过效果等知识点,网页的风格主题也很全面:如爱好、风景、校园、美食、动漫、游戏、咖啡、音乐、家乡、电影、名人、商城以及个人主页等主题,学生、新手可参考下方页面的布局和设计和HTML源码(有用点赞△) 一套A+的网_垃圾分类网页设计目标怎么写

C# .Net 发布后,把dll全部放在一个文件夹中,让软件目录更整洁_.net dll 全局目录-程序员宅基地

文章浏览阅读614次,点赞7次,收藏11次。之前找到一个修改 exe 中 DLL地址 的方法, 不太好使,虽然能正确启动, 但无法改变 exe 的工作目录,这就影响了.Net 中很多获取 exe 执行目录来拼接的地址 ( 相对路径 ),比如 wwwroot 和 代码中相对目录还有一些复制到目录的普通文件 等等,它们的地址都会指向原来 exe 的目录, 而不是自定义的 “lib” 目录,根本原因就是没有修改 exe 的工作目录这次来搞一个启动程序,把 .net 的所有东西都放在一个文件夹,在文件夹同级的目录制作一个 exe._.net dll 全局目录

BRIEF特征点描述算法_breif description calculation 特征点-程序员宅基地

文章浏览阅读1.5k次。本文为转载,原博客地址:http://blog.csdn.net/hujingshuang/article/details/46910259简介 BRIEF是2010年的一篇名为《BRIEF:Binary Robust Independent Elementary Features》的文章中提出,BRIEF是对已检测到的特征点进行描述,它是一种二进制编码的描述子,摈弃了利用区域灰度..._breif description calculation 特征点

房屋租赁管理系统的设计和实现,SpringBoot计算机毕业设计论文_基于spring boot的房屋租赁系统论文-程序员宅基地

文章浏览阅读4.1k次,点赞21次,收藏79次。本文是《基于SpringBoot的房屋租赁管理系统》的配套原创说明文档,可以给应届毕业生提供格式撰写参考,也可以给开发类似系统的朋友们提供功能业务设计思路。_基于spring boot的房屋租赁系统论文