C#Unstable writing to startup Excel (Interop, Excel 2010)

Asked 2 years ago, Updated 2 years ago, 68 views

Please let me know if anyone knows.
Currently under development, "Transcribe values retrieved from DB"
to startup Excel There is a function called .
There are times when I can write without any problems, but the behavior is unstable and
You may or may not be able to transfer.

Because operations using this feature are often urgent,
The instability needs to be resolved, so I'm in trouble.
The environment is Windows 7 Professional, Excel 2010 C# Visualstudio 2012.

The boot method uses the following:
Marshall.GetActiveObject("Excel.Application")

c# excel

2022-09-30 18:22

2 Answers

I don't know just by the content of your question, but I thought it might be a problem of missing the release.

Because COM objects are reference counter methods, missing releases can cause instability in subsequent operations.

After missing the release, invisible Excel application instances (hereinafter abbreviated as EAI) will remain, so even if the EAI appears to be running, there will actually be multiple EAIs.In this situation, it is not guaranteed which EAI the GetActiveObject will return, so the results of the operation to EAI will not be reflected on Excel with the screen.


2022-09-30 18:22

The cause was discovered and solved.
The problem was the behavior when multiple excels were started.
GetActiveObject said it is only valid if there is only one Excel running.

http://qa.atmarkit.co.jp/q/4634
I was able to solve this problem by searching ROT by referring to the above URL.
Thank you to everyone who responded despite your busy schedule.


2022-09-30 18:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.