office-interop

Determine Excel Version/Culture via Microsoft.Office.Interop.Excel

耗尽温柔 提交于 2019-11-27 15:52:43
How can I achieve that in .NET/C#? yas4891 You could use this code snippet: (taken from one of my projects, so not guaranteed to work out of the box) Microsoft.Office.Interop.Excel.Application tExcel = new Application(); CultureInfo cSystemCulture = Thread.CurrentThread.CurrentCulture; CultureInfo cExcelCulture = new CultureInfo(tExcel.LanguageSettings.get_LanguageID( Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI)); try { Thread.CurrentThread.CurrentCulture = cExcelCulture; double tVersion; bool tParseSucceded = double.TryParse(tExcel.Version, out tVersion); // 12 is the first version

Killing EXCEL.exe Process from C# in a Windows Service

我怕爱的太早我们不能终老 提交于 2019-11-27 15:16:49
问题 I have a windows service that opens up an Excel spreadsheet via the Microsoft.Office.Interop.Excel.Application object. Application xlApp = new Application(); Workbook workbook = xlApp.Workbooks.Open(fileName, 2, false); ... ... workbook.Close(); xlApp.Quit(); I would like to kill the EXCEL.exe process that is left running after it is done working with the workbook. I've tried the following with no success... // This returns a processId of 0 IntPtr processId; GetWindowThreadProcessId(new

Writing to an existing Excel File using c#

*爱你&永不变心* 提交于 2019-11-27 14:14:31
问题 I am trying to open (or create a new xls) Excel file and write some values to it. Although, the program below works just fine if I simply create a new xls file, I encounter the some problem in line **mWorkBook = oXL.Workbooks.Open (path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);** Here's the error: 'LOG.xls' cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only. It

How to fix 'Microsoft Excel cannot open or save any more documents'

牧云@^-^@ 提交于 2019-11-27 12:55:57
问题 I am running C# ASP.NET 4.5 web application on Windows 7 64-bit using IIS 7.5. The application pool it uses has the name 'ASP.NET v4.0' and its identity is ApplicationPoolIdentity. The application uses MS Office Interop (Microsoft Excel 14.0 Object Library). At line wBook = wBooks.Add(Missing.Value); , it throws the following error: Microsoft Excel cannot open or save any more documents because there is not enough available memory or disk space. u2022 To make more memory available, close

How to make correct date format when writing data to Excel

不羁岁月 提交于 2019-11-27 12:37:29
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.EnableAnimations = false; app.EnableAutoComplete = false; app.EnableSound = false; app.EnableTipWizard = false; app

Create Excel files from C# without office [duplicate]

若如初见. 提交于 2019-11-27 12:00:42
This question already has an answer here: How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office? [closed] 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? Adriaan Stander Unless you have Excel installed on the Server/PC or use an external tool (which is possible

Use Office Interop on ASP.net MVC6 website

Deadly 提交于 2019-11-27 09:39:32
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 ? Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component

Why does Microsoft.Office.Interop.Excel.Application.Quit() leave the background process running?

≡放荡痞女 提交于 2019-11-27 09:05:30
The following code leaves a Microsoft Excel background process running, until after my program has exited: var excelApplication = new Application(); var workbooks = excelApplication.Workbooks; var workbook = excelApplication.Workbooks.Open(file.FullName); workbook.Close(); excelApplication.Workbooks.Close(); excelApplication.Quit(); Marshal.ReleaseComObject(workbook); Marshal.ReleaseComObject(workbooks); Marshal.ReleaseComObject(excelApplication); Why? What am I missing? Got it! application.Workbooks != application.Workbooks This property doesn't expose a variable, it generates a value. So

Capturing keydown event of MS Word using C#

ぃ、小莉子 提交于 2019-11-27 08:20:23
问题 I'm trying to develop an office add-on and need to capture the keydown event on MS-Word using C#. can somebody give me an example on how i can do that? 回答1: This looks like a duplicate of: How to get the "KeyPress" event from a Word 2010 Addin (developed in C#)? In that question this answer links to a similar question on the MSDN forum: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/7198a84f-4a37-474b-93b5-1e6f38d5d139. In the accepted answer on the MSDN forum it is stated that:

How to create Microsoft.Office.Interop.Word.Document object from byte array, without saving it to disk?

心已入冬 提交于 2019-11-27 07:50:13
问题 How can I create a Microsoft.Office.Interop.Word.Document object from byte array, without saving it to disk using C#? public static int GetCounterOfCharacter(byte[] wordContent) { Application objWord = new Application(); Microsoft.Office.Interop.Word.Document objDoc = new Document(); //objDoc = objWord.Documents.Open(("D:/Test.docx"); i want to create document from byte array "wordContent" return objDoc.Characters.Count; } 回答1: There is no straight-forward way of doing this as far as I know.