/// <summary>
/// 20141118
/// Geovin Du
/// Aspose.Words创建表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
try
{
//实例化一个新的Word Document //也可以在Aspose.Words.Document doc = newAspose.Words.Document(path)中加path参数, //此path指向你设计好的Word模板路径
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
//设置单元格内容对齐方式
builder.ParagraphFormat.Alignment = ParagraphAlignment.Left; //清除设置
builder.PageSetup.ClearFormatting(); DataTable tbl = new DataTable();// m_db.GetDataTable(sql, m_cn);
tbl.Columns.Add("XZ", typeof(int));
tbl.Columns.Add("ZPPATH", typeof(string));
tbl.Columns.Add("XM", typeof(string));
tbl.Columns.Add("SZDW", typeof(string));
tbl.Columns.Add("DWDH", typeof(string));
tbl.Columns.Add("SJHM", typeof(string));
tbl.Columns.Add("DWYB", typeof(string));
tbl.Columns.Add("DZYJ", typeof(string)); tbl.Rows.Add(1, "", "geovindu", "缔友计算机信息技术有限公司;软件工程师", "82397501", "13824350518", "518003", "463588883@qq.com");
tbl.Rows.Add(2, "", "涂年生","缔创智能工程技术有限公司;网络工程师", "82397502", "13824350518", "518003", "geovindu@qq.com");
tbl.Rows.Add(3, "", "涂聚文", "缔建智能建筑工程有限公司;UI设计师", "82397503", "13824350518", "518003", "463588883@qq.com"); List<string> list = new List<string>(); if (tbl != null && tbl.Rows.Count > 0)
{
//加载小组
for (int i = 0; i < tbl.Rows.Count; i++)
{
if (!list.Contains(tbl.Rows[i]["XZ"].ToString()))
{
list.Add(tbl.Rows[i]["XZ"].ToString());
}
} double imgcellwidth = 85;
double imgcellheight = 120;
double cellwidth = 165;
double cellheight = 18.5; //匹配小组中的学员
builder.StartTable();//开始画Table
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center; // RowAlignment.Center; string xz = string.Empty;
int count = 0;
int rowcount = 0;
for (int n = 0; n < list.Count; n++)
{
xz = list[n];
builder.RowFormat.Height = 20;
//插入Table单元格 builder.InsertCell(); //Table单元格边框线样式
builder.CellFormat.Borders.LineStyle = LineStyle.Single; //Table此单元格宽度
builder.CellFormat.Width = 500; //此单元格中内容垂直对齐方式
builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center; builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None; //字体大小
builder.Font.Size = 11; //是否加粗
builder.Bold = true; //向此单元格中添加内容
builder.Write(xz); //Table行结束
builder.EndRow();
builder.Bold = false;
DataRow[] rows = tbl.Select("xz='" + xz + "'");
for (int i = 0; i < rows.Length; i = i + 2)
{
count++;
rowcount = (count - 1) * 6 + 1 + n;
//第一行
builder.InsertCell();
builder.RowFormat.Height = imgcellheight;
builder.CellFormat.Borders.LineStyle = LineStyle.Single; //合并行单元格
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First; builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
builder.CellFormat.TopPadding = 2;
builder.CellFormat.WrapText = false;
builder.CellFormat.Width = imgcellwidth; if (!string.IsNullOrEmpty(rows[i]["ZPPATH"].ToString()))
{ //向此单元格中插入图片
Shape shape = new Shape(doc, ShapeType.Image);
string url = System.Configuration.ConfigurationManager.AppSettings["UserPhotosSitePath"] + "\\" + rows[i]["ZPPATH"].ToString();
shape.ImageData.SetImage(url);
shape.Width = imgcellwidth - 2;
shape.Height = imgcellheight;
shape.HorizontalAlignment = HorizontalAlignment.Center;
CompositeNode node = shape.ParentNode; //把此图片移动到那个单元格中
builder.MoveToCell(0, rowcount, 0, 0);
builder.InsertNode(shape);
} builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = cellwidth;
builder.Write(rows[i]["XM"].ToString()); // builder.InsertCell();
builder.RowFormat.Height = imgcellheight;
builder.CellFormat.Borders.LineStyle = LineStyle.Single; //合并行单元格
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
builder.CellFormat.Width = imgcellwidth;
if (rows.Length > i + 1)
{
if (!string.IsNullOrEmpty(rows[i + 1]["ZPPATH"].ToString()))
{
Shape shape = new Shape(doc, ShapeType.Image);
string url = System.Configuration.ConfigurationManager.AppSettings["UserPhotosSitePath"] + "\\" + rows[i + 1]["ZPPATH"].ToString();
shape.ImageData.SetImage(url);
shape.Width = imgcellwidth - 2;
shape.Height = imgcellheight;
shape.HorizontalAlignment = HorizontalAlignment.Center;
CompositeNode node = shape.ParentNode;
builder.MoveToCell(0, rowcount, 2, 0);
builder.InsertNode(shape);
}
}
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = cellwidth;
if (rows.Length > i + 1)
{
builder.Write(rows[i + 1]["XM"].ToString());
}
builder.EndRow(); //第二行
builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = cellwidth;
builder.Write("单位及职务:" + rows[i]["SZDW"].ToString()); builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = cellwidth;
if (rows.Length > i + 1)
{
builder.Write("单位及职务:" + rows[i + 1]["SZDW"].ToString());
}
builder.EndRow(); //第三行
builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = cellwidth;
builder.Write("单位电话:" + rows[i]["DWDH"].ToString()); builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = cellwidth;
if (rows.Length > i + 1)
{
builder.Write("单位电话:" + rows[i + 1]["DWDH"].ToString());
}
builder.EndRow(); //第四行
builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = cellwidth;
builder.Write("手机:" + rows[i]["SJHM"].ToString()); builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = cellwidth;
if (rows.Length > i + 1)
{
builder.Write("手机:" + rows[i + 1]["SJHM"].ToString());
}
builder.EndRow(); //第五行
builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = cellwidth;
builder.Write("邮编:" + rows[i]["DWYB"].ToString()); builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = cellwidth;
if (rows.Length > i + 1)
{
builder.Write("邮编:" + rows[i + 1]["DWYB"].ToString());
}
builder.EndRow(); //第六行
builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = cellwidth;
builder.Write("Email:" + rows[i]["DZYJ"].ToString()); builder.InsertCell(); //此单元格与上一行单元格合并
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
builder.CellFormat.HorizontalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Width = imgcellwidth;
builder.InsertCell();
builder.RowFormat.Height = cellheight;
builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = cellwidth;
if (rows.Length > i + 1)
{
builder.Write("Email:" + rows[i + 1]["DZYJ"].ToString());
}
builder.EndRow();
}
}
builder.EndTable();
}
string name = "通讯录.doc"; //以下载Word的形式打开Wrod
Aspose.Words.Saving.HtmlSaveOptions options = new Aspose.Words.Saving.HtmlSaveOptions(SaveFormat.Html);
Aspose.Words.Saving.DocSaveOptions docoptions = new Aspose.Words.Saving.DocSaveOptions(SaveFormat.Doc);
//如图所示:Aspose.Words导出带图片人员信息到Word中
//doc.Save(name, Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInWord, Response);
doc.Save(Page.Response, name, ContentDisposition.Attachment, docoptions);//13.3.1 }
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
} }

参考:http://www.cnblogs.com/wuhuacong/archive/2013/02/05/2893191.html

 /// <summary>
/// 20141118
/// Geovin Du
/// Aspose.Words模板操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
try
{
Dictionary<string, string> dictSource = new Dictionary<string, string>();
dictSource.Add("TIS_HANDLE_NO", "T0001");
dictSource.Add("ACCUSE_INDUSTRY", "出租车");
dictSource.Add("ACCUSER_NAME", "张三");
dictSource.Add("ACCUSER_COMPANY", "缔友计算机信息技术有限公司");
dictSource.Add("ACCUSER_ID", "8888888888888");
dictSource.Add("COME_TEL", "82397507");
dictSource.Add("ACCUSER_ADDRESS", "深圳市罗湖区");
dictSource.Add("ACCUSER_ZIPCODE", "518003");
dictSource.Add("TO_DEPARTMENT", "六福");
dictSource.Add("TAXI_DEPT", "资讯科技部");
dictSource.Add("CONTENT", "生活如水,没有薪水发");
dictSource.Add("MEMO", "好来好样的");
dictSource.Add("FOREMANID", "李四");
dictSource.Add("HANDLE_TIME", "2014年11月18日下午6:00");
string templateFile = Server.MapPath("Advice.doc"); //现有模板文件
Aspose.Words.Document doc = new Aspose.Words.Document(templateFile); //使用文本方式替换
foreach (string name in dictSource.Keys)
{
//doc.Range.Replace(name, dictSource[name], true, true); Aspose.Words.Bookmark bookmarkd = doc.Range.Bookmarks[name];//插入的书签名
foreach (KeyValuePair<string, string> kvp in dictSource)
{ if (bookmarkd != null)
{
if (name == kvp.Key)
{
bookmarkd.Text = kvp.Value;
} }
} bookmarkd = doc.Range.Bookmarks[name]; } #region 使用书签替换模式 Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks["ACCUSER_SEX"];
if (bookmark != null)
{
bookmark.Text = "男";
}
bookmark = doc.Range.Bookmarks["ACCUSER_TEL"];
if (bookmark != null)
{
bookmark.Text = "1862029207*";
} #endregion
Aspose.Words.Saving.DocSaveOptions docoptions = new Aspose.Words.Saving.DocSaveOptions(SaveFormat.Doc);
doc.Save(Page.Response, "testAdvice.doc", Aspose.Words.ContentDisposition.Attachment,
docoptions);//Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Doc)
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}

csharp: Aspose.Words create table的更多相关文章

  1. 【SqlServer】empty table and delete table and create table

    1.建表 1 IF object_id (N'表名', N'U') IS NULL CREATE TABLE 表名 ( 2 id INT IDENTITY (1, 1) PRIMARY KEY ,.. ...

  2. mysqldump:Couldn't execute 'show create table `tablename`': Table tablename' doesn't exist (1146)

    遇到了一个错误mysqldump: Couldn't execute 'show create table `CONCURRENCY_ERRORS`': Table INVOICE_OLD.CONCU ...

  3. CREATE TABLE 表名 AS SELECT 语句

    1.新表不存在复制表结构即数据到新表 ? 1 2 create table new_table select * from old_talbe; 这种方法会将old_table中所有的内容都拷贝过来, ...

  4. 【MySQL】Create table 以及 foreign key 删表顺序考究。

    1.以下是直接从数据库导出的建表语句. 1 -- ---------------------------- 2 -- Table structure for files 3 -- ---------- ...

  5. SQL CREATE TABLE 语句\SQL 约束 (Constraints)\SQL NOT NULL 约束\SQL UNIQUE 约束

    CREATE TABLE 语句 CREATE TABLE 语句用于创建数据库中的表. SQL CREATE TABLE 语法 CREATE TABLE 表名称 ( 列名称1 数据类型, 列名称2 数据 ...

  6. MySQL的create table as 与 like区别

    对于MySQL的复制相同表结构方法,有create table as 和create table like 两种,区别是什么呢? ? 1 create table t2 as select * fro ...

  7. MySQL ERROR 1005: Can't create table (errno: 150)的错误解决办法

    在mysql 中建立引用约束的时候会出现MySQL ERROR 1005: Can't create table (errno: 150)的错误信息结果是不能建立 引用约束. 出现问题的大致情况 1. ...

  8. MySQL Create Table创建表

    表的创建命令需要: 表的名称 字段名称 定义每个字段(类型.长度等) 语法 下面是通用的SQL语法用来创建MySQL表: CREATE TABLE table_name (column_name co ...

  9. 【SQL篇章--CREATE TABLE】

    [SQL篇章][SQL语句梳理 :--基于MySQL5.6][已梳理:CREATE TABLE][会坚持完善] SQL : 1. Data Definition Statements: 1.3 CRE ...

随机推荐

  1. 3、TensorFlow基础(一) 设计思想与编程模型

    1.TensorFlow系统架构 如图为TensorFlow的系统架构图: TensorFlow的系统架构图,自底向上分为设备层和网络层.数据操作层.图计算层.API层.应用层,其中设备层和网络层,数 ...

  2. [HNOI2013]题解

    代码在最后 [HNOI2013]比赛 记忆化搜索 把每一位还需要多少分用\(27\)进制压进\(long\) \(long\),\(map\)记忆化一下即可 [HNOI2013]消毒 先考虑在二维平面 ...

  3. 数组和arguments

    Arguments(Array-Like Objects) arguments对象是所有(非箭头)函数中都可用的局部变量 拥有四个属性(按照规范来说只有三个了----caller) arguments ...

  4. pycharm入门的简易使用教程

    1.安装python3.5包: 本人安装到C盘,如下所示: Ps:安装时候,路径一定要添加到环境变量中,安装完,需要更新环境变量,所以要重启电脑 2.安装pycharm 下载相应的安装包,步骤不重复了 ...

  5. Pycharm 导入 Python 包、模块

    1.点击File->settings 2.选择Project Interpreter,点击右边绿色的加号添加包 3.输入你想添加的包名,点击Install Package 4.可以在Pychar ...

  6. U盘拷贝大文件提示文件过大无法拷贝解决方案

    工具: 计算机 windows操作系统 U盘 原因:由于U盘的格式问题导致的,当期的磁盘格式是FAT32类型的,无拷贝过大的文件 方法:接下来修改U盘类型,且不格式化U盘 1.键盘win+R快捷键弹出 ...

  7. mongodb3.4 远程连接认证失败

    mongodb开启或者关闭授权功能时还是挺麻烦的,需要新建服务键入mongod --auth.为了方便,我这里是建了两个服务,用到哪个就切换至哪个服务. --需要授权 mongod --logpath ...

  8. Unity Github 项目收集

    http://gad.qq.com/article/detail/24048 重磅推荐: Github 热门 Unity Assets 查询:http://unitylist.com/browse 最 ...

  9. 1.6 js基础

    必会示例: i的问题 qq头像完整版 this的错误用法 按住鼠标连续加减 封闭空间 甲乙的问题 京东轮播图 苏宁延迟选项卡 无限下拉菜单 淘宝短发送倒计时 1.必须会的         选项卡.按钮 ...

  10. 以cmd命令行方式执行php文件时,传递参数

    1. php自带的两个参数$argc, $argv: 1.1. $argv : (后面的v是variables的意思),传递进来的参数会以数组的方式保持在这个变量里 1.2. $argc : (后面的 ...