最近项目开发涉及到了操作Word模板,先前用Office的动态库编码,完成后,部署客户环境时候,发现出现各种问题,需要安装office,然后报出各种
注册表问题,麻烦的太太,于是改用另一种方法,引进Aspose.Words.dll后,就直接操作word模板,画表格,非常方便,于是把方法记录下来,分享给大家,
希望大家能在以后的工作中避开不必要的选择时间浪费,共进共勉:
/// <summary>
/// AsPose.Word's Export/// </summary>
/// <returns></returns>
public static string AsPoseExportData(ReportType roportType, Dictionary<string, string> param)
{
//Report Template'work Path
string path = Path.Combine(SPUtility.GetGenericSetupPath(@"TEMPLATE\LAYOUTS\Akmii.BMS.China.Workflow\ReportTemplate"), roportType.ToString() + ".docx");
Aspose.Words.Document doc = new Aspose.Words.Document(path);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToCell(0, 0, 1, 0);
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Bottom;
builder.Write(param["ReportName"].ToString());
builder.MoveToDocumentEnd();---------------------------------------------------------- 注意:换行,重新开始
//Insert Empty Rows
builder.StartTable();
builder.CellFormat.Borders.LineStyle = Aspose.Words.LineStyle.None;
for (int j = 0; j < 1; j++)
{
builder.InsertCell();
builder.EndRow();
}
builder.EndTabl