office-interop

`EOleException: Call was rejected by callee` while iterating through `Office.Interop.Word.Documents`

半世苍凉 提交于 2020-01-03 01:10:46
问题 I've been working with Word2010.pas for the past week and everything went well, until I found out that if you open a document manually , edit it (but don't save), press Alt+F4 , a prompt will show up saying if you want to save your document or not, leave it like that. Go into code and try to access that document , all calls will result in EOleException: Call was rejected by callee . Once you cancel that Word save prompt, everything works fine. I came across this while writing code that

`EOleException: Call was rejected by callee` while iterating through `Office.Interop.Word.Documents`

限于喜欢 提交于 2020-01-03 01:10:21
问题 I've been working with Word2010.pas for the past week and everything went well, until I found out that if you open a document manually , edit it (but don't save), press Alt+F4 , a prompt will show up saying if you want to save your document or not, leave it like that. Go into code and try to access that document , all calls will result in EOleException: Call was rejected by callee . Once you cancel that Word save prompt, everything works fine. I came across this while writing code that

How should I declare a Microsoft.Office.Interop.Excel.Worksheet so I can close it in C#?

天涯浪子 提交于 2020-01-02 20:18:08
问题 I am having a hard time making sure my COM objects are closing so I am not leaving an EXCEL.EXE process running in the background. I have learned that the double dot and chaining of declarations is bad as this could leave COM objects hanging around. Does anyone know how to fix this line of code so I can properly close and release the worksheet COM object? worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[strName]; EDIT: I have tried using app.Quit() when I am done

Microsoft Word Interop automation FilePrintSetup Error

北慕城南 提交于 2020-01-02 09:56:07
问题 I am getting "There is a printer error." when tying to send a print job to a printer using automation on Windows 7 with Word 2010. Same code works fine on Windows XP box with Word 2007. I am not sure if Windows 7 or word 2010 is causing the error. Any help appreciated using Microsoft.Office.Interop.Word; ..... object oWordbasic = wordDoc.Application.WordBasic; object[] argValues = new object[] { value, 1 }; //first arg is a printer name String[] argNames = new String[] { "Printer",

Filling Word template fields with C#

跟風遠走 提交于 2020-01-02 05:23:44
问题 Currently, if I create a Word Document Template with fields, and then fill them using C#, I do it similar to this... object missing = Type.Missing; Word.Application app = new Word.Application(); Word.Document doc = app.Documents.Open("file.doc", ref missing, true); Word.FormFields fields = doc.FormFields; fields[2].Result = "foo" fields[3].Result = "bar" Is there a better way to reference the fields? I notice when creating the template I can add a Title and a Tag to the field, but I haven't

Changing font (Trebuchet MS, Calibari) in Excel programmatically C#

孤街浪徒 提交于 2020-01-02 04:43:08
问题 I am currently working in a C# application which has a class which will generate an excel file. Everything went smooth. The data populated on the excel sheet has 'Times New Roman' has font. I would like to change it to some other fonts (Calibari). How can I do that programmatically. 回答1: Here is how: //Declare Excel Interop variables Microsoft.Office.Interop.Excel.Application xlApp; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; /

programmatically excel cells to be auto fit width & height

时间秒杀一切 提交于 2020-01-02 01:20:13
问题 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? 回答1: Try getting the range and then do Autofit Range.Rows.AutoFit(); Range.Columns.AutoFit(); 回答2: This questions just helped me to solve part of a problem. I had to copy the data to a

Adding Shapes to a New Visio Document

我的梦境 提交于 2020-01-01 06:08:35
问题 I have this code that creates a new Visio document and adds a rectangle. It works, but I don't like having to open another document to get the Masters collection from it. The issue is the new document has an empty Masters shape collection. I couldn't find a method in the Document class to add shapes to the Masters collection and all the examples I could find for adding shapes assumed you had an existing document. Is there a better way to do what I want? // create the new application Visio

Adding Shapes to a New Visio Document

▼魔方 西西 提交于 2020-01-01 06:06:08
问题 I have this code that creates a new Visio document and adds a rectangle. It works, but I don't like having to open another document to get the Masters collection from it. The issue is the new document has an empty Masters shape collection. I couldn't find a method in the Document class to add shapes to the Masters collection and all the examples I could find for adding shapes assumed you had an existing document. Is there a better way to do what I want? // create the new application Visio

Using Microsoft Office Interop to create and parse Excel spreadsheets from ASP.NET

瘦欲@ 提交于 2020-01-01 00:53:31
问题 I have a new ASP.NET MVC project that has two requirements that require using the Office Interop DLLs to generate Excel spreadsheet files in Excel 2003 format by combining several template files into a multi-sheet workbook and to parse these files once filled in. The files we parse may come back in Excel 2003, 2007 or 2010 format (I believe 2007 and 2010 file formats are identical but feel free to correct me on that). I'd be much happier if we could convince the (internal) clients to drop