 |
|
 |
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..
|
|
|
|
 |
|
 |
I have an excel file downloaded from a web site that I need to get the worksheet names from. It's in Excel 5.0 format and the code doesn't work. If I load it into Excel 2003 and then save it in that format, the code works fine.
When I run the code on an Excel 5.0 file (even if I change the Extended Properties = Excel 5.0), the SchemaTable returns zero rows (no information).
I'm frustrated! Can anyone help?
|
|
|
|
 |
|
 |
Is there any way by chance that I will be able to add a worksheet using ADO? Also is there any way that will enable me to create a new xls file and fill its contents with the values in a datatable?
Bikash Rai
|
|
|
|
 |
|
 |
i found a bug and im still figuring out how to fix it.
can you help?
it reads an extra sheet.
sample
newExcel.xls
sheet1 - somename
when it retrieves the sheets, it displays 2 sheets as
1 - oldsheetname
2 - sheet1$
i trace the problem here
dt = _oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
dt returns 2 rows when it should only retrive 1 row.
hmm it does not happen all the time. i tried creating a sheet and it works ok, but when i use my own excel sheets, the bug appears.
hmm. maybe it has something to do with renaming my sheets and deleting some sheets. i will try to replicate
someone is generating excelfile for me, i open it using this code to retrieve the excelsheet names.
im getting 2 sheets
1 - oldsheetname
2 - oldsheetname$
i use this sample app
http://www.codeproject.com/csharp/Excel_using_OLEDB.asp[^]
its using the code with you retrieving sheetnames.
im still having trouble on how to duplicate it.
im getting these error on these excel files.
one more thing, im also getting error if there are spaces on sheetnames - like "sheet1 (2)"
can you help?
|
|
|
|
 |
|
 |
Hi All , this concept of reading the ExcelSheet has really provided gr8 help to me as far as the issues of returning extra excelsheets with $ symbols appended to it I have come up with the following approach , the code is in VB.NET but its simple enough to be convertable to C#
Dim index As Integer
Dim excelsheetName As String = row("TABLE_NAME").ToString()
index = excelsheetName.LastIndexOf("$")
'Check wheather a sheet or not
If Not index < 0 Then
excelsheetName = excelsheetName.Remove(index, excelsheetName.Length - index)
If i = 0 Then
'To get rid of this "'"
If excelsheetName.Chars(0) = "'" Then
excelsheetName = excelsheetName.Remove(0, 1)
End If
excelSheets(i) = excelsheetName
i += 1
Else
If excelsheetName.Chars(0) = "'" Then
excelsheetName = excelsheetName.Remove(0, 1)
End If
If Not excelSheets(i - 1) = excelsheetName Then
excelSheets(i) = excelsheetName
i += 1
End If
End If
End If
Next row
ReDim Preserve excelSheets(i - 1)
return excelsheets // excelsheets are string array
|
|
|
|
 |
|
 |
Why not just do it this way...
foreach(Excel.Worksheet szWorksheetName in ThisWorkbook.Sheets)
SheetsArray.Add(szWorksheetName.Name.ToString());
????????????????????????????
|
|
|
|
 |
|
 |
I think the point of the tip was to use ADO.NET -- in the context of reading an Excel spreadsheet as an ADO.NET data source. With the information from this article, one would not need Excel installed on the machine.
What you propose is fine too - in the context of already having Excel installed on the machine, and using the Excel object library. But in the context of reading data from Excel sheets, probably without Excel installed, the author's tip is very useful.
|
|
|
|
 |
|
|
 |
|
 |
How to Retrieve Excel Workbook Sheet Names
using Java
|
|
|
|
 |
|
 |
Never thought to use ADO.NET with an Excel Workbook. 4 Balls though, the webpage is out of wack had to scroll right to left to read the entire article.
|
|
|
|
 |
|
|
 |
|
 |
just curious, if you like it, any reason you didn't vote for it???
|
|
|
|
 |
|
 |
i normally like to try the code out first (tho i don't always get around to it).
|
|
|
|
 |
|
 |
Hi Ken. Does this technique return names of hidden sheets as well?
|
|
|
|
 |
|
 |
I don't think hidden sheet names will be available.
|
|
|
|
 |
|
 |
I get certain sheets with their names ending with a underscore (for example Details_). but no such sheet is present in excel file. I think these are added when data is added to excel through another application. Is there a way to avoid reading these sheet names!!??
Ankit Bansal (.Net Programmer)
|
|
|
|
 |
|
 |
Ending in _ are hidden sheets. There can also be other calculated sheets etc. Always look for names
ending in $.
"Ken sent me"
|
|
|
|
 |