excel-interop

extract image from word file

核能气质少年 提交于 2019-11-27 04:43:48
I have been trying the following C# code to extract image from the doc file but it is not working: object missing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document oDoc = new Microsoft.Office.Interop.Word.Document(); oWord.Visible = false; object str1 = "C:\\doc.doc"; oDoc = oWord.Documents.Open(ref str1, 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,

How to access an already opened Excel file in C#?

为君一笑 提交于 2019-11-27 03:32:31
问题 I have an excel workbook opened via double-clicking it in windows explorer but cannot access it in code Excel.Application xlApp = (Application)Marshal.GetActiveObject("Excel.Application"); Excel.Workbooks xlBooks = xlApp.Workbooks; xlBooks.Count equals 0, why isn't it referencing my opened workbook? EDIT Here are the various scenarios and what is happening: Scenario 1: If the file is not already open Code opens workbook, I am happy. Scenario 2: If the file is initially opened from code and I

How do I auto size columns through the Excel interop objects?

流过昼夜 提交于 2019-11-27 03:31:26
Below is the code I'm using to load the data into an Excel worksheet, but I'm look to auto size the column after the data is loaded. Does anyone know the best way to auto size the columns? using Microsoft.Office.Interop; public class ExportReport { public void Export() { Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application(); Excel.Workbook wb; Excel.Worksheet ws; Excel.Range aRange; object m = Type.Missing; string[,] data; string errorMessage = string.Empty; try { if (excelApp == null) throw new Exception("EXCEL could not be started."); // Create the workbook and

Optimal way to Read an Excel file (.xls/.xlsx)

老子叫甜甜 提交于 2019-11-27 00:12:34
I know that there are different ways to read an Excel file: Iterop Oledb Open Xml SDK Compatibility is not a question because the program will be executed in a controlled environment. My Requirement : Read a file to a DataTable / CUstom Entitie s (I don't know how to make dynamic properties/fields to an object[column names will be variating in an Excel file]) Use DataTable/Custom Entities to perform some operations using its data. Update DataTable with the results of the operations Write it back to excel file . Which would be simpler. Also if possible advice me on custom Entities (adding

How do I import from Excel to a DataSet using Microsoft.Office.Interop.Excel?

谁都会走 提交于 2019-11-27 00:06:45
What I want to do I'm trying to use the Microsoft.Office.Interop.Excel namespace to open an Excel file (XSL or CSV, but sadly not XSLX) and import it into a DataSet. I don't have control over the worksheet or column names, so I need to allow for changes to them. What I've tried I've tried the OLEDB method of this in the past, and had a lot of problems with it (buggy, slow, and required prior knowledge of the Excel file's schema), so I want to avoid doing that again. What I'd like to do is use Microsoft.Office.Interop.Excel to import the workbook directly to a DataSet, or loop through the

Export the dataGridView to Excel with all the cells format

旧时模样 提交于 2019-11-26 22:34:58
I have this code that I know that it works fast CopyAlltoClipboard(dataGridViewControl); Microsoft.Office.Interop.Excel.Application xlexcel; Microsoft.Office.Interop.Excel.Workbook xlWorkBook; Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlexcel = new Excel.Application(); xlexcel.Visible = true; xlWorkBook = xlexcel.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkSheet.Name = page.Name; Excel.Range CR = (Excel.Range)xlWorkSheet.Cells[1, 1]; CR.Select(); xlWorkSheet.PasteSpecial(CR, Type

Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))

血红的双手。 提交于 2019-11-26 22:24:43
问题 I am trying to convert a .xls file to an .xlsx file on the server-side using Microsoft.Office.Interop.Excel.Workbook class as follows: workBook.SaveAs("FILENAME_HERE", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Microsoft.Office.Interop.Excel.XlSaveConflictResolution.xlLocalSessionChanges, Type.Missing, Type.Missing, Type.Missing, Type.Missing); and I get the following error: Retrieving the COM class factory for

System.Runtime.InteropServices.COMException (0x800A03EC)

萝らか妹 提交于 2019-11-26 22:06:08
Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs() method is working fine on Windows server 2003 and also on XP but not on Windows server 2008. I copied it as it is gave all Dll's and permissions I have also tried all the solutions given on the net, such as Culture settings and DCOM permission. Getting following error: System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup,

Microsoft Office Excel cannot access the file 'c:\\inetpub\\wwwroot\\Timesheet\\App_Data\\Template.xlsx'

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 21:43:24
I have my code as follows :- Microsoft.Office.Interop.Excel.Application oXL = null; Microsoft.Office.Interop.Excel.Sheets sheets; Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Workbooks.Add(System.Reflection.Missing.Value); /* * Here is the complete detail's about Workbook.Open() * * Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, * Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, * Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local,

Safely disposing Excel interop objects in C#?

走远了吗. 提交于 2019-11-26 20:56:21
问题 i am working on a winforms c# visual studio 2008 application. the app talks to excel files and i am using Microsoft.Office.Interop.Excel; to do this. i would like to know how can i make sure that the objects are released even when there is an error? here's my code: private void button1_Click(object sender, EventArgs e) { string myBigFile=""; OpenFileDialog openFileDialog1 = new OpenFileDialog(); DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult