Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 保存的Excel无法用Excel 2016打开_C#_Asp.net_Excel - Fatal编程技术网

C# 保存的Excel无法用Excel 2016打开

C# 保存的Excel无法用Excel 2016打开,c#,asp.net,excel,C#,Asp.net,Excel,我正在使用以下代码生成一个Excel文件 private void ExportGridView(GridView gv) { string attachment = "attachment; filename=Factuurtjes.xls"; Response.ClearContent(); Response.AddHeader("content-disposition", attachment); Response.ContentType = "appli

我正在使用以下代码生成一个Excel文件

private void ExportGridView(GridView gv)
{

    string attachment = "attachment; filename=Factuurtjes.xls";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
    StringWriter sw = new StringWriter();

    HtmlTextWriter htw = new HtmlTextWriter(sw);
    // Create a form to contain the grid
    HtmlForm frm = new HtmlForm();

    gv.Parent.Controls.Add(frm);

    //Response.Write("Opdrachtgever geselecteerd: " + ddlContractor.SelectedItem.ToString());

    frm.Attributes["runat"] = "server";
    frm.Controls.Add(gv);
    frm.RenderControl(htw);

    //GridView1.RenderControl(htw);
    Response.Write(sw.ToString());

    Response.End();
}
这一切都很好,excel文件会按其应有的方式保存

我可以用excel 2013打开excel文件。但当我想用Excel 2016打开它时,它会给我一条警告信息,说明文件可能已损坏

我想要一个解决方案,这样我就可以用Excel 2016打开文件

有人能帮我吗


提前感谢。

我认为这有助于解决您的问题。

这是因为导出的文件只是一个html文件,而不是“真正的”xls文档。根据office版本,它可以发出警告。Kijk eens naar,veel meer mogelijkheden voor het genereren van Excel文档感谢您的回复。如果你不介意的话,我将用英语继续。在您提供的链接上,只有与excel 2007/2010文件相关的文章。我需要excel 2016文件。我还需要说,导出的文件实际上是excel文件,因为它可以用早期版本的excel打开。EPPlus生成的格式是Open Office Xml格式xlsx。Excel 2016支持这一点。我将如何实现这一点?这不是我想要的。我是通过问题中提供的代码保存文件,而不是通过excel本身。在您的代码中,excel文件扩展名是.xls,它是2007年之前的excel版本,而.xlsx扩展名是在excel 2007及以后的版本中创建的,因此将您的文件扩展名Factuurtjes.xls更改为Factuurtjes.xlsx。不起作用。我已经试过了。仍然会收到一条警告信息。