 |
|
 |
excusme Mr.Kenny Young I want to ask about your code "Retrieve Excel Workbook Sheet Name" I don't know code (excelSheets[i] = row["TABLE_NAME"].ToString();) what TABLE_NAME is? please tell me sir about it
|
|
|
|
 |
|
 |
Old, but helpful information
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
//if any one need this code in c++ .
private:ArrayList *GetExcelSheetNames(String *excelFile)
{
OleDbConnection *objConn = NULL;
System::Data::DataTable *dt = NULL;
try
{
// Connection String. Change the excel file to the file you
// will search.
String *connString = String::Concat(S"Provider=Microsoft.Jet.OLEDB.4.0;",S"Data Source=", excelFile,S";Extended Properties=Excel 8.0;");
// Create connection object by using the preceding connection string.
objConn = new OleDbConnection(connString);
// Open connection with the database.
objConn->Open();
// Get the data table containg the schema guid.
dt = objConn->GetOleDbSchemaTable(OleDbSchemaGuid::Tables,NULL);
if(dt == NULL)
return NULL;
System::Data::DataRowCollection *GetSheets = dt->Rows ;
System::Data::DataRow *row;
//used for store the names of sheets or use the control what you want String[] , listBox etc..
ArrayList *excelSheets = new ArrayList();
Object *Objetos[] =NULL;
for (int i=0;i<GetSheets->Count;i++)
{
row = GetSheets->get_Item(i);
Objetos = row->get_ItemArray();
excelSheets->Add(Objetos->get_Item(2));
//another alternative
listBox1->Items->Add ( Objetos->get_Item(2)->ToString());
//another one
//printf("\n %i) [%s]\n",i++,Objetos->get_Item(2)->ToString() );
}
return excelSheets;
}
catch(Exception *ex)
{
return NULL;
}
}
|
|
|
|
 |
|
|
 |
|
 |
| Does anyone know how to get the order of the sheet as they are seen within Excel? hard learn
|
|
|
|
 |
|
 |
I am so much thankful that I can't express. It helped me so much.
Warm Regards,
Mujtaba Panjwani
Tiger Softwares
Software Designer and Developer
VB.NET, C#, ASP.NET, VFP
|
|
|
|
 |
|
 |
Hi Kenny,
I have used the code given above in a C# .Net Windows Excel project. It is working in about 5 computers perfectly well. Today when I was installing it on a users machine it gave the error "no error message available, result code:E_UNEXPECTED (0x8000FFFF) while I think it is trying to open the OLEDb connection.
Actually it is returning null in place of the worksheet name. I tried to figure out the problem but could not succeed. Please help me.
Thanks in advance.
|
|
|
|
 |
|
 |
Please recommend me, How can i use this code on linux.
Thanks.
|
|
|
|
 |
|
|
 |
|
 |
Nice article. Thanks for the tip-
|
|
|
|
 |
|
 |
Many thanks for posting this....it helped me out of a jam.
|
|
|
|
 |
|
 |
Very useful Artical
Thanks
|
|
|
|
 |
|
 |
Does anyone know how to get the order of the tabs as they are seen within Excel?
|
|
|
|
 |
|
|
 |
|
 |
I don't remember if I ever did.
|
|
|
|
 |
|
 |
With these methods, the SheetName will come back with $ or ' symbols, for example:
- Sheet1 will be returned as Sheet1$
- Customers will be returned as 'Customers$'
Is there any way to return the actual worksheet name (displayed in Excel), not the name recognised by codes?
|
|
|
|
 |
|
 |
Hi,
well, you could simply trim those characters.
On the other hand, you can try this Excel C# component to get sheet names. Here is a code:
var ef = new ExcelFile();
ef.LoadXls("MyFile.xls");
foreach (var ew in ef.Worksheets)
Console.WriteLine(ew.Name);
|
|
|
|
 |
|
 |
Thanks for posting this. I really did not want to add a reference to the Excel library and your code helped me avoid that.
|
|
|
|
 |
|
 |
Same here. Thanks!!!
|
|
|
|
 |
|
 |
hi,
I have a request
Can you give me a simple and complete example
in C# about access to MS excel 2003 sheets and cells
and reading or writing to cells and also drawing
graph in accordance with excel cells
(i.e. for example I have an integer table in an excel
sheet and now I want to draw a chart in accordance with
this integer table)
very thanks
yours sincerely hamed
yours sincerely
hamed
|
|
|
|
 |
|
 |
Good Day,
I had read your article which is nice. I would like to know if you had any idea of writting text on a worksheet column? My code is written below:
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
string connectionString = GetExcelConnection(); -- Get Connection to excel
DataTable dt = new DataTable();
dt = GetShipTypeTable(); -- Loads up the Data to be written to Excel
foreach (DataRow dr in dt.Rows)
{
string shipType = null;
shipType = dr["Description"].ToString(); - put the data into string
using (DbConnection connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString;
using (DbCommand command = connection.CreateCommand())
{
command.CommandText = @"INSERT INTO [Registers$] (ShipType)
VALUES (" + shipType + ")";
connection.Open();
command.ExecuteScalar();
}
}
}
[Registers$] - WorkSheet name from your code
ShipType - is the header of a column in that worksheet
when running it, I encounter this error:
[Syntax error (missing operator) in query expression 'Accommodation Unit'.]
Please help me.. and thanks in advance
Thanks,
Ben
|
|
|
|
 |
|
|
 |
|
 |
If the excel file has protection, it cant be accessed.. even with
"provider=Microsoft.Jet.OLEDB.4.0; data source=" + fileName + "; password=xyz; Extended Properties=Excel 8.0;"
Not much help out there for this specifically, you could be the first!
thanks in advance..
|
|
|
|
 |