1.npoi能读取Word书签并且替换里面的内容吗
NPOI是以POI为基楚移植到.NET平台的 根据POI的lib来看HWPF是WORD格式 但在目前的NPOI版本里,还找不到HWPF ,因此推测目前应该还未支援到word的部份 另一个方法是用MS的word组件(Microsoft.Office.Interop.Word.dll)建立word档案 可以参考 ~~如果能帮到您,麻烦点击【有用】吧,谢谢哈~。
2.如何做NPOI导出word
NPOI 2.0就可以了。
引用using NPOI.XWPF.UserModel;XWPFDocument doc = new XWPFDocument();doc.CreateParagraph();FileStream sw = File.OpenWrite("blank.docx");doc.Write(sw);sw.Close();追加一句,刚才是生成了一个文件,再用流的方式,提示客户端下载,即可/// /// 弹出提示框,提示用户是否下载保存到本地\/// /// 文件路径public static string openWindowExport(string strFileName){string strReutrn = "";try{FileInfo DownloadFile = new FileInfo(strFileName);System.Web.HttpContext.Current.Response.Clear();System.Web.HttpContext.Current.Response.ClearHeaders();System.Web.HttpContext.Current.Response.Buffer = false;System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename="+ System.Web.HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);}catch (Exception Ex){strReutrn = Ex.Message;}finally{System.Web.HttpContext.Current.Response.Flush();System.Web.HttpContext.Current.Response.End();}return strReutrn;。
转载请注明出处51数据库 » npoi读取word