Share via


Error1 Namespace '' contains a definition conflicting with alias 'Excel'

Question

Thursday, July 24, 2008 7:44 PM

I am trying to transfer data to an excel workbook . I have added the adodb and the MicrosoftExcel12ObjectLibrary into the com references. I am still getting this error. My code is as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Data;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;

namespace iExcelClass
{
    class iExcel
    {
        public Excel.Application _mExcelApp;
        private Excel.Workbook _mWorkbook;
        private Excel.Worksheet _mWorkSheet;

        private int _mSheet1Row = 1;
        private int _mSheet2Row = 1;
        private int _mExcelPID = 0;
        private bool _mblnExcelVisible = false;
        private string _mstrXLSFileFullName = "";
        private string _mstrWorkSheetName = "MyWkShtName";

The errors are on the underlined parts. The zigzag blue line is under Excel in all three lines. Any help would be really appreciated.

Thanks!

All replies (4)

Thursday, July 24, 2008 7:59 PM âś…Answered | 1 vote

I've never seen the error before, but it sounds like there is already an alias called "Excel". Try changing your alies to another name like:

using MyExcel = Microsoft.Office.Interop.Excel;

private MyExcel.Application...

See if that helps.


Thursday, July 24, 2008 8:26 PM

Why do you even have the Excel = Microsoft.Office.Interop.Excel? If you have the using reference you should be able to refer to those objects just as Application, Workbook and Worksheet without needing the Excel. part


Saturday, October 12, 2013 8:17 AM

"using Excel = Microsoft.Office.Interop.Excel;"

use different name instead of "Excel". example: "Excela", "MyExcel"..


Monday, December 30, 2013 9:00 AM

I got the same error after I added as a reference not only 

using Excel = Microsoft.Office.Interop.Excel; 

but also Microsoft Office 9.0 Object Library. Once I deleted this reference, I could compile the code.