C#空间

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

            System.Reflection.Missing miss = System.Reflection.Missing.Value;  
            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();

            Microsoft.Office.Interop.Excel.Workbooks books = (Microsoft.Office.Interop.Excel.Workbooks)excel.Workbooks;

           // Microsoft.Office.Interop.Excel.Workbook book = (Microsoft.Office.Interop.Excel.Workbook)(books.Add(miss));
            Microsoft.Office.Interop.Excel.Workbook book = books.Add(XlWBATemplate.xlWBATWorksheet);

            for (int i = 1; i < 6; i++)
            {

               // Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)book.ActiveSheet;

                Microsoft.Office.Interop.Excel.Worksheet newWorksheet;
                newWorksheet = (Microsoft.Office.Interop.Excel.Worksheet)book.Worksheets.Add(miss, miss, miss, miss);
                newWorksheet.Name = "test" + i.ToString();

            }
           excel.Visible = true;

posted on 2010-04-17 18:51  小海洋  阅读(2629)  评论(0编辑  收藏  举报