This project has moved. For the latest updates, please go here.
1
Vote

There was a problem sending the command to the program.

description

when I save excel file and try to open it with excel 2016 I get the following error:
"There was a problem sending the command to the program."
and excel opens up in compatibility mode. this does not happen in earlier versions of excel.
attached is the file produced, and here is source code:
 _     public void GenerateExcelReport(DataTable dtSource, string reportName) {
         foreach (DataColumn column in dtSource.Columns) {
            column.ColumnName = PageUtil.FromCamelCase(column.ColumnName);
         }

         HttpContext.Current.Response.Clear();
         HttpContext.Current.Response.ClearContent();
         HttpContext.Current.Response.ClearHeaders();
         HttpContext.Current.Response.Buffer = true;
         HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
         HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
         HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
         HttpContext.Current.Response.AddHeader("content-disposition", $"attachment;filename={reportName}.xlsx");

         using (var excelPackage = new ExcelPackage()) {
            // add worksheet 
            var workSheet = excelPackage.Workbook.Worksheets.Add(reportName);
            workSheet.Cells["A1"].LoadFromDataTable(dtSource, true);

            // make header BOLD
            var totalCols = workSheet.Dimension.End.Column;
            var headerCells = workSheet.Cells[1, 1, 1, totalCols];
            headerCells.Style.Font.Bold = true;

            var memoryStream = new System.IO.MemoryStream();
            excelPackage.SaveAs(memoryStream);
            memoryStream.WriteTo(HttpContext.Current.Response.OutputStream);
         }

         HttpContext.Current.Response.AddHeader("content-disposition", $"attachment;filename={reportName}.xlsx");

         HttpContext.Current.Response.Flush();
         HttpContext.Current.Response.End();
      }_

file attachments

comments