office-interop

How to print a docx to a specific printer using Microsoft.Office.Interop.Word.Document.PrintOut()

大兔子大兔子 提交于 2019-12-05 02:07:36
This seems like such a simple need, but for some reason I cannot find how I can accomplish this. I have code like this: Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); MemoryStream documentStream = getDocStream(); FileInfo wordFile = new FileInfo("c:\\test.docx"); object fileObject = wordFile.FullName; object oMissing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Document doc = wordInstance.Documents.Open(ref fileObject, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref

programmatically excel cells to be auto fit width & height

ε祈祈猫儿з 提交于 2019-12-05 02:01:17
when i convert datatable to .csv my excel sheets are generated as below: and tried like below: sw.Write(string.Format("=\"{0}\"", drow[i].ToString())); then my excel sheets were like: note that cells have =" " characters; i'm trying to do like auto fit width & height of each cells programmatically. How? Try getting the range and then do Autofit Range.Rows.AutoFit(); Range.Columns.AutoFit(); This questions just helped me to solve part of a problem. I had to copy the data to a secondary, auxiliary sheet, then send it to the datagrid, but when I did, it would display in the datagrid the sequence

How to connect to outlook 2010 while its running in c#?

无人久伴 提交于 2019-12-05 01:39:29
What I am trying to do is add an "Email To..." button to a winform client that opens a new outlook mail window and attaches a file so the user can forward it. I can get the outlook integration working just fine if outlook is not already running. This is a C# .NET 4.0 winforms app, using the Outlook 14.0 interop library, against Outlook 2010 32 bit running on windows 7 64 bit machine. I have the app already compiled to x86 for other reasons so I doubt its a 32/64 bit issue. Here is my code: // Connect to outlook and create a new mail item var app = new Outlook.Application(); var ns = app

VSTO custom taskpane on multi DPI system shows content twice

若如初见. 提交于 2019-12-05 00:11:53
I am building an office addin using VSTO. On systems with multiple monitors with different DPI settings, the contents of my custom task pane is drawn twice on the monitor with the higher DPI settings: Only the smaller version is actually responding to user input. The larger version seems to be simply an upscaled image. I have tried playing around with diverse DPI related settings like: AutoScaleMode on my user control. I tried all options, no change. Setting the process to DPI aware - or not - using SetProcessDpiAwareness . I tried all options, no change. Using an app.manifest and setting

Programmatically set Outlook 2013 Signature Defaults?

坚强是说给别人听的谎言 提交于 2019-12-04 23:45:06
问题 Is it possible to programmatically set the Outlook 2013 Default Signature settings? We can generate the user's signature OK but would like to also set the signature to appear by default in user's emails: The setting itself seems to be tucked-away in the Registry under an Outlook profile: HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Profiles\Outlook\9375CFF0413111d3B88A00104B2A6677\00000002 Reg Values: New Signature Reply-Forward Signature ... (which have binary data, presumably

Why doesn't Word “come to front” when we activate it?

馋奶兔 提交于 2019-12-04 21:17:57
问题 Our winforms application interacts with MS Word and we run this code when a document is generated and we want to show it in Word in front of our application: [setup w as a Word interop object] w.Visible = True w.Activate() When rolled out to XP machines running Office 2007 this works as intended. On Win7 machines running Office 2010 the document loads behind our application and flashes on the taskbar. Any ideas? 回答1: I stumbled upon a similar problem recently. My .NET program called a COM

Automating MS Word in Server 2012 R2

穿精又带淫゛_ 提交于 2019-12-04 19:34:11
问题 Firstly, please don't reply with the generic advice not to automate Word on a server or a link to the MS web page on "how to automate word on a server if you really must". I am aware of this. I have a process which runs as a Windows service and uses .Net OLE interop to automate Office (mostly just Open and SaveAs). This code has worked reliably for 8 years on literally hundreds of servers using many combinations of Windows and Office versions, both 32 and 64 bit, so I am happy that the

Print word document using c#

て烟熏妆下的殇ゞ 提交于 2019-12-04 16:20:33
I have this code to open a word file int num = 0; object fileName = FD.FileName; object readOnly = false; object isVisible = false; object missing = System.Reflection.Missing.Value; Word.Application WordApp = new Word.Application(); Word.Document aDoc = null; WordApp.Visible = false; aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages; num = aDoc

How to connect to a running instance of outlook from C# [duplicate]

好久不见. 提交于 2019-12-04 11:46:03
This question already has answers here : Getting/Creating an Outlook Application in Windows 7 (5 answers) Closed 5 years ago . In VBA, I usually use appOutlook = GetObject(, "Outlook.Application") to get a running instance of Outlook, and it throws an error if Outlook isn't running. I normally did this in excel, but now I am wanting to see if I can get better results by moving to C# and doing it from there. What I need to do is copy emails from outlook and paste them into excel so that the tables in the email get pasted into the spreadsheet as cell values rather than html. However, I'm not

How : Adding Multi tables on Word with .net

只愿长相守 提交于 2019-12-04 09:47:11
问题 I try to add multi tables within a word document using c# // Tables is a list of items which I want to present each in a table foreach (List<string[]> ClassTable in Tables) { // tbl is a "Microsoft.Office.Interop.Word.Table" // myRange is like MyDoc.Range(ref missing, ref missing) tbl = MyDoc.Tables.Add(myRange, ClassTable.Count(), 3, missing, missing); tbl.Borders.Enable = 1; RowCounter = 1; foreach (string[] item in TableContent) { ColumnCounter = 1; foreach (string str in item) { tbl.Cell