Moq & Interop Types: works in VS2012, fails in VS2010?

Edit : It works for me when I try it in Visual Studio 2012 and target .Net 4.0, only using the .Net PIA’s not the COM ref. Same solution doesn’t work in VS2010. VS2010 loads version’s 10.0.30319.1 of the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll’s and VS2012 loads version’s 11.0.50727.1. You can see the different version’s in the Modules window. … 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.

extract image from word file

using System; using System.Drawing; using System.IO; using System.Threading; using Page = System.Web.UI.Page; using Microsoft.Office.Interop.Word; using Microsoft.VisualBasic.Devices; public partial class ReadIMG : System.Web.UI.Page { private Application m_word; private int m_i; protected void Page_Load(object sender, EventArgs e) { object missing = Type.Missing; object FileName = Server.MapPath(“~/LectureOrig/Word.docx”); object readOnly = true; m_word = new Application(); m_word.Documents.Open(ref FileName, ref … Read more

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

What about using Excel Data Reader (previously hosted here) an open source project on codeplex? Its works really well for me to export data from excel sheets. The sample code given on the link specified: FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read); //1. Reading from a binary Excel file (’97-2003 format; *.xls) IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); … Read more

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

Got it! application.Workbooks != application.Workbooks This property doesn’t expose a variable, it generates a value. So every time I access the Workbooks property I create a new COM object. I fixed the code and all is well. Thanks, everybody. var excelApplication = new Application(); var workbooks = excelApplication.Workbooks; var workbook = workbooks.Open(pathToExcelWorkbook); // Fixed workbook.Close(); … 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