c# 导出excel格式xlsx
string sb="";//sql字符串
AttachmentConfigSection configSection = ConfigurationManager.GetSection("AttachmentConfig") as AttachmentConfigSection;
string path = "";
string sheetName = "Sheet1";
string fileName = "月结状态处理.xlsx";
if (!string.IsNullOrEmpty(configSection.ElementInformation.Source))
{
path = configSection.TargetPath.Path;
}
else
{
errormsg = "模版不正确";
}
WriteLog("xiujiamontyle 123....."+sb.ToString());
string index = "\\Upload\\XiuJiaMontly\\" + fileName;
string descFile = path + index.ToString();
FileInfo fileinfo = new FileInfo(descFile);
ExcelPackage excel = new ExcelPackage(fileinfo);
ExcelWorksheet sheet = excel.Workbook.Worksheets[sheetName];
DataTable dt = DBHelperExtend.Query(sb.ToString()).Tables[0];
int row = dt.Rows.Count; //行 sheet.Cells[1, 1].Value = "任务编号";
sheet.Cells[1, 2].Value = "月结状态";
sheet.Cells[1, 3].Value = "提交人";
sheet.Cells[1, 4].Value ="员工编号";
sheet.Cells[1, 5].Value ="部门";
sheet.Cells[1, 6].Value ="区域";
sheet.Cells[1, 7].Value ="休假类别";
sheet.Cells[1, 8].Value ="是否住院";
sheet.Cells[1, 9].Value ="原因";
sheet.Cells[1, 10].Value ="休假时间";
sheet.Cells[1, 11].Value = "天数时数";
sheet.Cells[1, 12].Value = "提交日期";
sheet.Cells[1, 13].Value = "状态";
sheet.Cells[1, 14].Value = "撤回编号";
sheet.Cells[1, 15].Value = "撤回日期";
sheet.Cells[1, 16].Value = "撤回状态";
sheet.Cells[1, 17].Value = "用年假抵扣"; for (int i = 0; i < dt.Rows.Count; i++)
{
sheet.Cells[i + 2, 1].Value = dt.Rows[i]["TaskID"];
sheet.Cells[i + 2, 2].Value = dt.Rows[i]["monthlyStatus"];
sheet.Cells[i + 2, 3].Value = dt.Rows[i]["RequestAccount"];
sheet.Cells[i + 2, 4].Value = dt.Rows[i]["hrid"];
sheet.Cells[i + 2, 5].Value = dt.Rows[i]["RequestDept"];
sheet.Cells[i + 2, 6].Value = dt.Rows[i]["RequestLocation"];
sheet.Cells[i + 2, 7].Value = dt.Rows[i]["XiuJiaType"];
sheet.Cells[i + 2, 8].Value = dt.Rows[i]["IsInHospital"];
sheet.Cells[i + 2, 9].Value = dt.Rows[i]["Description"];
sheet.Cells[i + 2, 10].Value = dt.Rows[i]["XiuJiaDate"];
sheet.Cells[i + 2, 11].Value = dt.Rows[i]["TotalTime"];
sheet.Cells[i + 2, 12].Value = dt.Rows[i]["SubmitTime"];
sheet.Cells[i + 2, 13].Value = dt.Rows[i]["Status"];
sheet.Cells[i + 2, 14].Value = dt.Rows[i]["CH_TaskID"];
sheet.Cells[i + 2, 15].Value = dt.Rows[i]["cheHuiTime"];
sheet.Cells[i + 2, 16].Value = dt.Rows[i]["cheHuiStatus"];
sheet.Cells[i + 2, 17].Value = dt.Rows[i]["AnnualDeductible"];
}
byte[] b = excel.GetAsByteArray();
HttpContext curContext = System.Web.HttpContext.Current;
// curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.ContentType = "text/plain";//Content-Disposition
// curContext.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
curContext.Response.AddHeader("content-disposition", "attachment; filename=XiuJiaMonthlyHandel.xlsx");
curContext.Response.Charset = "gb2312"; //必须写,否则会有乱码
curContext.Response.ContentEncoding = System.Text.Encoding.UTF7; //必须写,否则会有乱码 curContext.Response.AddHeader("Content-Length", b.Length.ToString());
curContext.Response.BinaryWrite(b);
curContext.Response.End();
c# 导出excel格式xlsx的更多相关文章
- 将页面中表格数据导出excel格式的文件(vue)
近期由于项目需要,需要将页面中的表格数据导出excel格式的文件,折腾了许久,在网上各种百度,虽然资料不少,但是大都不全,踩了许多坑,总算是皇天不负有心人,最后圆满解决了. 1.安装相关依赖(npm安 ...
- Powerdesigner 导出Excel格式数据字典 导出Excel格式文件
版权声明:本文为博主原创文章,转载请注明出处; 网上我也看到了很多的Powerdesigner 导出方法,因为Powerdesigner 提供了部分VBA功能,所以让我用代码导出Excel格式文件得以 ...
- 使用PHPExcel导入导出excel格式文件
使用PHPExcel导入导出excel格式文件 作者:zccst 因为导出使用较多,以下是导出实现过程. 第一步,将PHPExcel的源码拷贝到项目的lib下 文件包含:PHPExcel.ph ...
- 获取一个表中的字段总数(mysql) Navicat如何导出Excel格式表结构 获取某个库中的一个表中的所有字段和数据类型
如何获取一个表中的字段总数 1.function show columns from 表明: 结果 : 2.functiuon select count(*) from INFORMATION_SCH ...
- Html Table用JS导出excel格式问题 导出EXCEL后单元格里的000412341234会变成412341234 7-14 会变成 2018-7-14(7月14) 自定义格式 web利用table表格生成excel格式问题 js导出excel增加表头、mso-number-format定义数据格式 数字输出格式转换 mso-number-format:"\@"
Html Table用JS导出excel格式问题 我在网上找的JS把HTML Tabel导出成EXCEL.但是如果Table里的数字内容为0开的的导成Excel后会自动删除0,我想以text的格式写入 ...
- 插件 ExcelWrite 导出Excel格式数据/获取图层
使用ExcelWrite 插件可以导出Excel格式的数据: ExcelFile端口接 文件数据路径 最后面的是文件名,不用写格式 如果存储树形数据,需要 勾选 List To Row 选项: 附: ...
- [转发]导出Excel 格式 mso-number-format
应用中经常会遇到要从系统或数据库中导出数据平面文件,一般是导出到txt,csv或excel.txt和csv一般用在系统间的数据交换,而 excel一般有较好的显示效果,可以按照一定的模板导出,导出就不 ...
- 使用NPOI导入导出Excel(xls/xlsx)数据到DataTable中
using System; using System.Collections.Generic; using System.Text; using System.IO; using NPOI.SS.Us ...
- winfrom 使用NPOI导入导出Excel(xls/xlsx)数据到DataTable中
1.通过NUGET管理器下载nopi,在引入命令空间 using System; using System.Collections.Generic; using System.Text; using ...
随机推荐
- Camera Calibration 相机标定:原理简介(四)
4 基于3D标定物的标定方法 使用基于3D标定物进行相机标定,是一种传统且常见的相机标定法.3D标定物在不同应用场景下不尽相同,摄影测量学中,使用的3D标定物种类最为繁杂,如图-1的室内控制场,由多条 ...
- 聊聊高并发(四十四)解析java.util.concurrent各个组件(二十) Executors工厂类
Executor框架为了更方便使用,提供了Executors这个工厂类.通过一系列的静态工厂方法.能够高速地创建对应的Executor实例. 仅仅有一个nThreads參数的newFixedThrea ...
- Android之Http通信——1.初识Http协议
Android之Http通信--1.初识Http协议 引言: 今天是六一儿童节,先在这里给各位超龄儿童说声节日快乐哈~( ╯□╰ ),小猪也象征性地给群里的小朋友们派了红包-嗯,忙碌的五月最终过去了, ...
- Android ListView动画实现方法
在Android中listview是最经常使用的控件之中的一个,可是有时候我们会认为千篇一律的listview看起来过于单调,于是就产生了listView动画,listview载入了动画会让用户体验更 ...
- nj05---模块
概念:模块(Module)和包(Package)是Node.js最重要的支柱.在浏览器JavaScript中,脚本模块的拆分和组合通常使用HTML的script标签来实现,Node.js提供了requ ...
- json的认识及对json数据的相互转化
Json 和 Jsonlib 的使用 什么是 Json JSON(JvaScript Object Notation)(官网网站:http://www.json.org/)是 一种轻量级的数据交换格式 ...
- directshow 获取本地摄像头播放
最近因为项目的需要,做了一个基本的获取本地笔记本摄像头并且播放的例子,因为网上的关于这部分的完整例子基本都没有,那我就上传一个吧,希望能够帮到需要学习视频的朋友. 另外也是为了纪念雷霄骅博士为音视频方 ...
- ubuntu16.04下snort的安装(官方文档安装)(图文详解)
不多说,直接上干货! 最近为了科研,需要安装和使用Snort. snort的官网 https://www.snort.org/ Snort作为一款优秀的开源主机入侵检测系统,在windows和Linu ...
- window.location.href=*.html访问没反应问题
window.location.href=*.html访问没反应问题 1.SpringMvc配置中:扫描controller.视图层配置路径是否正确 报doc根路径 <mapper>匹配错 ...
- PostgreSQL 系统表
postgres=# \d pg_class Table "pg_catalog.pg_class" Column | Type | Modif ...