Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using the following code to save my work into workbook and closing it after saving my data into it

C#
object misValue = System.Reflection.Missing.Value;
            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkBook = xlApp.Workbooks.Add(misValue);

            Excel._Worksheet xlWorksheet1 = xlWorkBook.Sheets[1];
            
            List<DataSet> lstDS1 = new List<DataSet>();

         lstDS1 = GetExcelData(@"\\global.scd.scania.com\home\se\121\valhbc\Desktop\log file data\Output\", "ResponseTime.xls");

       
            string path1 = Properties.Settings.Default.OutputDirPath + "\\" + "GatewayMsgs.xls";


            if (File.Exists(path1))
                File.Delete(path1);




          //do something



            xlWorkBook.SaveAs(path1, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlShared, misValue, misValue, misValue, misValue, misValue);
            xlWorkBook.Close(true, misValue, misValue);



        }
    }


But when I am trying to open the workbook in output folder,another empty workbook is also opening with my saved workbook and every time the workbook number is incresing like(Book1,Book2,Book3 etc)

Can anyone please suggest me some olution to solve this problem


Thanks
John
Posted
Updated 10-Dec-13 4:22am
v2
Comments
Try quiting the app.

xlApp.Quit();

1 solution

All I know is that it is something to do with the Interop library.


Have a read of this one

http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900