1

So I use standard interface.

using Excel = Microsoft.Office.Interop.Excel; 

// file save function

 xlWorkBook.SaveAs("Bar Charts.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
 xlWorkBook.Close(true, misValue, misValue);
 xlApp.Quit();

Everything is fine, but file appears here C:\Users\Dex\Documents. How can I change file destination true way? Don't want to move it after all.

Function described here http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.saveas.aspx, but there is no such parameter.

1
  • 2
    Provide the fully qualified path? Commented Dec 11, 2013 at 9:58

3 Answers 3

5

The link you provided contains the answer:

Filename

The name of the file to be saved. You can include a full path; if you do not, Microsoft Office Excel saves the file in the current folder.

Use @"C:\Another\Folder\Bar Charts.xls" instead of just "Bar Charts.xls". You can also use the Path.Combine if you already have your folder in another string:

xlWorkBook.SaveAs(Path.Combine(folder, "Bar Charts.xls"), ...
Sign up to request clarification or add additional context in comments.

Comments

2

Try This :

xlWorkBook.SaveAs(@"YourPath" + "\Bar Charts.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
 xlWorkBook.Close(true, misValue, misValue);
 xlApp.Quit();

Comments

0
private static DateTime csvtime = DateTime.Now;
    private static string time = csvtime.ToString("dd-MM-yyyy");
private static string filename = @"C:\users\User\desktop\yourfolder_"+time+".xls";
xlWorkBook.SaveAs(filename, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
 xlWorkBook.Close(true, misValue, misValue);
 xlApp.Quit();

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.