다음 코드를 사용하여 데이터 세트를 xls로 변환했습니다. 그것은 잘 작동하지만 오류가 throw됩니다. (일부 서식 문제)데이터 세트를 xls로 내보내고 서버 하드 디스크에 저장하는 방법
사용자의 허가없이 특정 위치에서 생성 된 xls 파일을 저장하고 싶습니다. 그 거대한 보안 위험을 초래할 것이기 때문에 분명히 할 수 없습니다
conn.Open();
SqlDataAdapter getData = new SqlDataAdapter("SELECT * FROM profile", conn);
data.Clear();
getData.Fill(data);
conn.Close();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.Charset = "";
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" +"siv" +"\"");
using (StringWriter sw = new StringWriter())
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
DataGrid dg = new DataGrid();
dg.DataSource = data.Tables[0];
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
response.End();
}
질문에서 무엇을 묻고 있습니까? 당신은 형식 오류 (어쩌면 그것은 null 열 제로 아이디어)에 대해 언급. 그런 다음 사용자 권한을 사용하지 않고 저장하려고합니다. 서버 또는 클라이언트 컴퓨터에 저장하는 것입니까? 그것이 클라이언트 머신이라면 브라우저와 웹 브라우저의 사용자 설정에 달려 있습니다. –
@Mike 확장명이 ub 형식과 다른 것입니다. – SHiv