Using excel microsoft office interop excel ошибка

I am having troubles adding the excel reference to my project. I have already installed Primary Interop Assemblies.

The project is detecting the Microsoft.Office.Interop.Word assembly reference correctly but the excel reference still cannot be found.

When I try to manually add the reference, I right click the project, add reference, navigate to the Microsoft.Office.Interop.Excel file and try to add it manually. Once i select the reference I then make sure the reference is checked, then hit ok. Nothing happens, it fails to actually add the reference path to the project.

Using VS2012 Ultimate.

Any suggestions on what I can do to get the project to see the excel reference?

41686d6564's user avatar

41686d6564

19.2k12 gold badges41 silver badges79 bronze badges

asked Oct 23, 2013 at 13:38

stylex's user avatar

6

If you don’t have excel installed, run this command in the nuget-packet-manager-console:

Install-Package Microsoft.Office.Interop.Excel

answered Apr 14, 2017 at 14:51

Luca Ziegler's user avatar

Luca ZieglerLuca Ziegler

3,2961 gold badge23 silver badges39 bronze badges

I installed Microsoft office PIAs, but I had the same problem, cannot find microsoft.office.interop.excel dll, I also I installed Visual Studio 2010 Tools for the Office System 4.0 Runtime Service Pack 1 but still the problem persist.

Finally I resolve the problem with an add of Office / SharePoint development package to my Visual Studio 2017 installation:

Go to Tools > Get Tools and Features ..

And then check Office / sharepoint development and modify your installation.

answered Apr 4, 2018 at 15:03

Mohammed EL KALAKHI's user avatar

1

I installed MS Office 13 and from then on I started getting this error in VS 2012 project.
I tried adding the MS Office lib via COM control but that didnt work.
Finally I had to add this library references from the «Extensions» section (not not under COM); had to select Microsoft.Office.Interop.Excel, version 15.0.0.0. That fixed the error.

Hope that helps some.

answered Apr 11, 2016 at 19:16

Yoda's user avatar

So I had to move a project to my dev machine from a consultant.

My working machine reference pointed to Microsoft.Office.Interop
My non-working machine wanted «Excel» to come from DocumentFormat.OpenXml.Spreadsheet which was also in the project.

I needed to
Tools>NuGet Package Manager>Package Manager Console and type «Install-Package Microsoft.Office.Interop.Excel»

then I needed to «Add Reference» as described above.

Movin to my co-worker’s machine we had to do these two steps and close and open the project to get it all to take.

answered Jun 23 at 15:29

DanKrhla's user avatar

aldookar

0 / 0 / 0

Регистрация: 10.02.2013

Сообщений: 60

1

11.02.2013, 00:22. Показов 37939. Ответов 10

Метки нет (Все метки)


Студворк — интернет-сервис помощи студентам

Всем привет! Кто может подсказать мне как заставить работать это у строчку:

C#
1
using Excel = Microsoft.Office.Interop.Excel;

Ошибка «Имя типа или пространства имен «Office» отсутствует в пространстве имен «Microsoft»».
Везде в интернете пишут что нужно добавить в Reference Microsoft.Office, но у меня студия на русском и я не могу понять куда это добавлять.



0



28 / 28 / 6

Регистрация: 25.12.2008

Сообщений: 186

11.02.2013, 01:47

2

Цитата
Сообщение от aldookar
Посмотреть сообщение

Везде в интернете пишут что нужно добавить в Reference Microsoft.Office, но у меня студия на русском и я не могу понять куда это добавлять.

В ссылки…



0



460 / 441 / 75

Регистрация: 26.12.2012

Сообщений: 2,885

11.02.2013, 10:27

3

вот на скрине видно в англоязычной версии вместо слова ссылка у вас будет написано references
p.s ставьте лучше англоязычную версию

Миниатюры

Имя типа или пространства имен "Office" отсутствует в пространстве имен "Microsoft"
 



1



0 / 0 / 0

Регистрация: 10.02.2013

Сообщений: 60

11.02.2013, 13:25

 [ТС]

4

Блин значит у меня чего то нет…

Имя типа или пространства имен "Office" отсутствует в пространстве имен "Microsoft"



0



460 / 441 / 75

Регистрация: 26.12.2012

Сообщений: 2,885

11.02.2013, 13:51

5

на вкладке COM ищите

Миниатюры

Имя типа или пространства имен "Office" отсутствует в пространстве имен "Microsoft"
 



3



56 / 56 / 14

Регистрация: 06.04.2012

Сообщений: 185

11.02.2013, 13:54

6

Вкладка «Обзор», и далее — C:\Windows\Assemblies\GAC\Microsoft.Office.Interop.Excel и выберите нужную версию, это если у вас семерка, если ХР, то вроде бы понадобится установить PIA для вашей версии офиса(2003,2007), качается оно с сайта майкрософта (например для 2003 офиса — http://www.microsoft.com/en-us… x?id=20923), хотя, так как вам не просто использовать, а разрабатывать, то возможно еще понадобится(в случае ХР) установить VSTO



2



0 / 0 / 0

Регистрация: 10.02.2013

Сообщений: 60

11.02.2013, 14:12

 [ТС]

7

Спасибо! Дальше уже сам думаю разберусь.



0



0 / 0 / 0

Регистрация: 10.02.2013

Сообщений: 60

12.02.2013, 17:58

 [ТС]

8

Решил не создавать новую тему и написал здесь.
Как считывать с exel файла и попутно обрабатывать?
т.е. первый столбец это текст, второй это один из вариантов combobox, третий проверка на истину или лож и т.д.

Добавлено через 1 час 32 минуты
Нашел! Кому интересно вот ссылка



0



aldookar

0 / 0 / 0

Регистрация: 10.02.2013

Сообщений: 60

17.02.2013, 17:02

 [ТС]

9

Всем привет! Снова зашел в тупик…

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //Создаём приложение.
                Microsoft.Office.Interop.Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application();
                //Открываем книгу.                                                                                                                                                        
                Microsoft.Office.Interop.Excel.Workbook ObjWorkBook = ObjExcel.Workbooks.Open(openFileDialog1.FileName, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
                //Выбираем таблицу(лист).
                Microsoft.Office.Interop.Excel.Worksheet ObjWorkSheet;
                ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBook.Sheets[1];
 
                //Выбираем первые сто записей из столбца.
                for (int i = 0; i < 101; i++)
                {
                    //Выбираем область таблицы.
                    Microsoft.Office.Interop.Excel.Range range = ObjWorkSheet.get_Range("A" + (i+8).ToString(), "A" + (i+8).ToString());
 
                    MessageBox.Show(range.Text.ToString());
                    //Добавляем полученный из ячейки текст.
                    dataGridViewDan.Rows[i].Cells[0].Value = range.Text.ToString();
          
                    Application.DoEvents();
                }
 
                //Удаляем приложение
                ObjExcel.Quit();
            }
 
        }

Код записывает первую строчку в сетке, но не создает вторую…

Добавлено через 2 часа 3 минуты
И с этим разобрался. Добавил в цикл dataGridViewDan.Rows.Add(); и все работает!

Добавлено через 1 минуту
Блин он пустые строчки создает…

Добавлено через 30 минут
Поставил dataGridViewDan.Rows.Add(); перед dataGridViewDan.Rows[i].Cells[0].Value = range.Text.ToString(); и работает почти правильно… Вот только лишняя строчка снизу…



0



Сосна15

13 / 12 / 1

Регистрация: 02.10.2017

Сообщений: 22

02.10.2017, 16:27

10

Цитата
Сообщение от aldookar
Посмотреть сообщение

Всем привет! Кто может подсказать мне как заставить работать это у строчку:

C#
1
using Excel = Microsoft.Office.Interop.Excel;

Ошибка «Имя типа или пространства имен «Office» отсутствует в пространстве имен «Microsoft»».
Везде в интернете пишут что нужно добавить в Reference Microsoft.Office, но у меня студия на русском и я не могу понять куда это добавлять.

Столкнулся с той же проблемой. В русской ВидеоСтудии трудно понять куда заходить, чтобы установить компонент Экселя.

Решение такое:

В Обозревателе решений жмём правой кнопкой на свой проект, появляется окошко контекстного меню.
Выбираем Добавить ссылку... -> Открывается искомое окно (с надписью на английском): Add reference
Далее выбираем вкладку .NET, а в ней наш долгожданный Microsoft.Office.Interpop.Excel



1



SeIZVeIZ

02.10.2017, 16:52


    Имя типа или пространства имен «Office» отсутствует в пространстве имен «Microsoft»

Не по теме:

Сосна15, на дату смотреть не учили?



0



I am having troubles adding the excel reference to my project. I have already installed Primary Interop Assemblies.

The project is detecting the Microsoft.Office.Interop.Word assembly reference correctly but the excel reference still cannot be found.

When I try to manually add the reference, I right click the project, add reference, navigate to the Microsoft.Office.Interop.Excel file and try to add it manually. Once i select the reference I then make sure the reference is checked, then hit ok. Nothing happens, it fails to actually add the reference path to the project.

Using VS2012 Ultimate.

Any suggestions on what I can do to get the project to see the excel reference?

41686d6564's user avatar

41686d6564

19.2k12 gold badges41 silver badges79 bronze badges

asked Oct 23, 2013 at 13:38

stylex's user avatar

6

If you don’t have excel installed, run this command in the nuget-packet-manager-console:

Install-Package Microsoft.Office.Interop.Excel

answered Apr 14, 2017 at 14:51

Luca Ziegler's user avatar

Luca ZieglerLuca Ziegler

3,2961 gold badge23 silver badges39 bronze badges

I installed Microsoft office PIAs, but I had the same problem, cannot find microsoft.office.interop.excel dll, I also I installed Visual Studio 2010 Tools for the Office System 4.0 Runtime Service Pack 1 but still the problem persist.

Finally I resolve the problem with an add of Office / SharePoint development package to my Visual Studio 2017 installation:

Go to Tools > Get Tools and Features ..

And then check Office / sharepoint development and modify your installation.

answered Apr 4, 2018 at 15:03

Mohammed EL KALAKHI's user avatar

1

I installed MS Office 13 and from then on I started getting this error in VS 2012 project.
I tried adding the MS Office lib via COM control but that didnt work.
Finally I had to add this library references from the «Extensions» section (not not under COM); had to select Microsoft.Office.Interop.Excel, version 15.0.0.0. That fixed the error.

Hope that helps some.

answered Apr 11, 2016 at 19:16

Yoda's user avatar

So I had to move a project to my dev machine from a consultant.

My working machine reference pointed to Microsoft.Office.Interop
My non-working machine wanted «Excel» to come from DocumentFormat.OpenXml.Spreadsheet which was also in the project.

I needed to
Tools>NuGet Package Manager>Package Manager Console and type «Install-Package Microsoft.Office.Interop.Excel»

then I needed to «Add Reference» as described above.

Movin to my co-worker’s machine we had to do these two steps and close and open the project to get it all to take.

answered Jun 23 at 15:29

DanKrhla's user avatar

  • Remove From My Forums
  • Question

  • Hi,

    I’m going to create a simple Excel file and export data from a SQL server table and save it to the Excel file.

    I have problem with creating Excel file getting the error for the following code:

    Excellibrary.DataSetHelper.CreateWorkbook("test.xls", ds)

    The error message is : The name «Excellibrary» does not exist in the current context.

    Or

    using (Excel = Microsoft.Office.Interop.Excel)

    The error message is : The name «Excel» does not exist in the current context.

    I’ve added References these to my project: 

    Microsoft.Office.Interop.Excel

    Microsoft.Office.Tools.Excel

    Is there any reference i should add? Please advise me what the problem is?

    Thanks

    • Edited by

      Tuesday, December 10, 2013 11:12 AM

Answers

  • Hi Kate,

    You can create Excel file by this code:

    using Excel=Microsoft.Office.Interop.Excel;
    using System.Reflection;
    public void CreateExcel( string fileName)
            {
                Object missing = Missing.Value;
                Microsoft.Office.Interop.Excel.Application m_objExcel = new Microsoft.Office.Interop.Excel.Application();
                Microsoft.Office.Interop.Excel.Workbooks m_objWorkBooks = m_objExcel.Workbooks;
                Microsoft.Office.Interop.Excel.Workbook m_objWorkBook = m_objWorkBooks.Add(true);
                Microsoft.Office.Interop.Excel.Sheets m_objWorkSheets = m_objWorkBook.Sheets; ;
                Microsoft.Office.Interop.Excel.Worksheet m_objWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)m_objWorkSheets[1]; 
                m_objWorkBook.SaveAs(fileName, missing, missing, missing, missing, missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,
                        missing, missing, missing, missing, missing);
                m_objWorkBook.Close(false,missing,missing);
                m_objExcel.Quit();
            }

    Thanks.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    Click
    HERE to participate the survey.

    • Marked as answer by
      Kate es
      Wednesday, December 11, 2013 9:02 AM

  • Remove From My Forums
  • Question

  • Hello,

    Can someone please tell me what is incorrect about this code?  I have a reference to Excel 12 included in the project…

    using Excel = Microsoft.Office.Interop.Excel;
    
    
    
    namespace Program
    
    { 	
    
    	class Program	
    
    	{		
    
    		static void Main(string[] args)
    
            	{
    
    	            Excel.Application app = new Excel.Application();
    
                	    app.DisplayAlerts = false;
    
    	        }
    
     	}
    
    }
    
    
    
    

    results in the following error:

    System.InvalidCastException was unhandled
    
      Message="Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))."
    
      Source="Microsoft.Office.Interop.Excel"
    
      StackTrace:
    
           at Microsoft.Office.Interop.Excel.ApplicationClass.set_DisplayAlerts(Boolean RHS)
    
           at RefreshHelper.Program.Main(String[] args) in C:\Users\user\Desktop\program\program\Program.cs:line 20
    
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
    
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
    
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    
           at System.Threading.ThreadHelper.ThreadStart()
    
      InnerException: 
    
    

    Thanks,
    Dup

    • Edited by

      Tuesday, November 3, 2009 10:10 PM

Понравилась статья? Поделить с друзьями:
  • Usflib dll ошибка ableton
  • Usf ошибка на частотнике schneider
  • Utorrent ошибка соединения истекло время ожидания
  • Utorrent тест скорости stockholm se ошибка
  • Utorrent при установке выдает ошибку