XLWorkbook:十六进制值0x1D是内存流保存时的无效字符

时间:2016-06-02 11:14:23

标签: c# asp.net-mvc entity-framework-6 closedxml

我正在尝试下载excel文件,但一直在

  

十六进制值0x1D是无效字符'错误

请在下面找到我的代码。

public static string GenerateRADownloadExcel(System.Data.DataTable downloadtable,long studyid, out string fileName)
{
    try
    {
        using (var wb = new XLWorkbook())
        {
            wb.Worksheets.Add(downloadtable);
            var raDataKey = Guid.NewGuid().ToString();
            fileName = "Study_" + studyid + "_ResearchActivityData_" + DateTime.Now.ToString("ddMMyy") + "_" + DateTime.Now.ToString("HHmm");

            var memoryStream = new MemoryStream();
            wb.SaveAs(memoryStream);

            memoryStream.Position = 0;
            HttpContext.Current.Session[raDataKey] = memoryStream;

            return raDataKey;
        }
    }
    catch(Exception ex)
    {
        throw ex;
    }
}

执行wb.SaveAs(memoryStream);

时出现异常

0 个答案:

没有答案