npoi,按模板导出word
npoi,按模板导出word
篇一:Npoi2.0.5导出word(合并行和合并列
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data;
using System.Collections;
using System.IO;
using NPOI;
using NPOI.HSSF.UserModel;
using DAL = CC.DAL;
using CC.Common;
using BLL = CC.BLL;
using NPOI.XWPF.UserModel;
using NPOI.OpenXml4Net;
using NPOI.OpenXmlFormats.Wordprocessing;
/********************
* 功能:食谱分析报告导出
* 编写人:
* 日期:2014.5.27
* nopi版本:
********************/
public partial class ExportFoodCheckList : BasePage
{
#region //加载模板
protected void Page_Load(object sender, EventArgs e)
{
if (Request[RecweekId] != null)
{
string type = Request[type].ToString();
int RecweekId = int.Parse(Request[RecweekId].ToString());
ViewState[HidRecipwweekId] = RecweekId.ToString();
if (type == Rec)
{
XWPFDocument doc = HtmlExport(Int32.Parse(ViewState[HidRecipwweekId].ToString()), 0);//.Replace(
string wordFile = Server.MapPath(模板.docx);
FileInfo file = new FileInfo(wordFile);
if (file.Exists)
{
FileStream out1 = new FileStream(wordFile, FileMode.Create);doc.Write(out1);
out1.Close();
openWindowExport(wordFile, 食谱.docx);
}
}
else
{
XWPFDocument doc = new XWPFDocument();
string wordFile = Server.MapPath(模板.docx);
FileInfo file = new FileInfo(wordFile);
if (file.Exists){
doc = tbGetReport(Int32.Parse(ViewState[HidRecipwweekId].ToString()), doc);
FileStream out1 = new FileStream(wordFile, FileMode.Create);
doc.Write(out1);
out1.Close();
openWindowExport(wordFile, 食谱分析报告.docx);
}
}
}
}
public static string openWindowExport(string strFileName,string downfile)
{
string strReutrn = ;
try
{
FileInfo DownloadFile = new FileInfo(strFileName);
System.Web.Http