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;