ExportGrid Aspose.Cells.dll
using Aspose.Cells;
using Aspose.Words;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace WebApplication16
{ public partial class WebForm1 : System.Web.UI.Page
{ public void ExportWord()
{
string filePath = Server.MapPath("~/Template.doc");
string filePath1 = Server.MapPath("~/Template1.doc");
//预先生成数据
List<Student> studentData = new List<Student>();
for (int i = ; i < ; i++)
{
studentData.Add(new Student()
{
name = "学生" + i.ToString("D3"),
schoolName = "某某中学",
num = i,
score = i
});
}
//加载word模板。
Aspose.Words.Document doc = null;
try
{
doc = new Aspose.Words.Document();
}
catch (Exception ex)
{ }
Aspose.Words.DocumentBuilder docWriter = new Aspose.Words.DocumentBuilder(doc);
docWriter.StartTable();
double[] colWidth = new double[] { , , , };
string[] colName = new string[] { "编号", "姓名", "分数", "学校" };
int pageSize = ;
for (int i = , j = studentData.Count; i < j; i++)
{
if (i == )
{ }
if (pageSize== )
{
//word页刚开始,一个表格的开始,要插入一个表头
docWriter.InsertBreak(Aspose.Words.BreakType.ParagraphBreak);
//docWriter.StartTable();
AsposeCreateCell(docWriter, colWidth[], colName[]);
AsposeCreateCell(docWriter, colWidth[], colName[]);
AsposeCreateCell(docWriter, colWidth[], colName[]);
AsposeCreateCell(docWriter, colWidth[], colName[]);
docWriter.EndRow();
//docWriter.EndTable();
}
//else if (pageSize == 30)//经过测算,每页word中可以放置30行
//{
// //结束第一个表格,插入分栏符号,并开始另一个表格
// docWriter.EndTable();
// docWriter.InsertBreak(Aspose.Words.BreakType.ColumnBreak);
// docWriter.InsertBreak(Aspose.Words.BreakType.ParagraphBreak);
// docWriter.StartTable();
// AsposeCreateCell(docWriter, colWidth[0], colName[0]);
// AsposeCreateCell(docWriter, colWidth[1], colName[1]);
// AsposeCreateCell(docWriter, colWidth[2], colName[2]);
// AsposeCreateCell(docWriter, colWidth[3], colName[3]);
// docWriter.EndRow();
//}
//else if (pageSize == 60)//word分栏为2栏,那么一页word可以放60行数据
//{
// //一页word完毕,关闭表格,并绘制下一页的表头。
// docWriter.EndTable();
// docWriter.InsertBreak(Aspose.Words.BreakType.PageBreak);
// docWriter.InsertBreak(Aspose.Words.BreakType.ParagraphBreak);
// docWriter.StartTable();
// AsposeCreateCell(docWriter, colWidth[0], colName[0]);
// AsposeCreateCell(docWriter, colWidth[1], colName[1]);
// AsposeCreateCell(docWriter, colWidth[2], colName[2]);
// AsposeCreateCell(docWriter, colWidth[3], colName[3]);
// docWriter.EndRow();
// pageSize = 0;
//}
pageSize++;
//创建内容
AsposeCreateCell(docWriter, colWidth[], studentData[i].num.ToString());
AsposeCreateCell(docWriter, colWidth[], studentData[i].name);
AsposeCreateCell(docWriter, colWidth[], studentData[i].score.ToString());
AsposeCreateCell(docWriter, colWidth[], studentData[i].schoolName+"_"+i);
docWriter.EndRow();
}//end for
docWriter.EndTable();
//保存文件
doc.Save(filePath1, Aspose.Words.SaveFormat.Doc); }
public void AsposeCreateCell(Aspose.Words.DocumentBuilder builder, double width, string text)
{ builder.InsertCell();
builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.Single;
builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
builder.CellFormat.Width = width;//单元格的宽度
builder.CellFormat.LeftPadding = ;//单元格的左内边距
builder.CellFormat.RightPadding = ;//单元格的右内边距
builder.RowFormat.Height = ;//行高
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;//垂直居中对齐
builder.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Center;//水平居中对齐
builder.Write(text);
}
protected virtual void ExportGrid(string[] Columns, string title, System.Data.DataTable table, ArrayList ignorColList, bool showHeader)
{ Workbook workbook = new Workbook(); //工作簿
Worksheet sheet = workbook.Worksheets[]; //工作表
sheet.AutoFitColumns();
Cells cells = sheet.Cells;//单元格
Aspose.Cells.Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增样式
styleTitle.HorizontalAlignment = TextAlignmentType.Center;//文字居中
styleTitle.Font.Name = "宋体";//文字字体
styleTitle.Font.Size = ;//文字大小
styleTitle.Font.IsBold = false;//粗体
//样式2
Aspose.Cells.Style style2 = workbook.Styles[workbook.Styles.Add()];//新增样式
style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style2.Font.Name = "宋体";//文字字体
style2.Font.Size = ;//文字大小
style2.Font.IsBold = false;//粗体
style2.IsTextWrapped = true;//单元格内容自动换行
style2.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style2.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style2.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style2.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
Aspose.Cells.Style style3 = workbook.Styles[workbook.Styles.Add()];//新增样式
style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style3.Font.Name = "宋体";//文字字体
style3.Font.Size = ;//文字大小
style3.Borders[Aspose.Cells.BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style3.Borders[Aspose.Cells.BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style3.Borders[Aspose.Cells.BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style3.Borders[Aspose.Cells.BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
if (!string.IsNullOrEmpty(title))
{
int i = Columns.Length;
if (ignorColList != null)
{
i = i - ignorColList.Count;
}
cells.Merge(, , , i);//合并单元格
cells[, ].PutValue(title);//填写内容
cells[, ].SetStyle(styleTitle);
}
int start = string.IsNullOrEmpty(title) ? : ;
int j = ;
if (showHeader)
{
for (var i = ; i < Columns.Length; i++)
{
var c = Columns[i];
if (ignorColList != null && ignorColList.Contains(c))
{
continue;
}
cells[start, j].PutValue(c);
cells[start, j].SetStyle(style2);
j++;
}
}
for (var q = ; q < table.Rows.Count; q++)
{
j = ;
var row = table.Rows[q];
for (var i = ; i < Columns.Length; i++)
{
var c = Columns[i];
if (ignorColList != null && ignorColList.Contains(c))
{
continue;
}
cells[start + + q, j].PutValue(row[c]);
cells[start + + q, j].SetStyle(style3);
cells.SetRowHeight(start + + q, );
j++;
}
} workbook.Save(string.Format("report.xls"), Aspose.Cells.SaveType.OpenInExcel, Aspose.Cells.FileFormatType.Excel2003, Response);
Response.Flush();
Response.End();
}
protected void Page_Load(object sender, EventArgs e)
{
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("id2", typeof(string));
table.Columns.Add("name2", typeof(string)); for (int i = ; i < ; i++)
{
System.Data.DataRow dr = table.NewRow();
dr["id2"] = "id2_" + i;
dr["name2"] = "name2_" + i;
table.Rows.Add(dr);
} string[] columns = { "id2", "name2" }; ExportWord();
//ExportGrid(columns, "柯相彬表格",table,null, true);
Response.Write("ni mei de");
}
}
}
ExportGrid Aspose.Cells.dll的更多相关文章
- C# WinForm 导出导入Excel/Doc 完整实例教程[使用Aspose.Cells.dll]
[csharp] view plain copy 1.添加引用: Aspose.Cells.dll(我们就叫工具包吧,可以从网上下载.关于它的操作我在“Aspose.Cells操作说明 中文版 下载 ...
- C# WinForm使用Aspose.Cells.dll 导出导入Excel/Doc 完整实例教程
1.添加引用: Aspose.Cells.dll(我们就叫工具包吧,可以从网上下载.关于它的操作我在“Aspose.Cells操作说明 中文版 下载 Aspose C# 导出Excel 实例”一文中的 ...
- Aspose.Cells.dll引用导入导出Excel
Aspose.Cells 导入导出EXCEL 文章出处:http://hi.baidu.com/leilongbing/item/c11467e1819e5417595dd8c1 修改样式 ...
- Aspose.Cells.dll操作execl
附件:Aspose.Cells.dll 1.创建execl(不需要服务器或者客户端安装office) public void DCExexl(DataTable dt) { Workbook wb ...
- C# Aspose.Cells.dll Excel操作总结
简介 Aspose.Cells是一款功能强大的 Excel 文档处理和转换控件,不依赖 Microsoft Excel 环境,支持所有 Excel 格式类型的操作. 下载 Aspose.Cells.d ...
- C# 读写Excel的一些方法,Aspose.Cells.dll
需求:现有2个Excel,一个7000,一个20W,7000在20W是完全存在的.现要分离20W的,拆分成19W3和7000. 条件:两个Excel都有“登录名”,然后用“登录名”去关联2个Excel ...
- C# 利用Aspose.Cells .dll将本地excel文档转化成pdf(完美破解版 无水印 无中文乱码)
Aspose.Cells .dll下载 http://pan.baidu.com/s/1slRENLF并引用 C#代码 using System; using System.Collections. ...
- Aspose.Cells.dll的用法
public void OutExcel() { #region WorkbookDesigner designer = new WorkbookDesigner(); Worksheet sheet ...
- Aspose Cells dll 实现数据简单下载
Workbook workbook = new Workbook(); //工作簿 Worksheet sheet = workbook.Worksheets[ ...
随机推荐
- centos7.4上安装python3环境的坑
前言:为了将爬虫项目布置到服务器上,才有了今天这一下午的坑,必须记录 不要动现有的python2环境!不要动现有的python2环境!不要动现有的python2环境! 解压 tar -xvf Pyth ...
- java集合: LinkedList源码浅析
LinkedList 数据结构是双向链表,插入删除比较方便.LinkedList 是线程不安全的,允许元素为null . 构造函数: 构造函数是空的. /** * Constructs an emp ...
- 把图片上的文字转换成word文字?
转换后的文字不是很如意,但是免费方便. 1.打开Office办公软件自带的OneNote工具.随便新建一个笔记页面,以方便我们接下来的操作. 2.插入图片.在菜单栏里点击[插入],选择插入[图片],找 ...
- vue confirm确认
this.$confirm('您确定删除吗?').then(_ => { do something ... (确认) }).catch(_ => { do something ... (取 ...
- Openstack 集群,及常用服务的 高可用 haproxy配置
一.介绍 配置文件位置(yum 安装):/etc/haproxy/haproxy.cfg 全局配置 #------------------------------------------------- ...
- 如何利用FPGA进行时序分析设计
FPGA(Field-Programmable Gate Array),即现场可编程门阵列,它是作为专用集成电路(ASIC)领域中的一种半定制电路而出现的,既解决了定制电路的不足,又克服了原有可编程器 ...
- POJ-3278.CatchThatCow(数字BFS最短路输出)
本题大意:一个农夫和一头牛在一个数轴上,牛不动,农夫每次可使自己的坐标 +1 , -1, *2 ,问最小需要多少次农夫与牛坐标相等. 本题思路:最短路,BFS. 本题代码: #include < ...
- HDU 1542 Atlantis(线段树面积并)
描述 There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. S ...
- [Java学习]面向对象-抽象类;接口
抽象类 语法 public abstract class A{ } 定义 抽象类无法实例化.但抽象类有构造方法,在子类创建对象时用. 抽象类中可以定义抽象方法public abstract void ...
- 13-算法训练 P0505
算法训练 P0505 时间限制:1.0s 内存限制:256.0MB 一个整数n的阶乘可以写成n!,它表示从1到n这n个整数的乘积.阶乘的增长速度非常快,例如,13!就已经比较大了,已 ...