aspose.cells导出Demo
/// <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的更多相关文章
- Aspose.Cells导出Excel(1)
利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- Aspose.Cells导出Excel(2)
DataTable dtTitle = ds.Tables[]; DataTable dtDetail = ds.Tables[]; int columns = dtTitle.Columns.Cou ...
- C#+Aspose.Cells 导出Excel及设置样式 (Webform/Winform)
在项目中用到,特此记录下来,Aspose.Cells 不依赖机器装没有装EXCEL都可以导出,很方便.具体可以参考其他 http://www.aspose.com/docs/display/cells ...
- Asp.net & Aspose.cells 导出
protected void btnExport_Click(object sender, EventArgs e) { DataTable tbBooks = (DataTable)Session[ ...
- 利用Aspose.Cells导出Datatable数据
面对一些的格式各样的到处数据的要求,自学了一点 Aspose.Cells中操作Excel知识,如下代码: /// <summary> /// DataTable导出Excel /// &l ...
- C# 使用Aspose.Cells 导出Excel
今天在工作中碰到同事用了一种新型的方式导入excel,在此做个学习记录. 插件:Aspose.Cells 第一步:准备好导出的模板,例子: C#代码: #region 验证数据 if (model = ...
- Aspose.Cells 导出 excel
Aspose.Cells.Workbook book = new Aspose.Cells.Workbook(); Aspose.Cells.Worksheet sheet = book.Worksh ...
- aspose.Cells 导出Excel
aspose aspse.Cells可以操作Excel,且不依赖于系统环境. 使用模板,通过绑定输出数据源 这种适合于对格式没有特别要求的,直接绑定数据源即可.和数据绑定控件差不多. Workbook ...
随机推荐
- JavaWeb项目 IDEA+Tomcat+Nginx 部署流程
转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/11375100.html 一:IDEA Maven项目打包 1.修改打包方式 在maven项目的pom文件中, ...
- Linux7/Centos7用户密码安全
当Linux7/Centos7的用户root密码常用如下方式找回密码: 第一步:按e键进入内核启动页面如下: 第二步:在linux16一行LANG=zh_CN.UTF-8后面加rd.break con ...
- E09【餐厅】Can I have the bill,please?
核心句型: Can I have the bill ,please? 请给我账单,好吗? 场景对话: A:Excuse me. Can I have the bill ,please? 你好,请给我账 ...
- centos用手机号无法登入安全狗的解决方法
前面我们安装好了安全狗,需要加服务器加入服云中,通常用sdcloud –u 用户名就可以,但如果是手机号的话就可能无法登陆,我们用sdcloud -h命令查看帮助,如下图所示 我们看到输入账号可以用- ...
- SpringBoot使用@Value来获取properties的值
今天在项目中想使用@Value来获取Springboot中properties中属性值.场景:定义了一个工具类,想要获取一些配置参数,使用了@value来获取,但是死活也获取不到.如何解决:在使用这个 ...
- Java高级-反射
1.如何创建Class的实例 1.1过程:源文件经过编译(javac.exe)以后,得到一个或者多个.class文件..class文件经过运行(java.exe)这步,就需要进行类的加载(通过JVM的 ...
- 微信小程序 - 双线程模型
小程序的双线程模型 官方文档给出的双线程模型: 小程序的宿主环境 微信客户端提供双线程去执行wxml,wxss,js文件. 双线程模型 1.上述的渲染层上面运行着wxml文件,渲染层使用是的webvi ...
- Mysql 视图&事务&触发器
参考资料 一.视图 视图的含义: 视图是一个虚拟表,是从数据库中一个或者多个表中导出来的表. 1.创建视图 #语法:CREATE VIEW 视图名称 AS SQL语句 create view teac ...
- 个人网站 & 博客
www.ykmimi.com (测试使用) http://www.implements.fun/ (测试使用) http://www.java-developer.cn/ (测试使用,预备论坛) ...
- [RN] React-Native中Array渲染的优化
React-Native中Array渲染的优化 例如用Push加进去的数据: constructor(props){ super(props); this.state = { b ...