你的位置:首页 > 软件开发 > ASP.net > 关于c#生成word。

关于c#生成word。

发布时间:2015-04-16 16:00:42
需求:需要把数据做成这样的效果、一个页面展示一个r单子数据。 object filename = ""; Object Nothing = System.Reflection.Missing.Value; Word.Application ...

需求:关于c#生成word。需要把数据做成这样的效果、一个页面展示一个r单子数据。

 object filename = "";      Object Nothing = System.Reflection.Missing.Value;      Word.Application WordApp = new Word.ApplicationClass();//实例化word      HY.Common.Utils.Logger.Log.Info("WordApp:" + WordApp);      Word._Application oWord = new Word.Application();      //创建Word文档      Word._Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);      try      {        SetPage(WordApp, WordDoc, "横板", 21, 29.7, 1, 1, 1, 1);        HY.Common.Utils.Logger.Log.Info("WordDoc:" + WordDoc);        get='_blank'>string name = "审批表" + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.ToLongTimeString().Replace(":", "") + ".docx";//创建生成文件名字        HY.Common.Utils.Logger.Log.Info("name" + name);        string CreateFilePath = ConfigurationManager.AppSettings["CreateFilePath"];        HY.Common.Utils.Logger.Log.Info("CreateFilePath" + CreateFilePath);        filename = CreateFilePath + name; //文件保存路径        HY.Common.Utils.Logger.Log.Info("filename" + filename);        string[] SerialNumberArr = Context.Request["SerialNumber"].Substring(0, Context.Request["SerialNumber"].ToString().Length - 1).Split(',');        string[] ProcInstIDArr = Context.Request["ProcInstID"].Substring(0, Context.Request["ProcInstID"].ToString().Length - 1).Split(',');//挂账Id        string[] PaymentProcInstIDArr = Context.Request["PaymentProcInstID"].Substring(0, Context.Request["PaymentProcInstID"].ToString().Length - 1).Split(',');//付款Id        for (int i = 0; i < ProcInstIDArr.Length; i++)        {          #region 打印          InsertText(WordDoc, "         审批表       ", new System.Drawing.Font("微软雅黑", 12, System.Drawing.FontStyle.Bold), Word.WdParagraphAlignment.wdAlignParagraphLeft, false);          InsertText(WordDoc, "", new System.Drawing.Font("微软雅黑", 12, System.Drawing.FontStyle.Bold), Word.WdParagraphAlignment.wdAlignParagraphLeft, true);          InsertText(WordDoc, "申请人信息", new System.Drawing.Font("宋体", 12, System.Drawing.FontStyle.Bold), Word.WdParagraphAlignment.wdAlignParagraphLeft, false);          if (ProcInstIDArr.Length - 1 != i)          {            InsertBreak(WordDoc, Nothing);          }          #endregion        }        WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);        WordApp = null;        HY.Common.Utils.Logger.Log.Info("SaveAs" + filename);      }      catch (Exception ex)      {        HY.Common.Utils.Logger.Log.Info("error" + e.ToString());      }      finally      {        WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);        oWord.Quit(ref Nothing, ref Nothing, ref Nothing);        KillWordProcess();      }

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:关于c#生成word。

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录