Feedback Form

Friday, February 01, 2008

Excel file in new excel instance

You can open any excel file using code like this:

Process.Start(filePath);

But what will happen if we have these 2 lines of code:

Process.Start(filePathONE);

Process.Start(filePathTWO);

Will first open “filePathONE” in a new excel instance, then will open the “filePathTwo” in the same excel instance.

What we can do if we want to open each file in a separate new excel instance?

We must write it like that:

Process.Start(“Excel.exe”, filePathONE);

Process.Start(“Excel.exe”, filePathTWO);

It’s very simple, isn’t it?

But we can face a small problem with this way:

If you want to open an excel file that contains space in its name, for example “my Sheet.xls”, it will give you a runtime error that it can’t open files “my.xls” and “Sheet.xls”.

So what can I do?

It’s simple:

Just add “ before and after the file path, just like that:

Process.Start(“Excel.exe”, @“””filePathONE”””);

Like that it will open normally without any errors.

Note:

You will need to do the same for any office application (word, powerpoint, ….).

kick it on DotNetKicks.com

2 comments:

Alex said...

At work with excel files I recommend try good reliable tool to my mind-ms Excel sheet recovery tools,why it?,because program helped me in very difficult situation and has free status as far as I can see,utility can repair corrupted Microsoft Excel worksheets,restore data after problems with corrupted worksheet problem as a result of virus attack, disk and network failures or any other problem,an scan a damaged Microsoft Excel worksheet and repair it,work with *.xls, *.xlam, *.xltx, *.xlt and *.xlsm formats,recover modified Excel worksheets and shows recovered data in the same way, like it will be displayed in Microsoft Excel worksheet.

Anonymous said...

Easily I assent to but I about the list inform should have more info then it has.