ASP.NET中对EXCEL文件进行操作!

第一步:添加对Microsoft.Excel引用

using Excel = Microsoft.Office.Interop.Excel;

using Microsoft.Office.Interop.Excel;

第二步:

object missing = System.Reflection.Missing.Value;

       // Excel.ApplicationClass = new ApplicationClass();

        Excel.Application ex = new Microsoft.Office.Interop.Excel.Application();

         string  filename = "c:\\bb.xls";

         string dfilename = "c:\\cc.xls";

         object editable = true;

         Excel.Workbook wk = ex.Workbooks.Open

             (filename, missing, missing, missing, missing, missing, missing, missing, missing, editable, missing, missing, missing, missing, missing);

        Excel.Worksheet ws = wk.Worksheets[1] as Excel.Worksheet;

        ws.Protect

            (missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

       ws.SaveAs(dfilename,missing,missing,missing,missing,missing,Excel.XlSaveAsAccessMode.xlShared,missing,missing,missing);

        ex.Quit();

这样可以控制Excel文件,使其禁止修改内容!!!! 

第三种 可以使用NOPI控件,这是最具性价比的一种方法,推荐使用这种方式

posted @ 2009-04-13 11:59  雪莱·亨尼格  阅读(304)  评论(0编辑  收藏  举报