word.openWord(context.Server.MapPath(@"~/test/wordhelper/template/模板.docx"));
Dictionary<string, object> d = new Dictionary<string, object>(); //段落 d = new Dictionary<string, object>(); d.Add("no", DateTime.Now.ToString()); word.setCellValueParagraphs(d);
//表格内单元格局部替换 d = new Dictionary<string, object>(); d.Add("tableusername", "郑州张三"); word.setCellValuetTables(d, 0);
//表格内单元格全替换 d = new Dictionary<string, object>(); d.Add("#tableuserid$", "001"); d.Add("#tableusername$", "郑州张三"); d.Add("#img$", "$img{" + context.Server.MapPath(@"~/test/wordhelper/猫.jpg") + "}(5000000,5000000)"); //插入图片(宽,高) word.setCellValuetTables1(d, 1);
d.Add("#img$", "$img{" + context.Server.MapPath(@"~/test/wordhelper/猫.jpg") + "}(5000000,5000000)"); //插入图片(宽,高) word.setCellValuetTables1(d, 1);
//循环表格 DataSet ds_table = new DataSet(); DataTable dt_table = new DataTable(); dt_table.Columns.Add("itemid"); dt_table.Columns.Add("itemname"); for (int i = 0; i < 5; i++) { DataRow dr = dt_table.NewRow(); dr["itemid"] = i.ToString(); dr["itemname"] = i.ToString() + "name"; dt_table.Rows.Add(dr); } ds_table.Tables.Add(dt_table); word.setCellValuetTables(ds_table, 1, word.tables[2]);
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/wynan830/article/details/47313683