office-interop

Fastest way to get an Excel Range of Rows

烂漫一生 提交于 2019-11-27 03:28:51
问题 In a VSTO C# project I want to get a range of rows from a set of row indexes. The row indexes can be for example like "7,8,9,12,14". Then I want the range "7:9,12,14" rows. I now do this: Range rng1 = sheet.get_Range("A7:A9,A12,A14", Type.Missing); rng1 = rng1.EntireRow; But it's a bit inefficient due to string handling in range specification. sheet.Rows["7:9"] works but I can't give this sheet.Rows["7:9,12,14"] // Fails 回答1: Try this: Sheet.Range("7:9,12:12,14:14") EDIT: Sorry if using VSTO

c# word interop find and replace everything

隐身守侯 提交于 2019-11-27 01:41:20
问题 I have some code to replace text inside a word 2010 docx. object fileName = Path.Combine(System.Windows.Forms.Application.StartupPath, "document.docx"); Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true }; Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true); aDoc.Activate(); Microsoft.Office.Interop.Word.Find fnd = wordApp.ActiveWindow.Selection.Find; fnd

What reference do I need to use Microsoft.Office.Interop.Excel in .NET?

非 Y 不嫁゛ 提交于 2019-11-27 00:16:01
I am interested in using C# to manipulate/Automate Excel files. After browsing the web I have found VSTO but it seems you can not use that in Visual Studio Express Edition so I can not use that. Just few minutes ago I noticed a question in this site that used this namespace in its code: Microsoft.Office.Interop.Excel So I am wondering if all I need to use that is add necessary reference and if so which reference to add? UPDATE I installed "Primary Interop Assemblies" as the accepted answer suggested but for some reason they are still missing in the Add Reference dialog under ".NET" but they

The quest for the Excel custom function tooltip

女生的网名这么多〃 提交于 2019-11-26 23:36:34
This question has been asked before , but each time the accepted answer is simply a resignation to provide function descriptions using Application.MacroOptions ( VBA6 ) ( VBA7 ), but this information does not actually appear as a tooltip, so it does not solve my problem. The Goal What we all desire is to be able to define custom functions by any means (VBA, VSTO, or COM add-in) and give the user the benefit of a pop-up/tool-tip description of the function and its parameters, as appears for every built-in Excel function, either inline or in the formula bar: The widely accepted answer to this

How can I quickly up-cast object[,] into double[,]?

a 夏天 提交于 2019-11-26 22:52:00
I using Microsoft.Office.Interop.Excel I get returned a 2D array of type object[,] which contains double for elements. Note that the index lower bound is 1 instead of the default 0 , but I can deal with that easily. How can nicely convert the array into double[,] using .NET 3.5. (by nicely I mean concise, or compact). Note that double[] values_2 = values.Cast<double>().ToArray(); does work, but it flattens by array into a 1D structure. object[,] src = new object[2, 3]; // Initialize src with test doubles. src[0, 0] = 1.0; src[0, 1] = 2.0; src[0, 2] = 3.0; src[1, 0] = 4.0; src[1, 1] = 5.0; src

How to add items one at a time to to a new line a word document using word interop

流过昼夜 提交于 2019-11-26 21:37:06
问题 I am trying to add these three types of content into a word doc. This is how I am trying to do it now. However, each item replaces the last one. Adding images always adds to the beginning of the page. I have a loop that calls a function to create the headers and tables, and then adds images after. I think the problem is ranges. I use a starting range of object start = 0; How can I get these to add one at a time to to a new line in the document? foreach (var category in observedColumns) {

Alternative to Office Interop for document generation

依然范特西╮ 提交于 2019-11-26 20:45: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

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

家住魔仙堡 提交于 2019-11-26 19:50:38
问题 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

Accessing Office Word object model through asp.net results in “failed due to the following error: 80070005 Access is denied.”

拥有回忆 提交于 2019-11-26 19:43:22
I have developed a website that allows users to upload office documents then uses the office object model to convert the document to an HTML file that it then displays in an iFrame. I have, of course, included references to Office.interop.word, and the site works fine on my development machine. When I uploaded it to my production server the site functions fine until I try to upload a document. I initially got a similar error that said "COM object not registered". I realized that Word wasn't installed on my production server. So I installed word and now when the server tries to access the word

How to make correct date format when writing data to Excel

岁酱吖の 提交于 2019-11-26 17:41:49
问题 Iam exporting a DataTable to an Excel-file using office interop. The problem is, that Excel does not recognize dates as such, but instead it displays numbers. In another case I pass a string which it then recognizes as a date. In both cases the data is messed up. I tried NumberFormat @ which is supposed to store the cell in text format, but it didn't work either. Application app = new Application(); app.Visible = false; app.ScreenUpdating = false; app.DisplayAlerts = false; app