在我的應用程序中,我將gridview數據導出爲excel並將其存儲到特定文件夾中,現在我想將此excel文件設置爲只讀,以便任何人都不應編輯它。將excel表導出爲只讀
我寫了這樣的代碼:
保護無效Button5_Click(對象發件人,EventArgs的){
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幫我在這...
@傑夫 - 它不工作.. – Sweety 2011-06-15 12:11:06
@傑夫 - excel表得到修改... – Sweety 2011-06-15 12:13:53
@傑夫 - 我在我的本地機器創建文件夾,我保存這個excel工作表現在我想要的是它不應該是可編輯的我怎麼能做到這一點.. – Sweety 2011-06-15 12:16:01