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; } }

最新文章

  1. Visual Studio 2015 各版本对比及下载地址
  2. XUtils3 的 环境搭建
  3. 搜索引擎系列 ---lucene简介 创建索引和搜索初步
  4. 我的ORM之一 -- 查询
  5. 【代码笔记】iOS-利用图片序列创建动态图片效果
  6. Oracle数据库安装及配置(一)
  7. Android 线程模型
  8. smarty练习: 设置试题及打印试卷
  9. 传智播客C/C++学院年薪24-50万招聘C/C++讲师
  10. 2.14. 删除托管对象(Core Data 应用程序实践指南)
  11. docker~写个容器启动的bash脚本
  12. JS模块化-requireJS
  13. robotframework文本类型的下拉框
  14. JWT( JSON Web Token)
  15. SSHD启动失败,错误码255
  16. ext__给grid Panel设置绑定事件
  17. 很好的sql多表
  18. vim 撤销 回退操作
  19. IntelliJ IDEA的配置优化
  20. 推荐7个GitHub上不错的Python机器学习项目

热门文章

  1. maven学习笔记三(依赖特性,作用域)
  2. struct并不报错
  3. sqlserver 智能提示插件
  4. Luogu P2280/ACAG 0x03-1 激光炸弹
  5. java基础(14)---修饰符
  6. 小程序登录及AppSecret(小程序密钥)
  7. JS中的this、apply、call、bind(经典面试题)
  8. java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
  9. 2、Python的IDE之PyCharm的使用
  10. (转)接口测试工具Postman使用实践