-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
I am using latest version 1.0.5 of ClosedXML.Extensions.AspNet
I have a static class ExcelService containging this code:
public static void CreateExcelSheetForDataTableAndAddToResponse(DataTable tableToHandle, HttpResponse response, string fileName)
{
DataSet ds = new DataSet("REPORTS");
ds.Tables.Add(tableToHandle);
var wb = new XLWorkbook();
wb.Worksheets.Add(ds);
if (wb.Worksheets.FirstOrDefault() != null && wb.Worksheets.FirstOrDefault().Columns() != null)
{
wb.Worksheets.FirstOrDefault().Columns().AdjustToContents();
}
fileName = fileName.EndsWith(".xlsx") ? fileName : fileName + ".xlsx";
//wb.DeliverToHttpResponse(response, fileName);
response.DeliverWorkbook(wb, fileName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
I call it like this from my code behind for a asp.net page:
ExcelService.CreateExcelSheetForDataTableAndAddToResponse(myDataTable, this.Response, fileName.ToFileName());
My string extension for safe file name generation:
public static string ToFileName(this string s)
{
string regexSearch = new string(Path.GetInvalidFileNameChars());
Regex rs = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
s = rs.Replace(s, "");
return s.Replace(" ", "_"); // replace space with underscore
}
The response stream gets the file with both delivery methods but both delivery methods also throws a Thread was being aborted exception. Catching this exception explicitly and it all works. But why is it throwing that Thread exception?
Metadata
Metadata
Assignees
Labels
No labels