office-interop

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

…衆ロ難τιáo~ 提交于 2019-11-29 04:31:17
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] 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 underneath. In my case I didn't actually want mail folders so I exclude them. Const BACKUP_PST_PATH As

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

孤人 提交于 2019-11-29 04:27:40
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 the error in your VBA program". For reasons that I will not get into, this is not possible. A method that

How to create word docs programmatically from a template

穿精又带淫゛_ 提交于 2019-11-29 02:52:06
问题 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

Spell Checking in C# Using Word Interop

我的未来我决定 提交于 2019-11-29 02:34:56
I am writing a spell check application in C# using word.dll (the Word Interop API). I want to check which spellings are incorrect and accordingly get suggestions for the incorrect words. I got a sample code from the net and I cannot understand the parameters for the following command: Microsoft.Office.Interop.Word._Application.GetSpellingSuggestions (string, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object, ref object) I would just like to know what do all the ref object s imply? I want to know their

disabling overwrite existing file prompt in Microsoft office interop FileSaveAs method

感情迁移 提交于 2019-11-29 02:02:17
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. dotNetkow 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 this: Microsoft.Office.Interop.MSProject.Application msProjectApp = new Microsoft.Office.Interop

C# Excel Interop Slow when looping through cells

徘徊边缘 提交于 2019-11-28 23:56:18
I am trying to extract all text data from an Excel document in C# and am having performance issues. In the following code I open the Workbook, loop over all worksheets, and loop over all cells in the used range, extracting the text from each cell as I go. The problem is, this takes 14 seconds to execute. public class ExcelFile { public string Path = @"C:\test.xlsx"; private Excel.Application xl = new Excel.Application(); private Excel.Workbook WB; public string FullText; private Excel.Range rng; private Dictionary<string, string> Variables; public ExcelFile() { WB = xl.Workbooks.Open(Path); xl

Killing EXCEL.exe Process from C# in a Windows Service

纵饮孤独 提交于 2019-11-28 23:49:43
I have a windows service that opens up an Excel spreadsheet via the Microsoft.Office.Interop.Excel.Application object. Application xlApp = new Application(); Workbook workbook = xlApp.Workbooks.Open(fileName, 2, false); ... ... workbook.Close(); xlApp.Quit(); I would like to kill the EXCEL.exe process that is left running after it is done working with the workbook. I've tried the following with no success... // This returns a processId of 0 IntPtr processId; GetWindowThreadProcessId(new IntPtr(xlApp.Hwnd), out processId); Process p = Process.GetProcessById(processId.ToInt32()); p.Kill();

Writing to an existing Excel File using c#

て烟熏妆下的殇ゞ 提交于 2019-11-28 22:07:33
I am trying to open (or create a new xls) Excel file and write some values to it. Although, the program below works just fine if I simply create a new xls file, I encounter the some problem in line **mWorkBook = oXL.Workbooks.Open (path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);** Here's the error: 'LOG.xls' cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only. It's not read-only, it's not corrupted(because sometime the file is created on Run Time). What is the

Cannot debug or run Word AddIn because the required version of Microsoft Office is not installed

旧时模样 提交于 2019-11-28 19:42:54
问题 I need to work on an existing Word 2007 addIn project that's a part of a MSVS 2008 solution. However, when I try to debug the addIn, I get the following error message: "You cannot debug or run this project, because the required version of the Microsoft Office application is not installed". I have Office 2007 installed. I tried creating a new Word 2007 addIn project in the same solution, and I have no problem debugging it. As far as I can tell, all the referenced Office assemblies are the same

Fastest way to write cells to Excel with Office Interop?

浪尽此生 提交于 2019-11-28 19:38:46
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? You should avoid reading and writing cell by cell if you can. It is much faster to work with arrays, and read or write entire blocks at once. I wrote a post a while back on reading from worksheets using C