office-interop

Error reading word doc using Micorsoft.Office.Interop(Object library) via IIS 7

半腔热情 提交于 2019-11-26 17:25:34
问题 Iam facing issue while reading the document when runnning code from IIS. It is not reading the document and throwirng an error "No document is opne when trying to save the activedocument.". m_word.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 missing, ref missing, ref missing, ref missing, ref missing); m_word.ActiveDocument.SaveAs2(ref FileName_rtf, ref FileFormat, ref

Add a row to an MS Word table using Office.Interop

核能气质少年 提交于 2019-11-26 17:24:35
问题 I have a word template with a table that I am populating from a list of strings that I split using tab characters. I do not know how many lines of text I will have as it will vary. So I am adding a row programmatically before iterating through my loop like this: oWordDoc.Tables[2].Rows.Add(oWordDoc.Tables[2].Rows[1]); Unfortunately it is adding the row before rather than after the current row. How can I change my code to always have an empty row added after the current row? 回答1: Leave the

Office automation (Interop) on Windows Server 2012

試著忘記壹切 提交于 2019-11-26 17:11:54
问题 I'm successfully using Office automation on Windows Server 2008 R2 with Office 2007 in order to convert Office documents to PDFs. The code is rather simple: public class WordConvert { /// <summary> /// Converts a word file to PDF /// </summary> /// <param name="sourceFilePath">The path of the word file to convert</param> /// <param name="targetFilePath">The path of the PDF output file</param> public static void ConvertWord(string sourceFilePath, string targetFilePath) { object

Outlook 2007 from C# - COM exception, TYPE_E_LIBNOTREGISTERED

纵饮孤独 提交于 2019-11-26 17:06:37
问题 I'm trying to make a program that would open new Outlook 2007 message. I've referenced from COM tab Microsoft Outlook 12.0 ObjectLibrary. These items showed up in references in VS: Microsoft.Office.Core Microsoft.Office.Inerop.Outlook Now I try to invoke following code: var _outlookInstance = new Microsoft.Office.Interop.Outlook.Application(); var _message = (OutlookApp.MailItem)_outlookInstance.CreateItem(OutlookApp.OlItemType.olMailItem); where OutlookApp==Microsoft.Office.Interop.Outlook

Detecting a password-protected document

*爱你&永不变心* 提交于 2019-11-26 16:08:52
问题 Is there any way to know whether a doc / ppt / xls file is password-protected even before opening the file? 回答1: I have created an utility method that tries to detect if a given office document is protected by a password or not. Here are the list of advantages: supports Word, Excel and PowerPoint documents, both legacy (doc, xls, ppt) and new OpenXml version (docx, xlsx, pptx) does not depend on COM or any other library requires only System, System.IO and System.Text namespaces pretty fast

Create Excel files from C# without office [duplicate]

前提是你 提交于 2019-11-26 15:51:23
问题 This question already has an answer here: How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office? 42 answers I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference. My dev computer has Excel on it, but the end user may or may not have Office installed. Will this tool fail if Office isn't installed on the end users computer, or is this interop service separate from the actual application? 回答1: Unless you have

How to read an excel file in C# without using Microsoft.Office.Interop.Excel libraries

☆樱花仙子☆ 提交于 2019-11-26 15:06:08
I have a .Net-Windows application in C#. I need to open an excel and process it. How can I do this without using Microsoft.Office.Interop.Excel libraries? var fileName = @"C:\ExcelFile.xlsx"; var connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedTypes=Text\""; ; using (var conn = new OleDbConnection(connectionString)) { conn.Open(); var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); using (var cmd = conn

Use Office Interop on ASP.net MVC6 website

大兔子大兔子 提交于 2019-11-26 14:50:14
问题 I want to generate word documents from my ASP.net MVC 6 website. I've implemented several ways to generate a document in a POC : DocX, NetOffice, OpenXml, COM Interop objects. I was seduced by it. I made a Console App to test and it works. But, with ASP.net MVC6, we can't reference Console App's or COM Assemblies. We need to create "Console App (Package)". How can I add COM Assemblies to my ASP.net MVC 6 website ? 回答1: Microsoft does not currently recommend, and does not support, Automation

C# - How to add an Excel Worksheet programmatically - Office XP / 2003

元气小坏坏 提交于 2019-11-26 13:07:06
问题 I am just starting to fiddle with Excel via C# to be able to automate the creation, and addition to an Excel file. I can open the file and update its data and move through the existing worksheets. My problem is how can I add new sheets? I tried: Excel.Worksheet newWorksheet; newWorksheet = (Excel.Worksheet)excelApp.ThisWorkbook.Worksheets.Add( Type.Missing, Type.Missing, Type.Missing, Type.Missing); But I get below COM Exception and my googling has not given me any answer. Exception from

Importing Excel into a DataTable Quickly

大憨熊 提交于 2019-11-26 12:25:26
问题 I am trying to read an Excel file into a list of Data.DataTable, although with my current method it can take a very long time. I essentually go Worksheet by Worksheet, cell by cell, and it tends to take a very long time. Is there a quicker way of doing this? Here is my code: List<DataTable> List = new List<DataTable>(); // Counting sheets for (int count = 1; count < WB.Worksheets.Count; ++count) { // Create a new DataTable for every Worksheet DATA.DataTable DT = new DataTable(); WS = (EXCEL