我想从.NET应用程序创建一个Excel US preadsheet,然后设置一个Excel.Application实例当前目录自定义文件夹。我想这样做,这样,当用户点击在Excel中,另存为对话框已经位于正确的目录保存按钮。
I want to create an Excel spreadsheet from a .NET Application and then set the Excel.Application instance current directory to a custom folder. I want to do this so when the user clicks the save button in Excel, the Save as dialog is already located in the correct directory.
我知道这是可能改变当前目录中的Excel实例与VBA.FileSystem.ChDir和VBA code /宏这样一个Excel.Application实例中这样做:
I know it's possible to change the current directory in Excel Instance with VBA.FileSystem.ChDir and doing it within the Excel.Application instance with VBA Code/Macro like this:
从创建C#.NET中的Excel US preadsheet
Create an Excel Spreadsheet from C# .NET
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Workbooks.Add();
excel.Visible = true;
在Excel的小号preadsheet是开放的,按下Alt + F11。然后创建并运行下面的宏
When Excel spreadsheet is open, hit ALT + F11. Then create and run following macro
Sub SetChdir()
Call FileSystem.ChDir("C:\To\My\Custom\Directory\")
End Sub
当点击保存Excel中的当前目录设置路径设置CHDIR
When clicking Save in Excel the Current Directory is set path set with ChDir
我想不通,甚至如果可能的话,如何创建一个从.NET这种行为。我累了瞎搞与Excel.DefaultFilePath该Excel使用启动时设置当前目录。但是它有两个问题:
I can't figure out, or even if it's possible, how to create this behaviour from .NET. I tired messing around with Excel.DefaultFilePath which Excel uses on startup to set the Current Directory. But it has two problems:
在当前DefaultFilePath设置为不同的值,则需要重新启动Excel,使之在新的或开放源代码preadsheets影响 我真的不希望改变用户当前DefaultFilePath因为它是Excel中的一个全局值,而不是这种的各个S preadsheet。还有另一种方式。
excel.ExecuteExcel4Macro("DIRECTORY(\"C:\\To\\My\\Custom\\Directory\")");