Link to home
Start Free TrialLog in
Avatar of zaratin
zaratin

asked on

Excel files create and read

Hello everybody,
can somebody tell me how to create an Excel file and read from an Excel file in C#? I'm having problems with this command:
...
Excel.Application xlApp = new Excel.Application();      //works fine
Excel.Workbook xlWb = xlApp.Workbooks.Open(
    myExcelFile.xls, true, 5, "", "", true, Excel.XlPlatform.xlWindows,
    "\t", false, false,0, true);

 // here I get the message that xlApp.Workbooks.Open method doesn't take 13 Parameters?!


I'm using WinXP Pro and .NET Enterprise Architect
Thanks!!!
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

title : Open Method
source : http://msdn.microsoft.com/library/default.asp?url=/library/en-us/off2000/html/xlmthOpen.asp

description :
--------------
Syntax

expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password, WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable, Notify, Converter, AddToMRU)
--------------

chek for all parameters on the link,

you can also see this
-when you open excel
-open the vba editor with ALT+F11
-choose F2 and you can browse through all obejcts, methods and properties with F1 you got the parameter values

hope this helps a bit
PS which version of excel do you use?
Avatar of zaratin
zaratin

ASKER

Hello bruintje,
I use Excel 10.0 (Oxffice XP Developer). When trying to save an Excel workbook with:
...
Excel.Application exc=new Excel.Application();
                  
                  Excel.Workbook  wb = exc.Workbooks.Add (Type.Missing );
                  Excel.Sheets She = (Excel.Sheets)wb.Worksheets;
                  Excel.Worksheet Sheet = (Excel.Worksheet)(She.get_Item(1));
                  Excel.Range Range = Sheet.get_Range("A1", "A2");
                  Range.Value2 = "Foo";
                  wb.SaveAs (myPath,0, "", "",1,0,  
                        Excel.XlSaveAsAccessMode.xlNoChange,true,false, false,
                        0, false);
                  
                  wb.Close(false, myPath, false);

 I get the following message:

System.Runtime.InteropServices.COMException

If I save the workbook with "Save()"- Method (no arguments),  it is saved in my profile's MyDocuments folder...

What am I doing wrong?
Thanks
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sure to change you xlfileformat
Avatar of zaratin

ASKER

bruintje, you've got it!
Works great, thanks for your help
Many greetings
:) you're welcome, and thanks for the grade