excel-interop

Fastest method to remove Empty rows and Columns From Excel Files using Interop

淺唱寂寞╮ 提交于 2019-11-26 16:32:54
I have a lot of excel files that contains data and it contains empty rows and empty columns. like shown bellow I am trying to remove Empty rows and columns from excel using interop. I create a simple winform application and used the following code and it works fine. Dim lstFiles As New List(Of String) lstFiles.AddRange(IO.Directory.GetFiles(m_strFolderPath, "*.xls", IO.SearchOption.AllDirectories)) Dim m_XlApp = New Excel.Application Dim m_xlWrkbs As Excel.Workbooks = m_XlApp.Workbooks Dim m_xlWrkb As Excel.Workbook For Each strFile As String In lstFiles m_xlWrkb = m_xlWrkbs.Open(strFile) Dim

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

*爱你&永不变心* 提交于 2019-11-26 15:37:03
问题 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

Closing Excel Application Process in C# after Data Access

随声附和 提交于 2019-11-26 15:11:30
I'm writing an application in C# that opens an Excel template file for read/write operations. I want to when user closes the application, excel application process has been closed, without saving excel file. See my Task Manager after multiple runs of the app. I use this code to open the excel file : public Excel.Application excelApp = new Excel.Application(); public Excel.Workbook excelBook; excelBook = excelApp.Workbooks.Add(@"C:/pape.xltx"); and for data access I use this code : Excel.Worksheet excelSheet = (Worksheet)(excelBook.Worksheets[1]); excelSheet.DisplayRightToLeft = true; Range rng

How to count the number of rows in excel with data?

谁说我不能喝 提交于 2019-11-26 14:25:37
column A has data like this (ie frequent blank cells): HEADING <-- this is A1 kfdsl fdjgnm fdkj gdfkj 4353 fdjk <-- this is A9 I would like to be able to get the cell reference of the last cell that has data. So in the above example I want to return: A9 I have tried this but it stops at the first blank cell (ie returning A4 ) numofrows = destsheet.Range("A2").End(xlDown).Row - 1 Tomamais I like this way: ActiveSheet.UsedRange.Rows.Count The same can be done with columns count. For me, always work. But, if you have data in another columns, the code above will consider them too, because the code

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

删除回忆录丶 提交于 2019-11-26 11:26:14
问题 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? 回答1: Got it!

extract image from word file

浪尽此生 提交于 2019-11-26 11:19:45
问题 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

System.Runtime.InteropServices.COMException (0x800A03EC)

橙三吉。 提交于 2019-11-26 09:27:15
问题 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

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

倾然丶 夕夏残阳落幕 提交于 2019-11-26 09:17:30
问题 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

Microsoft Office Excel cannot access the file &#39;c:\inetpub\wwwroot\Timesheet\App_Data\Template.xlsx&#39;

送分小仙女□ 提交于 2019-11-26 07:23:54
问题 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

Export the dataGridView to Excel with all the cells format

你说的曾经没有我的故事 提交于 2019-11-26 06:41: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