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. ss-套接字监控工具

    ss(Socket Statistics) - another utility to investigate sockets(研究套接字的另一个实用程序,原先的是netstat) ss用于转储套接字统 ...

  2. OracleXETNSListener无法启动或启动停止

    一.修改配置文件 1. 打开oracle的安装目录,找到下述文件"listener.ora" 2. 用文本编辑器打开“listener.ora”文件,找到下图所示位置:(HOST ...

  3. session和cookie的区别和联系详解,Cookie Session相关看这篇就够了。

    本文转自:91博客:原文地址:http://www.9191boke.com/199015867.html 有一朋友做面试官的时候,曾经问过很多朋友这个问题: Cookie 和 Session 有什么 ...

  4. 执行chmod -R 777 / 补救

    执行后千万不要退出当前窗口!!! 在自己的虚拟机上设置某个站的权限的时候,原来应该是chmod -R 777 ./*  结果少按了个点,执行了chmod -R 777 /*  因为执行时间超出自己的预 ...

  5. 业余时间折腾了个微信小程序版本的街机游戏模拟器(吾爱街机),8090后的童年回忆,欢迎大家体验

    好多年没来博客园了,有段时间想玩街机游戏,发现都需要下载安装,现在小程序这么流行,是不是可以集成到小程序里(无需下载,在线玩),出于这想法,就业余时间折腾了下,分享给大家,偶尔可以回味畅玩下. 中间遇 ...

  6. java 计算两个日期间的所有日期

    public static void main(String[] args) { Calendar start = Calendar.getInstance(); start.set(2014, 6, ...

  7. Mysql【第二课】

  8. 【云栖社区002-二分估值法】要求不用数学库,求 sqrt (2)精确到小数点后10位(Java版)

    如题 初步审题的时候,想到的是暴力搜索:初步设置一个合法的种子,依次按照1e-2,1e-3,1e-4,1e-5,1e-6 , 1e-7...暴力搜索,额,就是太麻烦了. 打比赛搜索写多了,一看见题目就 ...

  9. netstat -an unix socket 会阻塞吗

    [lyd@localhost ~]$ netstat -an | grep "SOFO"unix 2 [ ACC ] SEQPACKET LISTENING 86308 @*MY- ...

  10. iptables 通用语句

    iptables -t filter -nvL --line-number | grep destination -t :  指定表 {fillter|nat|mangle|raw} -v : 显示详 ...