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 ...
随机推荐
- 【微信小程序】开发实战 之 「视图层」WXML & WXSS 全解析
在<微信小程序开发实战 之 「配置项」与「逻辑层」>中我们详细阐述了小程序开发的程序和页面各配置项与逻辑层的基础知识.下面我们继续解析小程序开发框架中的「视图层」部分.学习完这两篇文章的基 ...
- Ubuntu安装MDK
1 环境部署 [x] Ubuntu 18.04 [x] Wine 3.0.4 1.0 查看CPU信息 lscpu 序号 属性 描述 1 架构 x86_64 2 CPU 运行模式 32-bit, 64- ...
- mysql性能优化随笔
mysql性能优化是一个很大的命题,这里只记录一下近期的一些小经验. 曾经以为看了点create table时加index的语法就觉得自己知道怎么做mysql优化了,后来又看了点介绍mysql索引底层 ...
- 使用angularJS接收json数据并进行数据的显示
1.引入JS <script type="text/javascript" src="../plugins/angularjs/angular.min.js&quo ...
- WIN10安装64位JDK10.0.2详细完整教程(图文)
1.下载JDK 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 1)如下图,点击红色箭头处: 2)如下图 ...
- 【Spring 整合篇】整合SpringMVC+Mybatis(一)
首先,创建Maven Project,packaging为war,修改pom.xml. <properties> <!-- JDK版本 --> <java.version ...
- Tcp与Http
TCP协议对应传输层,而HTTP协议对应应用层.Http协议是建立在TCP协议基础之上的.当浏览器需要从服务器获取网页数据的时候,会发出一次Http请求.Http会通过TCP建立起一个到服务器的连接通 ...
- tornado中命名路由及反向解析使用
一. 命名路由: 通常路由写法为[ (r'/' , Handler), ... ] 以上路由写法无法实现命名, 使用命名路由需借助tornado提供的方法, 如下: [ tornado.web.url ...
- [NOIP2015]联合权值
1.题面 2.总结 第一次回忆一下当年的题目.但是这道题已经做烂了,只是看还记得树遍历会写么. 然后我写了一下,有点费劲,交上去之后只有70,比较尴尬,看了下去年5月写的代码,发现完全不是一个感觉啊. ...
- mac 下使用shell 命令 jq 解析json
官网 https://stedolan.github.io/jq/download/ 安装 brew install jq 创建json文件,file.json { , "msg" ...