/// <summary>
/// 导出excel
/// </summary>
/// <param name="list"></param>
private void ExportExcel(IList<CV_SaaS_POM_ProductionOrder> list)
{
try
{
SaveFileDialog Dialog = new SaveFileDialog();
Dialog.Filter = "Excel文件(*.xlsx)|*.xlsx|Excel文件(*.xls)|*.xls";
Dialog.FileName = "SAP生产工单_" + DateTime.Now.ToString("MMdd") + ".xlsx";
if (Dialog.ShowDialog() == DialogResult.OK)
{
Workbook workbook = new Workbook(); //工作簿
Worksheet sheet = workbook.Worksheets[]; //工作表
Cells cells = sheet.Cells;//单元格 #region 文字样式
Style style = new Style();
style.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style.VerticalAlignment = TextAlignmentType.Center;
style.Font.Name = "宋体";//文字字体
style.Font.Size = ; //
Style style1 = new Style();
style1.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style1.VerticalAlignment = TextAlignmentType.Center;
style1.Font.Name = "宋体";//文字字体
style1.Font.Size = ;
style1.Custom = "MM/dd";
//
Style style2 = new Style();
style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style2.VerticalAlignment = TextAlignmentType.Center;
style2.Font.Name = "宋体";//文字字体
style2.Font.Size = ;
style2.Custom = "yyyy/mm/dd";
#endregion
//生成行2 列名行
cells[, ].PutValue("SAP工单号");
cells[, ].SetStyle(style);
cells[, ].PutValue("物料编码");
cells[, ].SetStyle(style);
cells[, ].PutValue("物料描述");
cells[, ].SetStyle(style);
cells[, ].PutValue("BOM版本");
cells[, ].SetStyle(style);
cells[, ].PutValue("工单组件");
cells[, ].SetStyle(style);
cells[, ].PutValue("工单类型");
cells[, ].SetStyle(style);
cells[, ].PutValue("工艺路径");
cells[, ].SetStyle(style);
cells[, ].PutValue("工单数量");
cells[, ].SetStyle(style);
cells[, ].PutValue("计划开始时间");
cells[, ].SetStyle(style);
cells[, ].PutValue("计划完成时间(交期)");
cells[, ].SetStyle(style);
//根据当前日期生成一年的日期列
int cellIndex = ; DateTime today = Convert.ToDateTime(DateTime.Now.ToString(@"yyyy-MM-dd"));
DateTime endday = today.AddMonths();
for (; today < endday; today = today.AddDays())
{
cellIndex++;
cells[, cellIndex].PutValue(today);
cells[, cellIndex].SetStyle(style1);//定义后续两个月日期的格式
}
//设置下拉列表框格式
ValidationCollection validations = sheet.Validations;
Validation validation = validations[validations.Add()];
validation.Type = Aspose.Cells.ValidationType.List;
validation.Operator = OperatorType.None;
validation.InCellDropDown = true;
validation.Formula1 = GetOrderFamilyName();//逗号分隔字符串
validation.ShowError = true;
validation.AlertStyle = ValidationAlertType.Stop;
validation.ErrorTitle = "Error";
validation.ErrorMessage = "请选择工单组件";
CellArea area;
area.StartRow = ;
area.EndRow = ;
area.StartColumn = ;
area.EndColumn = ;
validation.AreaList.Add(area);
//写入工单数据
CV_SaaS_POM_ProductionOrder order = null;
for (int i = ; i < list.Count; i++)
{
order = list[i];
cells[i + , ].PutValue(order.ProductionOrderNO);
cells[i + , ].SetStyle(style);
cells[i + , ].PutValue(order.DefID);
cells[i + , ].SetStyle(style);
cells[i + , ].PutValue(order.DefName);
cells[i + , ].SetStyle(style);
cells[i + , ].PutValue("");
cells[i + , ].SetStyle(style);
cells[i + , ].PutValue(order.OrderGroup);
cells[i + , ].SetStyle(style);
cells[i + , ].PutValue(order.OderType);
cells[i + , ].SetStyle(style);
cells[i + , ].PutValue(order.PPRCode);
cells[i + , ].SetStyle(style);
cells[i + , ].PutValue(order.Quantity - order.AssignedQuantity);
cells[i + , ].SetStyle(style);
cells[i + , ].PutValue(order.StartTime);
cells[i + , ].SetStyle(style2);
cells[i + , ].PutValue(order.EndTime);
cells[i + , ].SetStyle(style2);
} int columnCount = cells.MaxColumn; //获取表页的最大列数
int rowCount = cells.MaxRow; //获取表页的最大行数
for (int col = ; col < columnCount; col++)
{
sheet.AutoFitColumn(col, , rowCount);
}
for (int col = ; col < columnCount; col++)
{
cells.SetColumnWidthPixel(col, cells.GetColumnWidthPixel(col) + );
} workbook.Save(Dialog.FileName);
MessageBox.Show("导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception exception)
{
SaMessageBox.ShowError(exception);
} }

aspose.cells导出Demo的更多相关文章

  1. Aspose.Cells导出Excel(1)

    利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...

  2. C#使用Aspose.Cells导出Excel简单实现

    首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...

  3. Aspose.Cells导出Excel(2)

    DataTable dtTitle = ds.Tables[]; DataTable dtDetail = ds.Tables[]; int columns = dtTitle.Columns.Cou ...

  4. C#+Aspose.Cells 导出Excel及设置样式 (Webform/Winform)

    在项目中用到,特此记录下来,Aspose.Cells 不依赖机器装没有装EXCEL都可以导出,很方便.具体可以参考其他 http://www.aspose.com/docs/display/cells ...

  5. Asp.net & Aspose.cells 导出

    protected void btnExport_Click(object sender, EventArgs e) { DataTable tbBooks = (DataTable)Session[ ...

  6. 利用Aspose.Cells导出Datatable数据

    面对一些的格式各样的到处数据的要求,自学了一点 Aspose.Cells中操作Excel知识,如下代码: /// <summary> /// DataTable导出Excel /// &l ...

  7. C# 使用Aspose.Cells 导出Excel

    今天在工作中碰到同事用了一种新型的方式导入excel,在此做个学习记录. 插件:Aspose.Cells 第一步:准备好导出的模板,例子: C#代码: #region 验证数据 if (model = ...

  8. Aspose.Cells 导出 excel

    Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(); Aspose.Cells.Worksheet sheet = book.Worksh ...

  9. aspose.Cells 导出Excel

    aspose aspse.Cells可以操作Excel,且不依赖于系统环境. 使用模板,通过绑定输出数据源 这种适合于对格式没有特别要求的,直接绑定数据源即可.和数据绑定控件差不多. Workbook ...

随机推荐

  1. CnetOS6.7编译安装MariaDB

    --安装所需软件包 [root@localhost mariadb-10.1.14]# yum install bison bison-devel ncurses libxml2 libxml2-de ...

  2. JDK8在接口中引入的default

    default关键字介绍 default是在java8中引入的关键字,也可称为Virtual extension methods——虚拟扩展方法.是指,在接口内部包含了一些默认的方法实现(也就是接口中 ...

  3. sqlalchemy(2)

    orm介绍 orm英文全称object relational mapping,就是对象映射关系程序,简单来说我们类似python这种面向对象的程序来说一切皆对象,但是我们使用的数据库却都是关系型的,为 ...

  4. 201871010136-赵艳强《面向对象程序设计(java)》第六,七周学习总结

            201871010136-赵艳强<面向对象程序设计(java)>第六七周学习总结 项目 内容 这个作业属于哪个课程 <任课教师博客主页链接> https://w ...

  5. 逆向工程文件example完美结合使用PageHelper分页插件及分页不成功原因

    原生的mybatis需要手写sql语句,项目数据库表多了之后,可以让你写sql语句写到手软,于是mybatis官方提供了mybatis-generator:mybatis逆向工程代码生成工具,用于简化 ...

  6. ibus mozc 日文输入法

    1)安装:     a) https://qiita.com/TANATY/items/8c0c17d54ab81fd1b491 b) ibus-setup 2)使用: open a console, ...

  7. 第一章、Go安装与Goland破解

    1.1.安装Go 安装包下载:https://studygolang.com/dl 一直点下一步安装即可,默认是安装在“C:\Go”,如果自己换成其它目录则需添加环境变量. 1.2.Liteide l ...

  8. ASP.NET CoreMVC 中的控制器

    Controller in ASP.NET Core MVC 在本节中,我们将讨论 Controller 是什么以及它在 ASP.NET Core MVC 中的作用. Fiddler 需要大家提前装一 ...

  9. [LeetCode] 208. Implement Trie (Prefix Tree) 实现字典树(前缀树)

    Implement a trie with insert, search, and startsWith methods. Example: Trie trie = new Trie(); trie. ...

  10. [LeetCode] 91. Decode Ways 解码方法

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...