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 ...
随机推荐
- Innodb Change Buffer
Change Buffer属于Innodb内存中的一块结构,它主要用来缓存对二级索引数据的修改(insert, update, delete)操作当二级索引不在Buffer pool中的时候,这些写操 ...
- 怎样解决非管理员账户添加Notepad++右键菜单的批处理的问题?
bat脚本如下: @echo off color 1e title 将Notepad++增加到右键菜单(或者去关联) goto :menu :menu cls echo. echo. 1 将Notep ...
- NLP中的预训练语言模型(三)—— XL-Net和Transformer-XL
本篇带来XL-Net和它的基础结构Transformer-XL.在讲解XL-Net之前需要先了解Transformer-XL,Transformer-XL不属于预训练模型范畴,而是Transforme ...
- 笔记6:Django基础
Django-MVT (1)查看python版本号: python -m django --version (2) 创建Django项目 django-admin startproject mysit ...
- 201871010134-周英杰《面向对象程序设计(java)》第十六周学习总结
项目 内容 <面向对象程序设计(java)> https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.com/ ...
- django学习-安装、创建应用、编写视图
快速安装指南 py -3 -m pip install django >>> import django >>> django.get_version() '2.2 ...
- 实战接口开发:python + flask + mysql + redis(根据反馈,持续细化更新。。。)
前言 自动化已经成为测试的必备技能之一了,所以,很多想跳槽的测试朋友都在自学,特别是最实用的接口自动化, 但是很多人因为没有可以练手的项目而苦恼,最终导致缺乏实战经验,其实,完全可以自己开发个简单项目 ...
- 15-numpy笔记-莫烦pandas-3
代码 import pandas as pd import numpy as np dates = pd.date_range('20130101', periods=6) df=pd.DataFra ...
- shell的使用技巧
推荐使用的远程连接软件以及vi编辑器的基本使用 简介:远程连接软件 与 vi命令的基本使用 (1)软件: CRT 已经下载好的压缩包 直接双击 点击新建会话 点击下一步 输入主机名 下一步 ...
- [LeetCode] 7. Reverse Integer 翻转整数
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Examp ...