Excel 2007에 gridview를 내보내고 싶습니다. mime type application/vnd.ms-excel (excel 2003)을 사용하여 2007 년 Excel 2007로 가져올 수있는 코드를 가져올 수 있지만 경고 메시지가 나타납니다. "당신이 열려고하는 파일이 다른 형식입니다 ..."라고 말하면 yes와 no를 사용하여 clic을 클릭하고 예를 들어 파일을 클릭하면 고객을 위해 msg를 가질 수 없습니다. 그리고 mime을 사용합니다 excel 2007 (application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) 파일을 열면 "Excel에서 형식이나 확장이 유효하지 않기 때문에 파일을 열 수 없습니다."라는 메시지가 나타납니다. GridView를 Excel 2007로 내보내기
이
내가 지금 코드를 사용하고 있습니다 :using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Drawing;
namespace TesteFornecedores
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
using (DataSet ds = new DataSet())
{
ds.ReadXml(Server.MapPath("~/Customers.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindGrid();
}
protected void ExportToExcel(object sender, EventArgs e)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=ExcelList");
Response.Charset = "";
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
//To Export all pages
GridView1.AllowPaging = false;
this.BindGrid();
GridView1.HeaderRow.BackColor = Color.White;
foreach (TableCell cell in GridView1.HeaderRow.Cells)
{
cell.BackColor = GridView1.HeaderStyle.BackColor;
}
foreach (GridViewRow row in GridView1.Rows)
{
row.BackColor = Color.White;
foreach (TableCell cell in row.Cells)
{
if (row.RowIndex%2 == 0)
{
cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
}
else
{
cell.BackColor = GridView1.RowStyle.BackColor;
}
cell.CssClass = "textmode";
}
}
GridView1.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
}
}
사람은 2007이있는 gridview Excel에서 나를 열어 도움을 줄 수있는 솔루션을 알아?
감사합니다.