Problem to create Excel file

Hi,
I'm to create Excel file by C# codes and have got this

Error	1	Assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' uses 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' which has a higher version than referenced assembly 'office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
Error	2	Assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' uses 'Microsoft.Vbe.Interop, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' which has a higher version than referenced assembly 'Microsoft.Vbe.Interop, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'

Open in new window

using these codes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using Microsoft.Office.Interop;
using Excel = Microsoft.Office.Interop.Excel;

namespace ns1
{
    class Program
    {
        static void Main(string[] args)
        {
            string orp_path = "//ABC";
            bool allowappend = true;

            string test = "test";
            Excel.Application app = null;
            Excel.Workbook workbook = null;
            Excel.Worksheet worksheet = null;
            Excel.Range workSheet_range = null;
            object misValue = System.Reflection.Missing.Value;

            Excel.Application xlApp = new
            Microsoft.Office.Interop.Excel.Application();
            workbook = xlApp.Workbooks.Add(misValue);

            workbook = xlApp.Workbooks.Add(misValue);
            worksheet = (Excel.Worksheet)workbook.Worksheets.get_Item(1);
            
            worksheet.Cells[1, 1] = "Run Date";

            workbook.SaveAs("c:\\" + test + ".xls", Excel.XlFileFormat.xlOpenXMLTemplate, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
            workbook.Close(true, misValue, misValue);
            xlApp.Quit();

            releaseObject(worksheet);
            releaseObject(workbook);
            releaseObject(xlApp);
            ...

Open in new window



on VS 2013. Any advice?
LVL 11
HuaMin ChenSystem AnalystAsked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You can set up Office 2010, but that needs to be the only version you have on the dev system, or you have to select the version in your USING statement (not recommended - that exact version is required then on any target system).
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Try if including those implicit references explicitly before line 12 helps.
However, there seem to be an error in the reference info, as the 15 one should be used by default when installed. Maybe you require a repair install of Office.
0
 
ThommyCommented:
The message says, that you are trying to compile against Office 2013 Interop (Version=15.0) but your project is using the wrong dll (Office 2007 Interop Version=12.0)!!!

Try re-installing Office 2013 and turn on the ".NET Programmability Support" to get Microsoft.Office.Interop.Excel Version 15.0.0.0 reinstalled.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
HuaMin ChenSystem AnalystAuthor Commented:
Thanks all.
Thommy,
is it OK if I set up Office 2010 for this? If OK, what to adjust next?
0
 
HuaMin ChenSystem AnalystAuthor Commented:
If not, how to adjust the codes, to still use the current MS Office version?
0
 
ThommyCommented:
Sorry, I was a little bit late!

I do absolutely confirm Olemo's words.

Why do you want to install Office 2010?
Thought you already have Office 2013 installed?
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Sorry, I compile the same codes, within another machine, on which I've set up Office 2010, but I still get these below
Error	1	Assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' uses 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' which has a higher version than referenced assembly 'office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'	
Error	2	Assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' uses 'Microsoft.Vbe.Interop, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' which has a higher version than referenced assembly 'Microsoft.Vbe.Interop, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'	

Open in new window

0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I'm confused. Are you still having that issue, even on another machine with Ofiice 2010 installed?
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Yes, OK to the problem already.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.