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. 无法将“ng”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。 通用解决方案

    1.找到你安装的路径 以@angular/cli 为例 (找到 ng.cmd 这个指令的具体位置) 2. 右键 这台电脑 添加路径到 系统变量的 Path中, 如下图 3.关闭所有的 cmd,并重新打 ...

  2. Linux指令(时间日期类)

    date指令-显示当前日期 基本语法: 1)date (功能描述:显示当前时间) 2)date +%Y (功能描述:显示当前年份) 3)date +%m (功能描述:显示当前月份) 4)date +% ...

  3. 云计算与大数据实验:Hbase shell操作用户表

    [实验目的] 1)了解hbase服务 2)学会hbase shell命令操作用户表 [实验原理] HBase是一个分布式的.面向列的开源数据库,它利用Hadoop HDFS作为其文件存储系统,利用Ha ...

  4. linux /bin/bash^M: bad interpreter的解决办法

    linux下执行shell脚本时报错:-bash: ./a.sh: /bin/bash^M: bad interpreter: No such file or directory. 原因是window ...

  5. kill详解

    一. 终止进程的工具kill .killall.pkill.xkill 终止一个进程或终止一个正在运行的程序,一般是通过kill .killall.pkill.xkill 等进行.比如一个程序已经死掉 ...

  6. The Sum of the k-th Powers(Educational Codeforces Round 7F+拉格朗日插值法)

    题目链接 传送门 题面 题意 给你\(n,k\),要你求\(\sum\limits_{i=1}^{n}i^k\)的值. 思路 根据数学知识或者说题目提示可知\(\sum\limits_{i=1}^{n ...

  7. python变量选中后高亮显示

    file>settings>editor>color scheme>general>code>identifier under caret>backgroun ...

  8. LG1036

    当我们看到这道题的时候,我们不仅大吼一声,这不就是搜索嘛. 于是搜索两大刀!搜索目标和搜索状态! 搜索目标:求选数的方案,以及他们的和是否为质数. 搜索状态: 1.从后往前分析目标(或从前往后):和是 ...

  9. UFUN函数 UF_ATTR函数(UF_ATTR_cycle )

    UF_initialize(); tag_t ; ; int type=UF_ATTR_any ; ]=""; UF_ATTR_value_t value; //循环读取程序的属性 ...

  10. javascript 百度地图无秘钥(appkey)创建marker标记地图

    创建简单的marker地图不一定需要去百度地图申请key,简单代码实现marker地图,效果如图: html代码如下,代码中的baidu.api.js参考后面的隐藏代码: <!DOCTYPE h ...