public void Export(DataRequest<ExportModel> request, DataResponse<dynamic> response)
{ try
{
var order = GetShopModel(request.ObjectData.guid); var newFile = Directory.GetCurrentDirectory() + "\\Export\\Order" + order.OrderDate + ".xls";
string p = System.IO.Path.GetDirectoryName(newFile);
if (!System.IO.Directory.Exists(p))
System.IO.Directory.CreateDirectory(p); var ShopGid = order.ShopGid; string startTime = order.OrderDate.Split('~')[] + " 00:00:00";
string endTime = order.OrderDate.Split('~')[] + " 23:59:59"; using (var fs = new FileStream(newFile, FileMode.Create, FileAccess.Write))
{
IWorkbook workbook = new XSSFWorkbook();
#region 车辆销售订单明细
ISheet sheet1 = workbook.CreateSheet("门店销售订单明细"); //index代表多少行
var rowIndex = ;
//创建表头行
IRow row = sheet1.CreateRow(rowIndex);
row.HeightInPoints = ;//行高 row.CreateCell().SetCellValue("门店商铺");
row.CreateCell().SetCellValue("商铺号码");
row.CreateCell().SetCellValue("销售单号");
row.CreateCell().SetCellValue("提车时间"); //填充数据
List<ExportOrderModel> OrderShops = GetModelExl(ShopGid.Value, startTime, endTime);
for (int i = ; i < OrderShops.Count; i++)
{
IRow row1 = sheet1.CreateRow(i + );
ICell cell = row1.CreateCell(); //创建第一列 #region 标题行设置字体
ICellStyle style = workbook.CreateCellStyle();//创建样式对象 //设置单元格的样式:水平对齐填充
style.Alignment = HorizontalAlignment.Left;
style.VerticalAlignment = VerticalAlignment.Center;//垂直居中 //自动换行
style.WrapText = true;
IFont font = workbook.CreateFont(); //创建一个字体样式对象
font.FontName = "宋体"; //和excel里面的字体对应 font.IsItalic = false; //斜体
font.FontHeightInPoints = ;//字体大小
//font.Boldweight = short.MaxValue;//字体加粗
font.Boldweight = (Int16)FontBoldWeight.Bold;//加粗;
style.SetFont(font); //将字体样式赋给样式对象
//cell.CellStyle = style; //把样式赋给单元格 /*修改指定单元格样式 如果要修改行样式则需要将row.Cells.Count循环出来,挨个设置!*/
// row.Cells[1].CellStyle = style;
for (int k = ; k < row.Cells.Count; k++)
{
row.Cells[k].CellStyle = style;
//列宽25 //设置列宽
sheet1.SetColumnWidth(k, * );
} #endregion #region 单元格列值属性样式 //for (int jj = 0; jj < row1.Cells.Count; jj++)
//{
// row1.Cells[jj].CellStyle = style; //}
//cell.CellStyle = style; #endregion cell.SetCellValue(OrderShops[i].ShopName);
cell = row1.CreateCell();//设置单元格的值
//设置列值样式
//row1.CreateCell(0).CellStyle = style;
cell.SetCellValue(order.ShopNo);
cell = row1.CreateCell();
cell.SetCellValue(OrderShops[i].OrderSaleNo);
cell = row1.CreateCell();
cell.SetCellValue(OrderShops[i].PayDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")); } #endregion #endregion #region 车辆销售换货明细表格 //创建表头
ISheet sheet6 = workbook.CreateSheet("车辆销售换货明细表格");
IRow row6 = sheet6.CreateRow();
row6.HeightInPoints = ;//行高
row6.CreateCell().SetCellValue("换货单号");
row6.CreateCell().SetCellValue("新车辆颜色");
row6.CreateCell().SetCellValue("原车辆型号类型"); var table = GetChangeOrder(ShopGid.Value, startTime, endTime);
j = ;
foreach (DataRow item in table.Rows)
{
IRow row1 = sheet6.CreateRow(j + );
ICell cell = row1.CreateCell(); #region 标题行设置字体
ICellStyle style = workbook.CreateCellStyle();//创建样式对象 //设置单元格的样式:水平对齐填充
style.Alignment = HorizontalAlignment.Left;
style.VerticalAlignment = VerticalAlignment.Center;//垂直居中 //自动换行
style.WrapText = true;
IFont font = workbook.CreateFont(); //创建一个字体样式对象
font.FontName = "宋体"; //和excel里面的字体对应 font.IsItalic = false; //斜体
font.FontHeightInPoints = ;//字体大小
//font.Boldweight = short.MaxValue;//字体加粗
font.Boldweight = (Int16)FontBoldWeight.Bold;//加粗;
style.SetFont(font); //将字体样式赋给样式对象
//cell.CellStyle = style; //把样式赋给单元格 /*修改指定单元格样式 如果要修改行样式则需要将row.Cells.Count循环出来,挨个设置!*/
// row.Cells[1].CellStyle = style;
for (int k = ; k < row6.Cells.Count; k++)
{
row6.Cells[k].CellStyle = style;
//列宽25
sheet6.SetColumnWidth(k, * );
} #endregion cell.SetCellValue(DataConvertHelper.GetString(item["ChangeNo"]));
cell = row1.CreateCell();
cell.SetCellValue(DataConvertHelper.GetString(item["OrderColor"]));
cell = row1.CreateCell();
cell.SetCellValue(DataConvertHelper.GetString(item["OrderType"])); j++;
}
#endregion workbook.Write(fs);
}
response.Tag = Common.ExportFile.ExportFlag;
response.ObjectData = new Common.ExportFile
{
FilePath = newFile,
FileName = "订单信息" + + ".xls"
};
}
catch (Exception ex)
{ LogHelper.Debug("异常" + ex.Message, "导出异常", this.GetType().ToString());
response.ObjectData= ex.Message; } }

NPOI导出EXCEL样式的更多相关文章

  1. NPOI导出EXCEL部分样式不起作用

    在使用NPOI导出excel的时候,设置cell样式,数据量多余6条之后,在后面几条数据没有样式(边框,对其,换行等). 原因是设置CellStyle的时候把CreateCellStyle放在循环列集 ...

  2. NPOI导出Excel (C#) 踩坑 之--The maximum column width for an individual cell is 255 charaters

    /******************************************************************* * 版权所有: * 类 名 称:ExcelHelper * 作 ...

  3. .NET NPOI导出Excel详解

    NPOI,顾名思义,就是POI的.NET版本.那POI又是什么呢?POI是一套用Java写成的库,能够帮助开发者在没有安装微软Office的情况下读写Office的文件. 支持的文件格式包括xls, ...

  4. NPOI导出Excel(含有超过65335的处理情况)

    NPOI导出Excel的网上有很多,正好自己遇到就学习并总结了一下: 首先说明几点: 1.Excel2003及一下:后缀xls,单个sheet最大行数为65335 Excel2007 单个sheet ...

  5. NPOI导出Excel示例

    摘要:使用开源程序NPOI导出Excel示例.NPOI首页地址:http://npoi.codeplex.com/,NPOI示例博客:http://tonyqus.sinaapp.com/. 示例编写 ...

  6. Npoi导出excel整理(附源码)

    前些日子做了一个简单的winform程序,需要导出的功能,刚开始省事直接使用微软的组件,但是导出之后发现效率极其低下,绝对像web那样使用npoi组件,因此简单的进行了整理,包括直接根据DataTab ...

  7. 使用NPOI导出Excel文件

    使用NPOI导出Excel文件,本实例使用了ASP.NET MVC. 1.使用NPOI导出Excel文件 实例:导出商品列表. 要求:1.通过NPOI导出导出商品列表信息: 2.使用Excel函数计算 ...

  8. Asp.Net 使用Npoi导出Excel

    引言 使用Npoi导出Excel 服务器可以不装任何office组件,昨天在做一个导出时用到Npoi导出Excel,而且所导Excel也符合规范,打开时不会有任何文件损坏之类的提示.但是在做导入时还是 ...

  9. NPOI导出EXCEL 打印设置分页及打印标题

    在用NPOI导出EXCEL的时候设置分页,在网上有查到用sheet1.SetRowBreak(i)方法,但一直都没有起到作用.经过研究是要设置  sheet1.FitToPage = false; 而 ...

随机推荐

  1. ELK Stack部署

    部署ELK Stack 官网:https://www.elastic.co 环境准备: ip hostname 服务 用户.组 192.168.20.3 node2003 kibana6.5,file ...

  2. MySQL/MariaDB数据库的用户和权限管理

    MySQL/MariaDB数据库的用户和权限管理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.元数据数据库(mysql) 系统授权表(均在mysql数据库中): db hos ...

  3. Kali下的内网劫持(一)

    ettercap利用计算机在局域网内进行通信的ARP协议的缺陷进行攻击,在目标主机与服务器之间充当中间人,嗅探两者之间的数据流量,从中窃取用户的数据信息,那么接下来我就给大家演示一下客户端的图片是怎么 ...

  4. PAT甲级1012题解——选择一种合适数据存储方式能使题目变得更简单

    题目分析: 本题的算法并不复杂,主要是要搞清楚数据的存储方式(选择一种合适的方式存储每个学生的四个成绩很重要)这里由于N的范围为10^6,故选择结构体来存放对应下标为学生的id(N只有2000的范围, ...

  5. 动态创建自绘的CListBox注意事项

    Create(WS_VISIBLE|WS_CHILD|LBS_NOTIFY|LBS_OWNERDRAWFIXED|LBS_HASSTRINGS|LBS_NOINTEGRALHEIGHT ,rcWnd, ...

  6. 如何让VS像CB一样使用

    之前用VS,先是完成了GLUT库下的opengl使用: 然后得知GLUT有些过时,又按照教程接触了GLFW库下,反正对我来说是有些复杂. 今天正式试一试用VS来写ACM的题目,发现不能定义string ...

  7. 浏览器-同源政策(same-origin policy)

    浏览器安全的基石是“同源政策”(same-origin policy). 1995年,同源政策由 Netscape 公司引入浏览器.目前,所有浏览器都实行这个政策. 何为同源? 协议相同 域名相同 端 ...

  8. pandas 6 时间

    类 备注 创建方法 Timestamp 时刻数据 to_datetime,Timestamp DatetimeIndex Timestamp的索引 to_datetime,date_range,Dat ...

  9. HBase学习笔记之HBase的安装和配置

    HBase学习笔记之HBase的安装和配置 我是为了调研和验证hbase的bulkload功能,才安装hbase,学习hbase的.为了快速的验证bulkload功能,我安装了一个节点的hadoop集 ...

  10. Tips on Probability Theory

    1.独立与不相关 随机变量X和Y相互独立,有:E(XY) = E(X)E(Y). 独立一定不相关,不相关不一定独立(高斯过程里二者等价) .对于均值为零的高斯随机变量,“独立”和“不相关”等价的. 独 ...