.Net application refreing to different version of Excel Object Lib

A

Abhirup Sen

Requirement:

1. Open an Excel 2007 file ( .xlxs)
2. Find out all the pivot tables in the workbook.
3. Set parameters to the pivot tables(i.e. Change the filter values for
these Pivot tables)

Whats done:

1. I created a windows application
2. Addded Microsoft Excel 12.0 Object Library and Microsoft Office 12.0
Object Library.
3. Now I try to create a new excel object.
4. Map it to the excel file i want .

Microsoft.Office.Interop.Excel.Application objExcel;

Microsoft.Office.Interop.Excel.Workbook objWrk;

Object objValue = System.Reflection.Missing.Value;

string path = @"C:\Test.xlsx";

objExcel = new Microsoft.Office.Interop.Excel.Application();

objWrk = objExcel.Workbooks.Add(objValue);





objWrk = objExcel.Workbooks.Open(path,

0,

false,

5,

"",

"",

true,


Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,

"\n",

false,

true,

0,

true,

1,

0);


Problem :

1. However everytime it tries converting the excel 2007 file to excel 2003
and open.
2. Inspite of refering to Office 12 dlls, when I look into the excel obj
created its shows version as 11.0 and its parent path is to offfice 11. and
hence converts to Exel 2003.

Just to mention : I have both Excel 2003 and Excel 2007 installed in my
system.


I tired adding a config file

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

<dependentAssembly>

<assemblyIdentity name="Microsoft.Office.Interop.Excel"

publicKeyToken="71e9bce111e9429c"

culture="neutral"/>

<publisherPolicy apply="No"/>

<bindingRedirect oldVersion="1.5.0.0"

newVersion="1.6.0.0"/>

</dependentAssembly>

</assemblyBinding>

</runtime>

</configuration>

Still its does not pick up version 12 and uses 11 instead.
However I am not sure if just adding this config does the trick or we need
to add any code in our c# class?

Does anyone have any solution how can I make my application open a Excel
2007 and not convert the .xlsx file to a .xls file

Thanks
Sen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top