office-interop

Is it possible to store hidden metadata information that is tied to a specific Table or Cell within a Word document?

◇◆丶佛笑我妖孽 提交于 2019-12-04 08:03:13
I am trying to store metadata (basically a unique id) along with each cell of a table in a Word document. Currently, for the add-in I'm developing, I am querying the database, and building a table inside the Word document using the data that is retrieved. I want to be able to save any of the user's edits to the document, and persist it back to the database. My initial thought was to store a unique id along with each cell in the table so that I would be able to tell which records to update. I would also like to store some sort of "isChanged" flag within each cell so that I could tell which

Formatting a plain text e-mail in C#

浪子不回头ぞ 提交于 2019-12-04 07:13:07
问题 I am trying to print a table inside an e-mail using plain text. I have the following code: string body = string.Format("{0,-30}{1,-30}{2,-50}{3,-40}", "Col1", "Col2", "Col2", “Col4”); body += string.Format("{0,-30}{1,-30}{2,-50}{3,-40}", value1, value2, value3, value4); Microsoft.Office.Interop.Outlook.ApplicationClass myOutlookApplication = null; myOutlookApplication = new Microsoft.Office.Interop.Outlook.ApplicationClass(); Microsoft.Office.Interop.Outlook.MailItem myNewMail = (Microsoft

How do I merge multiple excel files to a single excel file

纵饮孤独 提交于 2019-12-04 06:50:20
问题 So I was trying to make an excel sheet aggregator. In my line of work we get people who send us a bunch of individual excel files that are all related each with only 1 sheet used. I was following to some degree this previous post's ideas. But upon doing so, some of the excel sheets I copied were coming up blank. Only certain ones. I have no idea why some are blank and others are fine. Here is the code I use to open and copy the excel files OpenFileDialog browse = new OpenFileDialog(); browse

How to programmatically create a powerpoint from a list of images

半世苍凉 提交于 2019-12-04 06:48:40
I've seen this question: Creating PowerPoint presentations programmatically , but that question asks "Can you?" to which the answer is "yes". But I'm asking "How?" and specifically "From a list of images?" Here's what I do to break a ppt up into images var app = new PowerPoint.Application(); var pres = app.Presentations; var file = pres.Open(input, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); file.SaveAs(output, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue); file.Close(); app.Quit(); How do I do the reverse? It'll be something like

How to load Word document from byte array

。_饼干妹妹 提交于 2019-12-04 06:08:23
I have the whole MS Word file itself saved into a byte array.A want to load it the way I would if it was on file system but with the minimal use of Microsoft.Office.Interop.Word because it is very slow when it gets the the .Open(args[]) part. Try this.... byte[] bte = File.ReadAllBytes("E:\\test.doc"); // Put the Reading file File.WriteAllBytes(@"E:\\test1.doc", bte); // Same contents you will get in byte[] and that will be save here There is no supported way to do it right off-the-bat using Interop.Word , as there are no methods supporting byte arrays. As a viable workaround you can use a

How to open Excel-workbooks without the message The workbook contains links to other data sources. programmatically?

让人想犯罪 __ 提交于 2019-12-04 05:50:27
问题 I want to open 1 or more Excel-workbooks programmatically. And when I open the workbook, you get a question: The workbook contains links to other data sources. And I don't want press " Don't update " How can you leave this messagebox? So the functionality will not interrupted anymore. Updating is not needed. 回答1: try placing in the workbook Open event handler: Application.AskToUpdateLinks = False 回答2: I don't think you can get around the dialogs with the excel interop libraries (the warnings

How to set the file name of a word document without saving it from c# and automation

橙三吉。 提交于 2019-12-04 03:59:07
问题 I create word documents via automation and mailmerge with office Interop from c# (.net4). The merge works well and the user receives the created document as he desires. So far all is well. The client now requests, that if he tries to save the generated file (via save file dialog), that the filename of the document is already prefilled. I already have tried the obvious things such as setting the Name property of the Document-instance and other properties, I also googled for a solution but up

“You are not allowed to edit this selection because it is protected.” but only since Office 2013?

£可爱£侵袭症+ 提交于 2019-12-04 02:57:29
We've had these few lines of code running happily in our applications for several years (and in several versions of Office, 2003, 2007, 2010 etc). Purpose is to perform a kind of a mail merge in a Word document, substituting the field placeholders with names, addresses etc from a database: Dim w As Word.Application Dim d As Microsoft.Office.Interop.Word.Document = Nothing ... Dim f As Microsoft.Office.Interop.Word.Field For Each f In d.Fields f.Select() If fieldName = w.Selection.Text Then f.Result.Text = value End If Next However a user running Office 2013 reports this error on the line f

C# Create Excel workbook with 1 sheet by default

孤街浪徒 提交于 2019-12-04 01:48:46
I'm trying to create an Excel file with C# COM interop but seems it create it by default with 3 sheets instead of empty or only one. What is needed to create it Empty or just with one: Excel.Application xl = null; Excel._Workbook wb = null; // Create a new instance of Excel from scratch xl = new Excel.Application(); xl.Visible = true; wb = (Excel._Workbook)(xl.Workbooks.Add(Missing.Value)); wb.SaveAs(@"C:\a.xls", Excel.XlFileFormat.xlWorkbookNormal, null, null, false, false, Excel.XlSaveAsAccessMode.xlShared, false, false, null, null, null); Take a look at MSDN's explanation of Workbooks.Add

Setting an Outlook mailitem's category programmatically?

最后都变了- 提交于 2019-12-04 01:09:23
There doesn't seem to much information or any good code samples for setting an Outlook 2007 MailItem's categories programmatically. MSDN has a limited page , and mentions using VB's Split function, saying more or less " you're on your own from here onwards, so sort it out yourself ". So far as I can tell we manipulate the Categories as a comma delimited string property of the mailitem. It seems a bit primitive, is that all there is to it? Does everyone just dig out their library of string functions and parse the Categories property, trusting not to get in a muddle when multiple categories are