Excel 2007 c# saveas method error

D

Donato Grippo

Hi guy

I write this software but when i call saveas methos, the application present
an error.

In excel 2003 all process best works
the first problem in excel 2007 in Add() method.

Without using
System.Threading.Thread.CurrentThread.CurrentCulture =
System.Globalization.CultureInfo.CreateSpecificCulture("en-US");
the application doesent work, why?

In secondary the SaveAs methos doesent work, why?
I using culture info English and italian , but the problem similar
I specify the excel number file format , 50, 56 but the problem similar

Sample:
//Instance Excel
Type ExcelType = Type.GetTypeFromProgID("EXCEL.Application");
objEXLApp = Activator.CreateInstance(ExcelType);
ExcelType.InvokeMember("Visible",System.Reflection.BindingFlags.SetProperty,
null, objEXLApp, new object[] { false });

//Se non metto questo non funziona il metodo add va in eccezione
System.Threading.Thread.CurrentThread.CurrentCulture =
System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

// istance Workbooks
objBooks =
objEXLApp.GetType().InvokeMember("Workbooks",BindingFlags.GetProperty, null,
objEXLApp, null);

// istance workbook
objBook = objBooks.GetType().InvokeMember("Add",BindingFlags.InvokeMethod,
null, objBooks, null );

// Sheet
objSheets =
objBook.GetType().InvokeMember("Worksheets",BindingFlags.GetProperty, null,
objBook, null);

// Select first sheet
Parameters = new Object[1];
Parameters[0] = 1;
objSheet = objSheets.GetType().InvokeMember("Item",BindingFlags.GetProperty,
null, objSheets, Parameters);

//Write sample
object cells = _sheet.GetType().InvokeMember("Cells",
BindingFlags.GetProperty, null, _sheet, null);
cells.GetType().InvokeMember("Item", BindingFlags.SetProperty, null, cells,
new object[] { row, col, str });

Parameters = new Object[2];
Parameters[0] = "c:\\file.xlsx"; //or xls
Parameters[1] = 39; //xlExcel7=39, others 50, 56 similar problem
xlsx

objBook.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, null,
objBook, Parameters);

Error description:

at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr,
Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture,
String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
bindingFlags, Binder binder, Object target, Object[] providedArgs,
ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at ExportPLoad.frmMain.ExportExcel()

Tanks for any response
Donato
 

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