【发布时间】:2011-06-15 11:24:33
【问题描述】:
在我的应用程序中,我正在将 gridview 数据导出到 excel 并将其存储到特定文件夹中,现在我想要将此 excel 文件设置为只读,这样任何人都不应对其进行编辑。
我写过这样的代码:
protected void Button5_Click(object sender, EventArgs e) {
this.GridView1.Page.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
hw.WriteLine("<b><font size='5'> Report</font></b>");
this.GridView1.RenderControl(hw);
string HtmlInfo = tw.ToString();
string DocFileName = "Report" + ".xls";
string FilePathName = Request.PhysicalPath;
FilePathName = FilePathName.Substring(0, FilePathName.LastIndexOf("\\"));
FilePathName = @"C:\Excel" + "\\" + DocFileName;
FileStream Fs = new FileStream(FilePathName, FileMode.Create);
BinaryWriter BWriter = new BinaryWriter(Fs,System.Text.Encoding.GetEncoding("UTF-8"));
BWriter.Write(HtmlInfo);
BWriter.Close();
Fs.Close();
}
any1 帮我解决这个问题...
【问题讨论】: