/// <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的形式打开WrodAspose.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*";}#endregionAspose.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. Can't create table... error150

    mysql Can't create table... error150: 在创建数据库的时候使用的联合主键,之后有两个外键,建好各自的表之后进行添加外键,报错,解决办法,对比两个表的相对应的字段的大 ...

  2. mysql create table()_MySQL Create Table创建表

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

  3. postgres语法_SQL Create Table解释了MySQL和Postgres的语法示例

    postgres语法 A table is a group of data stored in a database. 表是存储在数据库中的一组数据. To create a table in a d ...

  4. Oracle中,使 CREATE TABLE AS SELECT 支持ORDER BY

    Oracle中,使 CREATE TABLE AS SELECT 支持ORDER BY 文章发表:kehui  发表日期:2002-01-21  阅读次数:1103  大家都知道,"CREA ...

  5. 如何使‘CREATE TABLE AS SELECT’能支持ORDER BY ?

    如何使'CREATE TABLE AS SELECT'能支持ORDER BY ?         大家都知道,"CREATE TABLE AS SELECT"这个SQL命令并不支持 ...

  6. oracle中create table with as和insert into with as语句

    oracle支持使用with as 子句来创建表 语法: create table table_name as with clause_name as (select query ) [, claus ...

  7. SQL CREATE TABLE 语句(转)

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

  8. 使用Navicat创建数据库,外键出现错误ERROR 1005: Can't create table (errno: 121)

    ERROR 1005: Can't create table (errno: 121) 意思是: 1.表名重复 2.以该名字命名的表之前创建过后来删除了,但是对应的.frm文件还留在磁盘上 3.主键名 ...

  9. oracle数据库【表复制】insert into select from跟create table as select * from 两种表复制语句区别...

    create table  as select * from和insert into select from两种表复制语句区别 create table targer_table as select ...

最新文章

  1. 【人在职场】能力与价值
  2. elementui原生属性_elementUI——主题定制
  3. 不在pytorch中的损失的函数
  4. WinDBG 要点学习
  5. Consul入门01 - 安装Consul
  6. SSY and JLBD
  7. ViewPager+Fragment,Fragment会预加载的问题
  8. 消息中间件学习总结(20)——主流MQ比较及MQ常见使用场景总结
  9. 【动态规划】【数位DP】[PA 2015]Rownanie
  10. hive血缘关系之输入表与目标表的解析
  11. 自治系统中单个路由表的构造
  12. 如何使用C#操作WinAPI
  13. Ubuntu固定ip和dns配置和查看
  14. 群晖3617可以有几个网卡_一步到位,购入群晖920+和它的小伙伴们
  15. mysql5.7卸载教程_MySQL 5.7.19 简易安装、卸载教程
  16. CSP多USBkey操作获取信息
  17. Python爬虫实现无限刷不背单词app的酷币!很有意思!
  18. 查看linux系统显卡型号
  19. QT 中文语法错误: 缺少“(” (在“}”的前面)(所遇到的特殊情况)
  20. hive修改分区信息

热门文章

  1. 汇编和python-PyAsm-在python中嵌入汇编 | 学步园
  2. python各个解释器的用途-python解释器有哪些?
  3. 输出9*9口诀python-Python输出9*9乘法表的方法
  4. python官方手册-Python3 中文手册
  5. python游戏编程入门 免费-python游戏编程入门 python游戏编程入门课
  6. 报错:ModuleNotFoundError: No module named ‘cv_bridge‘,以及在ROS是如何安装cv_bridge库包
  7. conda下载出现连接超时怎么办
  8. 4_Tensorflow框架的使用(20181217-)
  9. Opengl-基本概念-着色器(都是固定的)
  10. Fisher_Yates算法