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 ...
随机推荐
- springboot使用vue打包过的页面资源
(一)webpack打包 如果在vue基于webpack的,build打包后得到的是如下的资源文件: webstorm中提示如下: 这个大致的意思就是这边的文件需要放在http服务器上访问,如果直接打 ...
- nginx反向代理和负载均衡的基本配置
一.反向代理的基本配置 在原本默认的nginx上修改server配置 server { listen 2222;#监听请求端口 server_name 192.168.100.3;#监听请求地址,ng ...
- CentOS7 配置 SSH监听多个端口方法
一.修改ssh默认端口,防止暴力破解,让系统安全多一点点: i. 在配置文件/etc/ssh/sshd_config文件中修改 Port #AddressFamily any #ListenAddre ...
- python简单日志处理
简单日志处理 import datetime import re logfile='''58.61.164.141 - - [22/Feb/2010:09:51:46 +0800] "GET ...
- 19、FTP服务器
FTP (File Transfer Protocol) 文件传输协议的简称.主要用跨网络.跨平台的文件 传输. FTP 支持两种工作工作模式:主动模式.被动模式. 主动模式: 客户端使用 ...
- CSS的四种基本选择器和四种高级选择器
做个快乐的搬运工:https://blog.csdn.net/DYD850804/article/details/80997251
- c# 第15节 StringBuilder
本节内容: 1:StringBuilder 2:内容总结 1:StringBuilder 实例: 2:内容总结 项目:
- 201871020225-牟星源《面向对象程序设计(java)》第十二周学习总结
201871020225-牟星源<面向对象程序设计(java)>第十二周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ ...
- uiautomator 调试例子
package com.bing.cn; import com.android.uiautomator.testrunner.UiAutomatorTestCase; public class Dem ...
- zz姚班天才少年鬲融凭非凸优化研究成果获得斯隆研究奖
姚班天才少年鬲融凭非凸优化研究成果获得斯隆研究奖 近日,美国艾尔弗·斯隆基金会(The Alfred P. Sloan Foundation)公布了2019年斯隆研究奖(Sloan Research ...