| | |
opening Excel 2003 file by c#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
Hello everyone
First ,My name is Hashem I'm a beginner in c#, I'm trying to open Excel file(2003) but I get error at Open Function in the below code :
(Old Format Or Invalid Library Of kinds (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
Is there anybody can help me? where I use the following code that i have collected from many reference.
The replies are valuable.
public static Excel.Application ExlApp;
public static Excel.Workbook ExlWrkBook;
public static Excel.Worksheet ExlWrkSheet;
Excel.Application ExcApp = new Excel.Application();
ExcApp.Visible = true;
Excel.Workbook excelWorkbook = ExcApp.Workbooks.Open("D:\\Salary Calc.xls", 0, false, 5, "", "", true,Excel.XlPlatform.xlWindows, "\t", true, false, 0, false, true, true);
Excel.Sheets ExcSheet = excelWorkbook.Worksheets;
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)ExcSheet.get_Item(currentSheet);
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");
First ,My name is Hashem I'm a beginner in c#, I'm trying to open Excel file(2003) but I get error at Open Function in the below code :
(Old Format Or Invalid Library Of kinds (Exception from HRESULT: 0x80028018 (TYPE_E_INVDATAREAD))
Is there anybody can help me? where I use the following code that i have collected from many reference.
The replies are valuable.
public static Excel.Application ExlApp;
public static Excel.Workbook ExlWrkBook;
public static Excel.Worksheet ExlWrkSheet;
Excel.Application ExcApp = new Excel.Application();
ExcApp.Visible = true;
Excel.Workbook excelWorkbook = ExcApp.Workbooks.Open("D:\\Salary Calc.xls", 0, false, 5, "", "", true,Excel.XlPlatform.xlWindows, "\t", true, false, 0, false, true, true);
Excel.Sheets ExcSheet = excelWorkbook.Worksheets;
string currentSheet = "Sheet1";
Excel.Worksheet excelWorksheet = (Excel.Worksheet)ExcSheet.get_Item(currentSheet);
Excel.Range excelCell = (Excel.Range)excelWorksheet.get_Range("A1", "A1");
What's your Office SDK version?
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
•
•
Join Date: May 2009
Posts: 3
Reputation:
Solved Threads: 0
Hy,
I did something like what you want in VC++ .NET Framework language. Just use the same classes in C# and it should work (there are some peaces of code that are usefull in my application but do no refer to Excell handling - just not care of). Please note that you have to install Excel 2003 and Windows XP or higher in the system where the application runs.
private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e)
{
String^ XlsFile = String::Format("Z:\\Documenti\\Lavoro\\Fatture\\2009\\Fattura_02_AEM_marzo_09.xls");
String^ XlsSheet = String::Format("Milano, {0}/{1}/{2}",
dateTimePicker1->Value.Day.ToString(),
dateTimePicker1->Value.Month.ToString(),
dateTimePicker1->Value.Year.ToString());
Excel::Application^ oXLApp;
Excel::Workbook^ oXLWBook;
//Excel::Sheets^ oXLSheet;
//Excel::Worksheet^ oXLWSheet;
Excel::Range^ rng;
//starts Excel application
oXLApp = (gcnew Excel::Application());
oXLApp->Visible = true;
//opens the workbook of the file "XlsFile"
oXLWBook = oXLApp->Workbooks->Open(XlsFile, 0, false, 5, "", "",
true,Excel::XlPlatform::xlWindows, "\t", true, false, 0, false, true, true);
//updates the range of sheet1, cell D4
rng = oXLApp->Range::get("D4","D4");
rng->Value2 = XlsSheet;
}
I did something like what you want in VC++ .NET Framework language. Just use the same classes in C# and it should work (there are some peaces of code that are usefull in my application but do no refer to Excell handling - just not care of). Please note that you have to install Excel 2003 and Windows XP or higher in the system where the application runs.
private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e)
{
String^ XlsFile = String::Format("Z:\\Documenti\\Lavoro\\Fatture\\2009\\Fattura_02_AEM_marzo_09.xls");
String^ XlsSheet = String::Format("Milano, {0}/{1}/{2}",
dateTimePicker1->Value.Day.ToString(),
dateTimePicker1->Value.Month.ToString(),
dateTimePicker1->Value.Year.ToString());
Excel::Application^ oXLApp;
Excel::Workbook^ oXLWBook;
//Excel::Sheets^ oXLSheet;
//Excel::Worksheet^ oXLWSheet;
Excel::Range^ rng;
//starts Excel application
oXLApp = (gcnew Excel::Application());
oXLApp->Visible = true;
//opens the workbook of the file "XlsFile"
oXLWBook = oXLApp->Workbooks->Open(XlsFile, 0, false, 5, "", "",
true,Excel::XlPlatform::xlWindows, "\t", true, false, 0, false, true, true);
//updates the range of sheet1, cell D4
rng = oXLApp->Range::get("D4","D4");
rng->Value2 = XlsSheet;
}
Hi!
Hope this code will resolve your problem.
Hope this code will resolve your problem.
C# Syntax (Toggle Plain Text)
using System.Collections; using Microsoft.Office.Interop.Excel; using System; using System.Reflection; class Sample { static void Main() { string file = @"c:\csnet\jap\ex1\sample1.xls"; Microsoft.Office.Interop.Excel.ApplicationClass ap = new ApplicationClass(); Missing m=Missing.Value; Workbook wb=ap.Workbooks.Open(file, m, m, m, m, m, m, m, m, m, m, m, m, m, m); Worksheet sh =(Worksheet) wb.Sheets[1]; for (int i = 1; i < 10; i++) { string[] p = new string[10]; for (int j = 1; j <= 10; j++) { Range r = (Range)sh.Cells[i, j]; p[j - 1] = r.Value2; } } ap.Quit(); } }
Last edited by adatapost; May 20th, 2009 at 10:32 am.
Failure is not fatal, but failure to change might be. - John Wooden
•
•
Join Date: Apr 2009
Posts: 13
Reputation:
Solved Threads: 0
i did the same thing using javascript..may be that helps you..
here is the javascript code:
here is the javascript code:
C# Syntax (Toggle Plain Text)
<html> <head> <title></title> </head> <body> <script type="text/javascript"> function read() { var myApp = new ActiveXObject("Excel.Application"); if (myApp != null) { myApp.visible = true; myApp.workbooks.open("C:\\Book2.xls"); } } </script> <button onclick="read();">READ</button> </body> </html>
•
•
•
•
i did the same thing using javascript..may be that helps you..
here is the javascript code:
C# Syntax (Toggle Plain Text)
<html> <head> <title></title> </head> <body> <script type="text/javascript"> function read() { var myApp = new ActiveXObject("Excel.Application"); if (myApp != null) { myApp.visible = true; myApp.workbooks.open("C:\\Book2.xls"); } } </script> <button onclick="read();">READ</button> </body> </html>
Nice code. You should post this one on Web forum.
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- Opening Excel 2007 File using Asp.net Hangs (ASP.NET)
- Excel 2003 Error opening file (Windows NT / 2000 / XP)
- Firefox keeps opening multiple tabs by itself everytime I open Firefox (Viruses, Spyware and other Nasties)
- IE keeps opening w ADS and more <HiJAcjThis log included> (Viruses, Spyware and other Nasties)
- Help! IE browser keeps opening up by itself! <HijackThis Log Included> (Viruses, Spyware and other Nasties)
Other Threads in the C# Forum
- Previous Thread: Sudoku
- Next Thread: How to remove uid and password in connection string?
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom customactiondata database datagrid datagridview dataset datastructure date/time datetime datetimepicker degrees development dll draganddrop drawing encryption enum event excel file filename files form format forms function gdi+ gis gtk hash image index input install java label list listbox mandelbrot math mouseclick mysql operator outlook2003 path photoshop picturebox pixelinversion pixelminversion post programming radians regex remoting richtextbox safari server sleep snooze socket sql statistics stream string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser webcam wia windows winforms wpf xml






