Groups | Blog | Home
all groups > dotnet sdk > november 2007 >

dotnet sdk : Process.Start("filename.xlsx") never returns


David Thielen
11/20/2007 3:43:01 PM
Hi;

This is for a C# Excel AddIn. Because it is an AddIn to C# I do not have
control over setting the threading model.

When my AddIn creates a report and calls Process.Start(filename), it works
fine if the file is a docx file. But if it is an xlsx file the method never
returns.

In my code I am in the thread that Excel's menu event called me on. In that
code I call:

BeginInvoke(new LaunchDelegate(LaunchReport));
}
....
[SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)]
private void LaunchReport()
{
Process rtn = Process.Start(filename);

LaunchReport is in the same thread as it's caller - I don't know if that is
guaranteed but it is what is happening.

So why is this not returning?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm

jialge@online.microsoft.com
11/21/2007 7:41:54 AM
Hello Dave,

When we are calling Prcess.Start("filename.xlsx") inside a Excel COM
Add-in, the current thread will ask the current process of Excel to open
the xlsx file. The current thread is waiting for the return of the
Process.Start call, Process.Start is also waiting for the finish of the
current thread actually. Therefore, a dead lock is constituted and it never
returns. To work-around it, we could use Excel.Application.Workbooks.Open
method to open the target xlsx. Please have a try and let me know the
result.

If you have any concern or question, please feel free to let me know.

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen
11/21/2007 9:57:06 AM
Hi;

I did the following for my code:
Microsoft.Office.Interop.Excel.Application excelApp = new
Microsoft.Office.Interop.Excel.ApplicationClass();
excelApp.Visible = true;
excelApp.Workbooks.Open(filename, 0, false, 5, "", "", false,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0,
true, false, false);


There are a couple of problems with this approach:
1) When running under Excel 2007 on my system, where Excel 2003 is also
installed and is the default version of Excel, then it creates an instance of
Excel 2003 instead of Excel 2007. How do I get it to use the same version of
Excel I am running in.

2) When it pops up, it tells me "Calculation is incomplete. Recalculate
before saving?" How can I avoid that message. And "No" is the only answer
that works - "Yes" keeps bringing up the same prompt.

3) How do I know which extensions to do this for. A user could set all .txt
files to be handled by Excel (weird, but possible). And they could set .XLS
to be handled by OpenOffice.

4) I assume I need to do the same thing for Word? Same question (3) on what
extensions. And what is the suggested code to do this for Word?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
David Thielen
11/21/2007 12:44:00 PM
I now hit an even bigger deadlock using the Excel.Application.Open() approach.

If it starts a different version of Excel, then it re-loads my AddIn which
on the startup puts up a message box saying there is a version mis-match
between Excel and my AddIn and that totally locks up Excel.

I don't think this approach is safe. Is there another way to launch a file
where it either returns to me immediately or I can have a worker thread do it
somehow?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
jialge@online.microsoft.com
11/22/2007 10:35:13 AM
Hello Dave,

I am doing researches on it to see how to use the current version of Excel,
where the add-in is running, to open the excel document, and will get back
to you as soon as possible. But according to the KB article
http://support.microsoft.com/kb/214388/, it is highly not recommended to
run multiple versions of excel on the same computer. The workaround in my
last reply works well if the computer is installed with one version of
Office.

Regards,
Jialiang Ge (jialge@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
David Thielen
11/26/2007 11:47:01 AM
I have a solution that is working. I start a worker thread and that worker
thread launches the application using Process.Start("filename.xlsx") .

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




[quoted text, click to view]
AddThis Social Bookmark Button