How to close-without-save an Excel /xlsm workbook, w/ a custom function, from C#

When you use the Excel objects, be sure to close the workbook like this: Excel.Application xlApp ; Excel.Workbook xlWorkBook ; Excel.Worksheet xlWorkSheet ; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(“Yourworkbook”); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); ….do your stuff xlWorkBook.Close(false, misValue, misValue); xlApp.Quit(); The false in the close method indicates don’t save changes.

Class not registered error when creating Excel workbook in C#

I had this exact same problem. Here’s how I fixed it: Go to HKEY_CLASSES_ROOT\TypeLib\ and search for Office.Interop.Excel. I found HKEY_CLASSES_ROOT\TypeLib\(guid)\1.8 but its child nodes were empty! I deleted it because Office 15 wasn’t installed on that machine, and hey presto – it worked. Either our VSTO project installer, or our own custom installer must … Read more

System.Runtime.InteropServices.COMException (0x800A03EC)

Found Answer…….!!!!!!! Officially Microsoft Office 2003 Interop is not supported on Windows server 2008 by Microsoft. But after a lot of permutations & combinations with the code and search, we came across one solution which works for our scenario. The solution is to plug the difference between the way Windows 2003 and 2008 maintains its … Read more

Cannot close Excel.exe after Interop process

Simple rule: avoid using double-dot-calling expressions, such as this: var workbook = excel.Workbooks.Open(/*params*/) …because in this way you create RCW objects not only for workbook, but for Workbooks, and you should release it too (which is not possible if a reference to the object is not maintained). So, the right way will be: var workbooks … Read more

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

Try this: Create the directory C:\Windows\SysWOW64\config\systemprofile\Desktop (for the 32-bit version of Excel/Office on a 64-bit Windows computer) or C:\Windows\System32\config\systemprofile\Desktop (for a 32-bit version of Office on a 32-bit Windows computer or a 64-bit version of Office on a 64-bit Windows computer). For the Desktop directory, add Full control permissions for the relevant user (for example … Read more

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

Take a look at Linq-to-Excel. It’s pretty neat. var book = new LinqToExcel.ExcelQueryFactory(@”File.xlsx”); var query = from row in book.Worksheet(“Stock Entry”) let item = new { Code = row[“Code”].Cast<string>(), Supplier = row[“Supplier”].Cast<string>(), Ref = row[“Ref”].Cast<string>(), } where item.Supplier == “Walmart” select item; It also allows for strongly-typed row access too.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)