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

aldookar

0 / 0 / 0

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

Сообщений: 60

1

11.02.2013, 00:22. Показов 37443. Ответов 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,883

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,883

11.02.2013, 13:51

5

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

Миниатюры

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



3



56 / 56 / 14

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

Сообщений: 185

11.02.2013, 13:54

6

Вкладка «Обзор», и далее — C:WindowsAssembliesGACMicrosoft.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 stands w. Palestine's user avatar

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,1671 gold badge22 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

  • Remove From My Forums
  • Question

  • I am trying to use this namespace and downloaded the O2003pia.exe from http://support.microsoft.com/kb/897646.

    I ran the msi and see the Interop files in the GAC but when I try to ‘Add a Reference’ in VS2005, I do not see any of the Interop namespaces.

    I already had Office 2003 installed before I ran the above msi.

    What else am I doing wrong. Why aren’t these included with VS2005 in the first place…………..

    Please help,

    JJM

Answers

  • Hi JJJMonty,

    Actually, if you want to use this DLL, following these steps:

    1.       On the Project menu, click Add Reference.

    2.       On the COM tab, locate Microsoft Excel Object Library, and then click Select. In Visual Studio 2005, locate Microsoft Excel 11.0 Object Library on the COM tab.

    3.       Click OK in the Add References dialog box to accept your selections. If you are prompted to generate wrappers for the libraries that you selected, click “Yes”.

    Then you should be able to use this interop DLL, for more details, please visit Primary Interop Assemblies.

    Hope this helps!

    Thanks!

  • Remove From My Forums
  • Question

  • I’m having trouble with Excel Interop.  I wrote a sample application:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

    Dim xlApp As New Application()

    Dim objWorkbook As Workbook

    Dim objWorksheet As Worksheet

    Dim objRange As Range

    Dim intRow As Integer

    Dim intCell As Integer

    Dim strRow As New String(«»)

    ‘ Change the path to SOLVSAMP.XLS to match the path on your computer.

    objWorkbook = xlApp.Workbooks.Open _

    («C:Documents and Settingspmarino.USIDesktopsample.xls»)

    objWorksheet = objWorkbook.Worksheets.Item(1)

    objRange = objWorksheet.Range(«A2», «F16»)

    For intRow = 1 To 15

    For intCell = 1 To 6

    strRow = strRow & objRange.Cells(intRow, intCell).value & vbTab

    Next intCell

    Me.ListBox1.Items.Add(strRow)

    strRow = «»

    Next intRow

    End Sub

    This works fine while debugging.  When I publish the application to localhost and then run, I get this 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: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). on this line:

    Line 20:     objWorkbook = xlApp.Workbooks.Open _
    Line 21:         («C:Documents and Settingspmarino.USIDesktopsample.xls»)

    I have a reference to Microsoft.Office.Interop.Excel which is in c:Program FilesMicrosoft Visual Studio 9.0Visual Studio Tools for OfficePIAOffice11Microsoft.Office.Interop.Excel.dll

    Thanks for your help

Answers

  • I had this problem and it resolved after I ran the Office 2003 repair. Use Add Remove programs> Go to the tab Change or remove programs
    Go to Microsoft Office Professional 2003. Click the link «Click here for support information». Use Repair Button.

    This works.

    • Proposed as answer by

      Tuesday, March 2, 2010 2:08 AM

    • Marked as answer by
      Martin_XieModerator
      Friday, October 22, 2010 4:44 AM

  • Phil Marino,

    Based on your post, I created a new WindowsApplication1 in VB 2005 Express Edition. I copied a sample.xls, added reference of Excel Object Library 12.0 (I am using Office 2007) then use your code snippet with a Button and ListBox control. The application runs well when clicked debugging.

    I publish the application with the default location: http://localhost/WindowsApplication1/, then I can see the page that to install the project and run. The application runs well, too. I can see the result in the ListBox after clicking the button.

    I would like to suggest you to download the OleView.exe to see the related information on RegKeys, Typelib to track down the cause of your problem.

    Hope that can help you.

  • hi again…

    Im gonna answer myself hehe…

    I changed this in the code and now works in all the computer =)

    Dim oExcel As Excel.ApplicationClass —-> Dim oExcel As Excel.Application


    Dim oBooks As Excel.Workbooks

    Dim oBook As Excel.WorkbookClass ——> Dim oBook As Excel.Workbook

    D

    im oSheet As Excel.Worksheet

    • Proposed as answer by
      surendra singh samant
      Thursday, August 27, 2009 4:13 AM
    • Marked as answer by
      Martin_XieModerator
      Friday, October 22, 2010 4:43 AM

  • friends this is Balaji.

    i felt reliable to share the issue i solved. inface the one i face nd suffered from 2-3 days. this is for absolute beginners. Might the Big-B’s knw. but for a beginner newly coding involved with processes would find it help full.

    this error :-

    unable to cast com object of type ‘Microsoft.office.Interop.Excel.ApplicationClass’ to interface type ‘Microsoft.office.Interop.Excel._Application’ .

    The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

    if this arise — the one i solved is not exactly solution in all situations.  a case of mistake can be made by a beginner.

    the situation i solved :

    I tried to kill all the EXCEL processes as some times i used to get the excel file is being used by another processes.

    Solution :

    by doing that we are killing almost the connectivity to the excel. because we import excel in vb.net that process — even that process gets killed nd so the interop classes functionality stops working as the classes connectivity to excel is broken.

    that means by any means if the excel process is terminated we wil get that error.

    • Proposed as answer by
      balajivalla
      Tuesday, September 7, 2010 7:33 AM
    • Marked as answer by
      Martin_XieModerator
      Friday, October 22, 2010 4:44 AM

I have a project which opens a simple Excel file and populates it. It was working fine until this morning, when it has suddenly started giving me the error above: 'Application' is ambiguous in the namespace 'Microsoft.Office.Interop.Excel'.

I haven’t changed any project references, or anything within the file itself. The references include Microsoft.Office.Interop.Excel. The imports statement is there: imports Microsoft.Office.Interop

The object declaration is also complete: Dim xl As Microsoft.Office.Interop.Excel.Application which is the line that’s giving me the error!

I’ve tried googling this error, and the only response is that I need to declare xl as Microsoft.Office.Interop.Excel.Application.

The fact that I hadn’t changed anything within the project nor the code tells me this is a corruption in Visual Studio 2008. However, cleaning and rebuilding the project, rebooting Windows, and restarting VS has no effect.

Any ideas?

  • Userinit exe ошибка приложения
  • User32 dll ошибка windows 10
  • User status may not be up to date роблокс ошибка
  • User is terminated ошибка
  • User device registration ошибка