office-interop

Outlook 2007 from C# - COM exception, TYPE_E_LIBNOTREGISTERED

江枫思渺然 提交于 2019-11-28 00:03:02
I'm trying to make a program that would open new Outlook 2007 message. I've referenced from COM tab Microsoft Outlook 12.0 ObjectLibrary. These items showed up in references in VS: Microsoft.Office.Core Microsoft.Office.Inerop.Outlook Now I try to invoke following code: var _outlookInstance = new Microsoft.Office.Interop.Outlook.Application(); var _message = (OutlookApp.MailItem)_outlookInstance.CreateItem(OutlookApp.OlItemType.olMailItem); where OutlookApp==Microsoft.Office.Interop.Outlook namespace. While invoking second line of listing I keep getting this exception: (InvalidCastException)

How to expose a C# class to a VBA module in a document-level add-in?

*爱你&永不变心* 提交于 2019-11-27 23:53:09
问题 This is a hypothetical situation. I would like to find out if it's possible to expose a C# class to VBA in a document-level add-in. Here's an SSCCE: In VS PRO 2012 I have started a new project, Selected Office -> Excel 2010 Workbook. (make sure you select .Net framework ver 4) I have added a DateTimePicker control to Sheet1. I can set/get the .Value property off the DateTimePicker control within the C# solution without a problem. While debugging: In VBA, the .Value property is not exposed. (

How to eliminate warning about ambiguity?

我怕爱的太早我们不能终老 提交于 2019-11-27 22:38:46
I have this warning: Warning 3 Ambiguity between method 'Microsoft.Office.Interop.Word._Application.Quit(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit'. Using method group. on my line wordApplication.Quit(); I have tried replacing it with: wordApplication.Quit(false); // don't save changes and wordApplication.Quit(false, null, null); // no save, no format but it keeps giving me this warning. It's not a huge problem because the code compiles perfectly and functions as expected, but I'd like to get rid of the warnings. What can I

Problems with office automation in asp.net. I can use alternatives such as open-office, if I knew how

谁都会走 提交于 2019-11-27 22:31:47
问题 I have a ASP.NET 2.0 web application that should upload a ppt file and then extract its slides to images. For that I have imported office.dll and Microsoft.Office.Interop.PowerPoint.dll assemblies and wrote the following code public static int ExtractImages(string ppt, string targetPath, int width, int height) { var pptApplication = new ApplicationClass(); var pptPresentation = pptApplication.Presentations.Open(ppt, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse); var slides

disabling overwrite existing file prompt in Microsoft office interop FileSaveAs method

☆樱花仙子☆ 提交于 2019-11-27 21:46:43
问题 I am using Ms Office Interop assemblies to create a MS Project file. To save the file created, I am using FileSaveAs method and it prompts a message saying that if you want to replace the existing file. I want to suppress the message, and I didn't find any parameter in FileSaveAs method for this purpose. Any Idea on this? I'am using C# as my programming language. 回答1: I ran into this issue when working with Excel Interop. The best I've been able to find is to disable all Office alerts, like

Alternative to Office Interop for document generation

旧巷老猫 提交于 2019-11-27 21:37:06
At the moment we're using office interop to generate documents from templates in office 2003 (word, excel & powerpoint). This seems to be rather frowned upon (see office-interop-with-64bit-windows-in-asp-net ) and whilst it works fine I would be happier with a supported solution. What non hacky method is there to do this? Requirements are Office 2003 only. (No office xml / office 2007 compatability pack allowed) Must run server side from ASP.NET Must be able to create Word, Excel & Powerpoint documents from user supplied .dot, .xlt and .pot templates Must be able to further customise the

Fastest way to write cells to Excel with Office Interop?

大兔子大兔子 提交于 2019-11-27 20:34:06
问题 I am writing a function to export data to Excel using the Office Interop in VB .NET. I am currently writing the cells directly using the Excel worksheet's Cells() method: worksheet.Cells(rowIndex, colIndex) = data(rowIndex)(colIndex) This is taking a long time for large amounts of data. Is there a faster way to write a lot of data to Excel at once? Would doing something with ranges be faster? 回答1: You should avoid reading and writing cell by cell if you can. It is much faster to work with

Detecting a password-protected document

青春壹個敷衍的年華 提交于 2019-11-27 19:52:33
Is there any way to know whether a doc / ppt / xls file is password-protected even before opening the file? This might help.. http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/34701a34-f1d4-4802-9ce4-133f15039c69 I have created an utility method that tries to detect if a given office document is protected by a password or not. Here are the list of advantages: supports Word, Excel and PowerPoint documents, both legacy (doc, xls, ppt) and new OpenXml version (docx, xlsx, pptx) does not depend on COM or any other library requires only System, System.IO and System.Text namespaces pretty

Does *every* Excel interop object need to be released using Marshal.ReleaseComObject?

試著忘記壹切 提交于 2019-11-27 19:21:06
Edit Please see also How do I properly clean up Excel interop objects? . I recently came across this question, and it provided a lot of insight into the problem of how to properly dispose of COM objects. Definitely check beyond the first (marked) answer, because the other answers go beyond the simple "don't use two dots" and "use ReleaseComObject for every com object" advice. I revisited this question in the first place because I realized that, despite being very thorough about registering and disposing all my COM objects, my Excel instances still weren't being properly disposed. It turns out,

How can I create an Outlook PST file using .Net?

老子叫甜甜 提交于 2019-11-27 18:19:18
问题 I'm writing an app that will manipulate Outlook data. I want to make a backup of that data first and am hoping I could just loop through the contact/calendar items, etc and write them out to a PST file. How can I write the contents of 1 or several Outlook folders to a PST using .Net? [vb or c# no matter] 回答1: I was able to piece this code together from a variety of samples around the internet and MSDN docs. This will allow you to choose an outlook high level folder and will backup all folders