office-interop

Replace Field in Header&Footer in Word Using Interop

帅比萌擦擦* 提交于 2019-11-30 13:52:12
问题 How to replace a "FIELD" in the header/footer? Ex: Word doc file with File Name & Date. in place of file path - [FilePath] instead C://Documents/Location/Filename.doc ,[Date] instead 18/07/2013. I can replace any text with range. foreach (Microsoft.Office.Interop.Word.Section section in wordDocument.Sections) { section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text.Replace(sourceDocPath, "[File Path]"); section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text

Replace Field in Header&Footer in Word Using Interop

我怕爱的太早我们不能终老 提交于 2019-11-30 13:00:51
How to replace a "FIELD" in the header/footer? Ex: Word doc file with File Name & Date. in place of file path - [FilePath] instead C://Documents/Location/Filename.doc ,[Date] instead 18/07/2013. I can replace any text with range. foreach (Microsoft.Office.Interop.Word.Section section in wordDocument.Sections) { section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text.Replace(sourceDocPath, "[File Path]"); section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text.Replace(sourceDocPath, "[File Path]"); } This works fine for The Filename, however for Date, it is not

Office Interop with 64bit Windows in ASP.NET

喜欢而已 提交于 2019-11-30 07:42:51
问题 I'm trying to do office 2003 interop using C# ASP.NET on a server running Windows 2003 64 bit (I'm running IIS in 32bit mode though) and getting error messages like: The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID {00024500-0000-0000-C000-000000000046} to the user domain\username SID (S-X-X-XX-XXX-XXXX-XXX-XXXXX). This security permission can be modified using the Component Services administrative tool. Does anybody

Office Interop Does Not Work in Windows Service

烂漫一生 提交于 2019-11-30 07:39:08
I have a very weird issue with Microsoft Office. I have a common library whose sole purpose is to open whatever word document file type is passed to it (by a full file path...) and save that opened word document as a pdf file. The weird issue is that if I consume that library from a windows service, whenever it attempts to open the word document, I get a null... aka, the word document never got opened. If however I consume the library from a WPF or Windows Form application I never have any issues. I am aware that there are issues with threading, (Single Thread Appartment) however I have no

How can I capture a Microsoft Access VBA debug error from my C# code?

丶灬走出姿态 提交于 2019-11-30 07:30:30
问题 I have a C# program that opens several Microsoft Access files, and executes functions from within each one. Essentially, the code looks something like this: Microsoft.Office.Interop.Access.Application app = new Microsoft.Office.Interop.Access.Application(); app.Visible = true; app.OpenCurrentDatabase(accessFileFullPath, false, ""); //Call the function app.Eval(function); However, when a debug error occurs in the VBA code, I would like to trap it in my C# program. Please don't answer: "trap

support different Office versions with Office Automation

吃可爱长大的小学妹 提交于 2019-11-30 06:49:09
We created an application that uses Office 2007 (Excel 2007) to read in data from an Excel worksheet. However. I noticed that when I want to deploy the application on a system with Office 2003 installed, it crashes because other PIA's (and other dll's) need to be referenced for this version of office. Do I need to compile different versions of my application to be able to support different versions of Office or is there a more elegant solution for this problem? I use Visual Studio 2010 (C#) and the .Net 4.0 platform. As you're using .NET 4, you can use "embedded" PIAs (aka "No PIA"). Change

find all open Excel workbooks

末鹿安然 提交于 2019-11-30 05:34:26
问题 I'm trying to get a list of all currently open Excel workbooks, so that the user can select which one of them to get some data from. I tried this: List<string> excelList = new List<string>(); Process[] processList = Process.GetProcessesByName("excel"); foreach (Process p in processList) { excelList.Add(p.MainWindowTitle); Console.WriteLine(p.MainWindowTitle); } But that only gets the first open instance of Excel and the most recently opened instance, so any workbooks that were opened between

Invoking Word for rtf to docx conversion

旧街凉风 提交于 2019-11-30 05:15:16
问题 I have a need to routinely programmatically convert *.rtf files into *.docx. Manually, this works just fine with Save As inside Word 2007 ... the resulting docx behaves just fine. Programmatically, I can't get it to work. What I tried is basically the following: Fetch RTF from Word ... but in the reverse direction. Instead of opening *.docx and using SaveAs to *.rtf, I'm opening the *.rtf and using SaveAs to *.docx. However, the resulting file won't open, and so evidently there's something I

How to create word docs programmatically from a template

风流意气都作罢 提交于 2019-11-30 04:51:07
I am trying to create about 600 reports in microsoft office Word. The documents are populated with data from a database, and images found on a local drive. I have figured out, that I might create a Word Template project in visual studio 2010, and program the template, so that when you enter a single value (id-number), it automatically fills out the entire document. I am quite confident that this is possible. the only problem is. How do I loop through all entries in the database, open a new document based on the template and set the id-value? for(int i = 0; i < idnumbers.Count(); i++) { Word

Looking up the value for MS Office Interop constants rather than hard coding them

我怕爱的太早我们不能终老 提交于 2019-11-30 04:14:09
问题 Using PowerShell, it is easy enough to create, say, an instance of the Excel Application class and start manipulating it: $app = New-Object -ComObject "Excel.Application" However, if I need to use the constants like xlDoubleQuote or xlDelimited - it seems like I am forced to hard code them. I would really like to be able to do something like: $constants = New-Object -ComObject "Excel.Constants" $constants.xlDoubleQuote And see that it would return the value of 1. Unfortunately I can't create