日期:2014-05-17  浏览次数:20949 次

c# excel 复制一个sheet到一个新建的excel中!运行时代码出错求大神帮忙修改!
        private bool CobyEXCEL(string sourcePath)
        {
            bool result = false;
            Excel.XlFixedFormatType targetType = Excel.XlFixedFormatType.xlTypePDF;
            object missing = Type.Missing;
            Excel.ApplicationClass application = null;
            Excel.Workbook workBook = null;
            try
            {
                application = new Excel.ApplicationClass();
                object type = targetType;
                workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
                        missing, missing, missing, missing, missing, missing, missing, missing, missing);
                //Excel.Worksheet worksheet = (Excel.Worksheet)workBook.Sheets["sheet1"];
                Excel.Sheets shs = workBook.Sheets;

                Excel.Worksheet worksheet = (Excel.Worksheet)shs.get_Item(1);

             //定义一个COM中空类型的对象
            object missing1=System.Reflection.Missing.Value;
            Excel.Application app = new Excel.ApplicationClass();
            app.Application.Workbooks.Add(true);
            Excel.Workbook book =(Excel.Workbook)app.ActiveWorkbook;
            //worksheet = (Excel.Worksheet)book.Worksheets.Add();