我使用以下代碼將數據集轉換爲xls。它工作正常,但會引發錯誤。 (某些格式化問題)如何將數據集導出到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();
}
你在問什麼問題?你提到一些關於格式錯誤的東西(也許這是空列零的想法)。然後,您想要將其保存爲無用戶權限 - 是將它保存在服務器還是客戶機上?如果它是客戶機,並且它看起來像一個完全取決於瀏覽器和該機器上用戶設置的Web瀏覽器。 –
@Mike它說這是ub不同於擴展名的格式 – SHiv