3
votes

I'm wanting to import data from an Excel workbook without actually displaying the open workbook.

I could have sworn I had used the following code on a previous project and it had worked:

var excelApp = new Excel.Application { Visible = false };
var workbook = excelApp.Workbooks.Open(filePath);

Unfortunately when the workbook opens it is displayed to the user which is unnecessary for this application.

I'm using Microsoft Excel 15.0 Object Library on this project when previously I think it was version 12 or 13. Maybe this is the problem, or is my memory fading and the code is incorrect?

1
"Unfortunately when the workbook opens it is displayed to the user which is unneccessary for this application." Why would you open Excel for the user if the user doesn't want to see it? This reeks of you trying to troll the user.Aron
@Aron I assure you that I'm not. I'm writing something that parses data from an Excel workbook. The user would select the filepath for the workbook, and my application would parse the required data and add to the database. No nefarious activity.Darren Young
In that case you should not be running Excel. Please look into using OpenXML.Aron
Could you check the excelApp.Visible value after opening a book? Is it still false?Dmitry
Thanks @Aron. I'll take a look at OpenXml.Darren Young

1 Answers

0
votes

I know this is old but just in case anybody still needs this answer...

excelApp.Visible = false;

(excelApp being the name of the variable used for the excel application)