0
我正在使用外部DLL來創建Excel文件。它完全在網頁中工作,但是當我通過Web服務使用它時,它不會給出任何錯誤,但不會創建任何文件。這裏是web服務和excel導出函數的代碼。使用asp.net web服務創建excel文件
[WebMethod, System.Web.Script.Services.ScriptMethod]
public static string DownloadProfile(string profileids)
{
Result pro = new Result();
if (profileids == "")
pro = new Result(0, false, "No Profile to download", "");
else
{
candidate_search cs = new candidate_search();
string SqlProfile = "query";
try
{
cs.ExportExcel(SqlProfile);
pro = new Result(0, true, "CV Downloaded Successfully !", "");
}
catch {
//pro = new Result(0, false, "No Profile to download", "");
}
}
string json = JsonConvert.SerializeObject(pro, Newtonsoft.Json.Formatting.Indented);
return json;
}
public void ExportExcel(string SQLqueryProfile)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection ConProfile = new SqlConnection(constr);
SqlCommand CmdProfile = new SqlCommand(SQLqueryProfile);
SqlDataAdapter SdaProfile = new SqlDataAdapter();
CmdProfile.Connection = ConProfile;
SdaProfile.SelectCommand = CmdProfile;
DataTable DtProfile = new DataTable();
SdaProfile.Fill(DtProfile);
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(DtProfile, "Profile");
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=dataExport.xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
}
錯誤??????????? –
沒有錯誤。但不創建任何Excel文件。 –
使用調試器。 – nvoigt