How to move your mail infrastructure away from Lotus Notes

Friday, 26 December 2014

Excel 2007 automation on top of a Windows Server 2008 x64

Excel 2007 automation on top of a Windows Server 2008 x64:



'via Blog this'



’m well aware of the Microsoft support base article stating that it’s not supported to automate office products UI less. It seems that Windows Server 2008 and Excel 2007 enforce the given statement.
I’m running the following code in a NT Service (Local System account) OnStart method. All it does is Excel automation the way it’s working when you run the same code in a Console Application.
The provided code has two parts. The first part launches Excel, creates a new work book and saves it to the given filename. The second part launches a new instance of Excel and opens the given file. The open operation ends in this exception:
Service cannot be started. System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot access the file 'c:\temp\test.xls'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
Why was the automated excel able to launch and write files to disk but fails when it’s asked “just “ to open an existing file? 
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            // launch excel and create/save a new work book
            Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.UserLibraryPath, excel.Interactive));
            //           
            string filename = "c:\\temp\\test.xls";
            if(System.IO.File.Exists(filename)) System.IO.File.Delete(filename);
            //
            excel.Workbooks.Add(System.Reflection.Missing.Value);
            excel.Save(filename);
            excel.Quit();
            excel = null;
            // lauch new instance of excel and open saved file
            excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
            try
            {
                Microsoft.Office.Interop.Excel.Workbook book = excel.Workbooks.Open(filename,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    true,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value,
                    false,
                    false,
                    System.Reflection.Missing.Value,
                    false,
                    System.Reflection.Missing.Value,
                    System.Reflection.Missing.Value);
                book.Close(false, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
                book = null;
            }
            finally
            {
                excel.Quit();
                excel = null;
            }
            //
            GC.Collect();


Chris Richner http://www.raccoom.net





Hi,
I was running into the same issue and
I have investigated infomation about "registry hack".
After all, I found another solution that changes no registry values
 and everything works on properly.
This solution is ...
・Windows 2008 Server x64

  Please make this folder.
  C:\Windows\SysWOW64\config\systemprofile\Desktop
・Windows 2008 Server x86
  Please make this folder.
  C:\Windows\System32\config\systemprofile\Desktop
  ...instead of dcomcnfg.exe.
This operation took away office automation problems in my system.
A Desktop folder seems to be necessary in the systemprofile folder to open file by Excel.
It disappears from Windows2008, Windows2003 had the folder,
and I think it cause this error.
I think it is safer than "registry hack".
If you try this solution, please let me know results.

Ogawa

0 comments :

Post a Comment

Thank you for taking the time to comment. Your opinion is important and of value and we appreciate the positive feedback! If you are "Negative Nancy" then please do us, and humanity, a favor, and piss off.

Total Pageviews

Google+ Followers

Pages

Blog Archive

Popular Posts

Recent Comments

Rays Twitter feed

Ads

Web sites come and go and information is lost and therefore some pages are archived. @rayd123 . Powered by Blogger.