protected void btnExportZip_Click(object sender,EventArgs e)
{
string archiveName=String.Format("zip文件名{0}-{1}.zip",CurrentUser.DepartmentName,DateTime.Now.ToString("yyyy-MM-dd");
Resoponse.CotentType="application/zip";
Response.AddHeader("content-disposition","attachment;filename=\""+HttpUtility.UrlEncode(archiveName,Encoding.UTF8)+"\"");
var docHelper=new DocHelper();
var template=Server.MapPath("~/Template/export/template.doc");//模板
var streamList=new List<MemoryStream>();
//数据源赋值
using(var zip=new ZipFile(Encoding.UTF8))
{
foreach(var proposal in proposaList)
{
var newDs=new Dataset();
var dt1=ListExtend.ListToDataTable(new List<Proposal>(){proposal});// T转换为datatable
dt1.TableName="table";
newDs.Tables.add(dt1);
//关联建议人 把建议人数据放入提案数据的尾部
var suggesterList=ProposerService.GetListByProposalId(proposal.Id);
var dtSuggester=ListExtend.ListToDataTable(suggesterList);
dtSuggester.TableName="Proposer";
newDs.Table.Add(dtSuggester);
newDs.Relations.Add("ProposalWithProposer",dt1.Columns["Id"],dtSuggester.Colums["ProposalId"]);
docHelper.DataSetList=new List<DataSet>(){newDs};
var fileName=string.Format("{0}-{1}-政协提案交办全文.doc",proposal.Num,proposal.Title);
var stream=docHelper.ExportStream(template);
stream.Seek(0,SeekOrigin.Begin);
zip.AddEntry(fileName,stream);
streamList.Add(stream);
}
zip.save(Response.OutputStream);
foreach(var memoryStream in streamList)
{
memoryStream.Close();
}
}
}