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. Altium Designer常用快捷键总结

    一.PCB中常用快捷键 ● R+L 输出PCB中所有网络的布线长度 ● Ctrl+左键点击 对正在布的线完成自动布线连接 ● M+G 可更改铜的形状; ● 按P+T在布线状态下,按Shift+A可直接 ...

  2. MySQL/MariaDB数据库的PROXY实现读写分离

    MySQL/MariaDB数据库的PROXY实现读写分离 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.ProxySQL概述 1>.各家互联网公司读写分离的解决方案 m ...

  3. ps aux|grep *** 解释

    对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程, 而ps命令(Process Status)就是最基本同时也是非常强大的进程查看命令. 使用该命令 可以确定有哪些进程正在运 ...

  4. 万众期待的kintone开发账号免费开放申请啦!

    亲爱的小伙伴们,等了很久很久的kintone开发账号终于可以免费申请使用了! 有人想问了,什么是kintone? kintone是指无需开发知识,即可根据公司业务轻松创建系统的Cybozu的云服务. ...

  5. 使用Xpath爬虫库下载诗词名句网的史书典籍类所有文章。

    # 需要的库 from lxml import etree import requests # 请求头 headers = { 'User-Agent': 'Mozilla/5.0 (Windows ...

  6. everything in javascript can act like an object,

  7. dimensionality reduction动机---visualization(将数据可视化帮助我们更好地理解数据)

    如果我们能更好地理解我们的数据,这样会对我们开发高效的机器学习算法有作用,将数据可视化(将数据画出来能更好地理解数据)出来将会对我们理解我们的数据起到很大的帮助. 高维数据如何进行显示 GDP: gr ...

  8. 6、Python基础语法

    一.Python输出 print是python输出的关键字,默认是输出内容后换行. 如果不想换行,需要在变量末尾加上 end="" . a = 'hello' b = 'world ...

  9. 为什么管理人员都喜欢用Visio画图

    一.形状数据一体化 这是管理者最喜欢的功能了,这也Visio的最核心的功能: 操作如下: 例如流程中的步骤.开始日期或结束日期.成本.设备部件等.数字.图标.颜色.标志和进度条等图形有助于快速方便地浏 ...

  10. [Codeforces Educational Round 71]Div. 2

    总结 手速场...像我这种没手速的就直接炸了... 辣鸡 E 题交互,少打了个 ? 调了半个小时... 到最后没时间 G 题题都没看就结束了...结果早上起来被告知是阿狸的打字机...看了看题一毛一样 ...