|
|
|
thx a lot it help me too much
|
|
|
|
|
Hi,
I am trying to read excel 2003 xls file in visual studio 2008 by using the code published in this website "Loading and reading the Microsoft Excel file contents using C#" By _duk_
The file test.xls is exist in the path.
But am getting the below error.
System.Runtime.InteropServices.COMException was unhandled
HelpLink="C:\\Program Files\\Microsoft Office\\OFFICE11\\1033\\xlmain11.chm"
Message="'c:\\test.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files on the File menu, make sure that the file has not been renamed, moved, or deleted."
Source="Microsoft Office Excel"
ErrorCode=-2146827284
StackTrace:
at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in C:\VSTAF\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 32
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WindowsFormsApplication1.Program.Main() in C:\VSTAF\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
can anyone tell me the solution
Thanks in advance
|
|
|
|
|
Hi vishwa.
Its bit late for your solution but it may help you.
you need to add a dll (Microsoft.Office.Interop.Excel.dll)as reference
then use this as namespace-
using Excel = Microsoft.Office.Interop.Excel;
Hope this'll relief your headache.
Cheers.
Raj.
|
|
|
|
|
In Visual Studio 2008 what are the References to include?
Should they be COM interop?
|
|
|
|
|
One suggestion: Move the row: rowIndex = 2+index;
to the end of the while loop, or else there will be exception thrown.
Hope I can help U
|
|
|
|
|
Hi,
I want to read excel file using VC++. If anybody knows plz share.
|
|
|
|
|
if i read the excel file its contains a date format
the c# is considered as a text or decimal value so how to
Read the date formated column in excel file
muruga
|
|
|
|
|
Hi,
you could try this Excel C# library. It handles DateTime type correctly.
Also if you are importing Excel to DataSet and column types in Excel and DataSet are different, you can easily make appropriate conversion, like in this code snippet:
var ef = new ExcelFile();
ef.LoadXls("Excel file.xls");
for(int i = 0; i < ef.Worksheets.Count; ++i)
{
var ws = ef.Worksheets[i];
ws.ExtractDataEvent += (sender, e) =>
{
if (e.ErrorID == ExtractDataError.WrongType)
{
if (e.Mapping.DataSetColumn == "time1" || e.Mapping.DataSetColumn == "time2")
{
e.DataTableValue = DateTime.Parse(e.ExcelValue);
e.Action = ExtractDataEventAction.Continue;
}
}
};
ws.ExtractToDataTable(dataSet.Tables[i], ws.Rows.Count, ExtractDataOptions.StopAtFirstEmptyRow, ws.Rows[0], ws.Columns[0]);
}
|
|
|
|
|
Hi ,
I have written a code to read Excel 2003 . But my user has Office 97 .
It throws an exception at
// code for creating an object of Excel.ApplicationClass()
//create a workBook object ...
excelObj.Workbooks.Open ( StrFilename,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,false,Missing.Value,Missing.Value,Missing.Value);
Can you provide any solution for this ?
Regards,
Tara
|
|
|
|
|
I forgot to mention that the Exception is Null Reference Error .
Regards,
Tara
|
|
|
|
|
Dear fellows
I have problem about which i donot from where i can get help.
What is Working:
I have made a ASP.NET (C#) application that is reading Data from Excel (cell b cell). That is working fine and i can check it in browser.
Problem:
Now using this code i made a web part in C# and i want to show it in SharPoint Server 2007 site page. Now that is not working , thats mean not showing the web part on the page.
And when i comment the excel ralated code in web part coding and check it at SharePoint server, web part works.
I donot know what to do, Please Help
Piece of code is:
Excel.Application app = new Excel.Application();
Excel.Workbook wbook = null;
Excel.Worksheet wsheet = null;
Excel.Range range = null;
app.Visible = false;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
string filepath = inputFile1.Value.ToString();
if (filepath != "")
{
wbook = app.Workbooks.Open(filepath, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value);
string currentSheet = "Sheet1";
wsheet = (Excel.Worksheet)wbook.Worksheets.get_Item(currentSheet);
range = wsheet.get_Range("B6", "H20");
System.Array myvalues = (System.Array)range.Cells.Value2;
valueArray = ConvertToStringArray(myvalues);
if (app != null)
{
app.Workbooks.Close();
app.Quit();
}
app = null;
wsheet = null;
range = null;
Asif khan
|
|
|
|
|
Hi there,
I've created a web using visual studio and c#. I can use your code no problem when i'm running it off my local host. However once it's hosted i'm getting the following error:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
Source Error:
Line 54: {
Line 55: //sets up an excel class called excelApp
Line 56: Excel.Application excelApp = new Excel.ApplicationClass();
Line 57: Excel.Workbook newWorkbook = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Line 58:
Is it at all possible to use this code online??
Thanks,
Adrian.
|
|
|
|
|
Essentially what it is says (I think) is that the Excel Com libs are not available online...
or at least, not available in the environment you are hosted in.
|
|
|
|
|
I want to import data from excel 2007 file. I am getting "COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005." error while creating object of Application class. But note that the Microsoft office is not installed on my machine. I want to import excel file without installing the micrsoft excel?
|
|
|
|
|
Are you serious? This is like saying I want to build a house but I don't want to use any materials.
|
|
|
|
|
I tried this sample and when i opened my "Task Manager" I saw that there are many instances of Excel. Any reason why?
|
|
|
|
|
Yes, the author failed to extensively test his application
Use the following to ensure a complete closure of the process.
Please not this is not the complete solution. If the program exits with an exception
before this point, instances may not be closed as your workbook will be unavailable.
usage: shutDownExcel(workSheet,workBook,app);
#region Close Excel
// from microsofts MSDN
private void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
finally
{
o = null;
}
}
//not from the msdn
private void shutDownExcel(Excel.Worksheet workSheet, Excel.Workbook workBook, Excel.ApplicationClass app) {
NAR(workSheet);
workBook.Close(false, false, Type.Missing);
NAR(workBook);
app.Quit();
NAR(app);
}
#endregion
|
|
|
|
|
Hi,
The performance using the code is very poor, you can try is using just 5000 rows with say 10 columns and try to copy/write that, will take more than 5 min. even on 3GHz Machine .
thanks
anil
(pl)
india
|
|
|
|
|
Um, DUH! You can't possibly expect excel to perform like SQLServer with that kind of data. Sheesh.
void (*)()
|
|
|
|
|
Yes, unfortunately I've noticed this too. Not much you can do, it's the way the old COM objects are set up. You have to get each column individually. If only there was a way to get a bunch of columns at once.
One way I've found to get data from an xls a bit faster is to write an excel macro to write the data into a CSV file, then read the CSV file. You can use the Excel libraries mentioned in this post to execute the macro (see http://support.microsoft.com/?kbid=306683)
John
|
|
|
|
|
|
Try this : http://free.netartmedia.net/CSharp/CSharp22.html
|
|
|
|
|
the code dosnt read the dateformat
salah
gis member
|
|
|
|
|