Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,

i generate excel file using code given below but it's generate file in "c:\\" drive but i want to change location of file where it was generated so how can i change location where file is generated i use code given below.

Microsoft.Office.Interop.Excel.Application xlApp;

Microsoft.Office.Interop.Excel.Workbook xlWorkBook;

Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;

object misValue = System.Reflection.Missing.Value;



xlApp = new Microsoft.Office.Interop.Excel.ApplicationClass();

xlWorkBook = xlApp.Workbooks.Add(misValue);



xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

xlWorkSheet.Cells[1, 1] = "c:\\csharp-Excel.xls";



xlWorkBook.SaveAs("c:\\csharp-Excel.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

xlWorkBook.Close(true, misValue, misValue);

xlApp.Quit();



releaseObject(xlWorkSheet);

releaseObject(xlWorkBook);

releaseObject(xlApp);
Posted

1 solution

xlWorkBook.SaveAs("c:\\csharp-Excel.xls",

YOU are telling excel where to save the workbook, YOU need to change the path.
 
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