当前位置: 代码迷 >> .NET组件控件 >> 各路大神,NPOI对word进行操作时构造函数运行异常
  详细解决方案

各路大神,NPOI对word进行操作时构造函数运行异常

热度:118   发布时间:2016-05-04 23:18:33.0
求救各路大神,NPOI对word进行操作时构造函数运行错误
       读取word模板的时候报错了,参考了npoi作者的网站也是这样写应该是没错的呀,为什么到了 实例doc的时候就会报出“Wrong local header signature” 的错误,有没有解决方法或者其他途径可以读取到word模板的呀?
        
using NPOI.XWPF;
using NPOI.XWPF.UserModel;
using NPOI.XWPF.Model;
public string ExportComment()
        {
            string fileName = string.Format("pkcommentlist_{0}.docx", DateTime.Now.ToString("yyyyMMddHHmmss"));
            string savePath = string.Format("{0}content\\temp\\{1}", Request.PhysicalApplicationPath, fileName);
            string templatePath = string.Format("{0}content\\wordtemplate\\test.docx", Request.PhysicalApplicationPath);
            FileStream fileStream = new FileStream(templatePath, FileMode.Open, FileAccess.Read);
            XWPFDocument doc = new XWPFDocument(fileStream );//出错行
           .....(下面的走不下去了)
            FileStream savefile = new FileStream(savePath, FileMode.Create);
            doc.Write(savefile);
            savefile.Close();
       }
------解决思路----------------------
你先断点跟,看Request.PhysicalApplicationPath里面的路径后面到底带不带\
  相关解决方案