惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Vulnerabilities – Threatpost
U
Unit 42
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
P
Proofpoint News Feed
F
Full Disclosure
月光博客
月光博客
Engineering at Meta
Engineering at Meta
博客园_首页
The Register - Security
The Register - Security
G
Google Developers Blog
The Cloudflare Blog
博客园 - Franky
K
Kaspersky official blog
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
C
Check Point Blog
NISL@THU
NISL@THU
AI
AI
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Stack Overflow Blog
Stack Overflow Blog
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Vercel News
Vercel News
T
Tor Project blog
P
Privacy International News Feed
D
Docker
I
Intezer
L
LangChain Blog
P
Proofpoint News Feed
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
博客园 - 聂微东
AWS News Blog
AWS News Blog
Martin Fowler
Martin Fowler
P
Privacy & Cybersecurity Law Blog
V
V2EX
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
The Hacker News
The Hacker News
T
Tenable Blog
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog

博客园 - baileyer

VisualSVN破解安装到VS2026 使用 SQL 中的递归查询(Recursive CTE)来实现1-50数字 git 忽略本地文件提交(VS) Abp vue项目找不到模块“./app.vue” MSSqlserver分割文件备份恢复 github的镜像下载加快clone下载速度 widows部署.NET Core 3.1项目到IIS问题 .net core/mvc获取特性 oracle instr 替代like查询 quartz3.0.7和topshelf4.2.1实现任务调度 VS2017同时生成.net core和.net framework两份代码 .net core Failed to load API definition 错误 vs 2017 调试中断问题 .net Core 2.2实现京东宙斯API采用OAuth授权方式调用 WinForm 校验只能输入数字英文字母退格键 NPOI导出excel C#通过反射获取相应的字段和值 activemq.bat 在window7 x64下启动(安装)报错解决方案 <asp:RadioButton> 选项判断
C# 自定义导出模板(NPOI)
baileyer · 2022-04-07 · via 博客园 - baileyer
private async Task<Stream> ExportOrderDtlTemp(string tempName = "订货订单明细导入模板")
        {
            IWorkbook workbook = new XSSFWorkbook(); //.xlsx
            ISheet sheet = workbook.CreateSheet("sheet1");
            #region 创建表头
            #region 尺码组
            //第一行
            IRow row = sheet.CreateRow(0);
            row.CreateCell(0).SetCellValue("");
            row.CreateCell(1).SetCellValue("");
            row.CreateCell(2).SetCellValue("");
            row.CreateCell(3).SetCellValue("尺码组名称A");
            row.CreateCell(4).SetCellValue("36");
            row.CreateCell(5).SetCellValue("37");
            row.CreateCell(6).SetCellValue("38");
            row.CreateCell(7).SetCellValue("39");
            row.CreateCell(8).SetCellValue("40");
            //第二行
            IRow row2 = sheet.CreateRow(1);
            row2.CreateCell(0).SetCellValue("");
            row2.CreateCell(1).SetCellValue("");
            row2.CreateCell(2).SetCellValue("");
            row2.CreateCell(3).SetCellValue("尺码组名称B");
            row2.CreateCell(4).SetCellValue("S");
            row2.CreateCell(5).SetCellValue("M");
            row2.CreateCell(6).SetCellValue("L");
            row2.CreateCell(7).SetCellValue("XL");
            row2.CreateCell(8).SetCellValue("XXL");
            #endregion

            #region 第三行
            IRow rowTitle = sheet.CreateRow(2);
            rowTitle.CreateCell(0).SetCellValue("商品编码");
            rowTitle.CreateCell(1).SetCellValue("商品名称");
            rowTitle.CreateCell(2).SetCellValue("颜色");
            rowTitle.CreateCell(3).SetCellValue("店铺");
            rowTitle.CreateCell(4).SetCellValue("尺码1");
            rowTitle.CreateCell(5).SetCellValue("尺码2");
            rowTitle.CreateCell(6).SetCellValue("尺码3");
            rowTitle.CreateCell(7).SetCellValue("尺码4");
            rowTitle.CreateCell(8).SetCellValue("尺码5");
            #endregion 
            #endregion
            //字体颜色
            IFont font = workbook.CreateFont();
            font.Color = IndexedColors.Red.Index;
            ICellStyle style = workbook.CreateCellStyle();
            style.SetFont(font);
            rowTitle.GetCell(0).CellStyle = style;
            rowTitle.GetCell(2).CellStyle = style;
            rowTitle.GetCell(3).CellStyle = style;
            //转为字节数组  
            MemoryStream memoryStream = new MemoryStream();
            workbook.Write(memoryStream);
            var buf = memoryStream.ToArray();
            memoryStream = (MemoryStream)null;
            //返回待下载文件
            Stream stream = new MemoryStream(buf);
            stream.Flush();
            stream.Position = 0L;
            stream.Seek(0L, SeekOrigin.Begin);
            string str = ".xlsx";
            string fileName = (string.IsNullOrEmpty(tempName) ? DateTime.Now.ToString("yyyyMMddHHmmssffff") : tempName) + str;
            this._httpContextAccessor.HttpContext.Response.ContentType = "application/vnd.ms-excel";
            this._httpContextAccessor.HttpContext.Response.ContentLength = new long?(stream.Length);
            ContentDispositionHeaderValue dispositionHeaderValue = new ContentDispositionHeaderValue((StringSegment)"attachment");
            dispositionHeaderValue.SetHttpFileName((StringSegment)fileName);
            this._httpContextAccessor.HttpContext.Response.Headers["Content-Disposition"] = (StringValues)((object)dispositionHeaderValue).ToString();
            this._httpContextAccessor.HttpContext.Response.Headers["Accept-Ranges"] = (StringValues)"bytes";
            Stream stream1 = (Stream)stream;
            stream = (NpoiMemoryStream)null;
            return stream1;
        }

posted @ 2022-04-07 17:35  baileyer  阅读(375)  评论()    收藏  举报