彩票走势图

代码说明Aspose.Words模板打印功能

原创|其它|编辑:郝浩|2012-10-09 14:45:35.000|阅读 2019 次

概述:对于Aspose.Words模板打印功能进行了详细描述,附代码。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

Aspose.Words模板说明:书签必须在文字前面

String modelFile = context.Server.MapPath("~/WordModel/ODO.docx");
Document doc = new Document(modelFile);//加载模板
doc.Protect(ProtectionType.ReadOnly);
doc.Range.Bookmarks["lblcompany"].Text = "";//获取模板书签并复制
//动态生成表格
DocumentBuilder docBuilder = new DocumentBuilder(doc);
nt count = 0;
//记录要显示多少列
for (int i = 0; i < MyTable.Columns.Count; i++)
{
if (doc.Range.Bookmarks[MyTable.Columns[i].ColumnName.Trim()] != null)
{
Bookmark mark = doc.Range.Bookmarks[MyTable.Columns[i].ColumnName.Trim()];
mark.Text = "";
count++;
}
}
Hashtable ht = new Hashtable();//单元格宽度
System.Collections.Generic.List<string> listcolumn = new System.Collections.Generic.List<string>(count);
for (int i = 0; i < count; i++)
{
docBuilder.MoveToCell(0, 0, i, 0); //移动单元格
if (docBuilder.CurrentNode.NodeType == NodeType.BookmarkStart)
{
listcolumn.Add((docBuilder.CurrentNode as BookmarkStart).Name);
ht.Add((docBuilder.CurrentNode as BookmarkStart).Name, docBuilder.CellFormat.Width);
}
}
docBuilder.MoveToBookmark("lblgoods"); //开始添加值
for (int m = 0; m < MyTable.Rows.Count; m++)
{
for (int i = 0; i < listcolumn.Count; i++)
{
docBuilder.InsertCell();// 添加一个单元格
docBuilder.CellFormat.Borders.LineStyle = LineStyle.Single;
docBuilder.CellFormat.Borders.Color = System.Drawing.Color.Black;
docBuilder.CellFormat.Width = (double)ht[listcolumn[i]];
docBuilder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
docBuilder.Write(MyTable.Rows[m][listcolumn[i]].ToString());
if (m == 0)
{
docBuilder.CellFormat.Borders.Top.LineStyle = LineStyle.None;
docBuilder.CellFormat.Borders.LineWidth = 0;
}
if (m == MyTable.Rows.Count - 1)
{
docBuilder.CellFormat.Borders.Bottom.LineStyle = LineStyle.None;
docBuilder.CellFormat.Borders.LineWidth = 0;
}
}
docBuilder.EndRow();
}
doc.Range.Bookmarks["lblgoods"].Text = ""; // 清掉标示

if (extension.Equals(".docx"))
{
fileName += DateTime.Now.ToString("yyyyMMddHHmmssfffff") + ".doc";
doc.Save(fileName, SaveFormat.Doc, SaveType.OpenInWord, context.Response);
}

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:睦木的163博客

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP