 |
|
|
 |
|
|
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?
|
| Sign In·View Thread·PermaLink | 2.20/5 (5 votes) |
|
|
|
 |
|
|
Thanks for posting this. I really did not want to add a reference to the Excel library and your code helped me avoid that.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 1.33/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
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..
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
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?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
|
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?
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
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
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Why not just do it this way...
foreach(Excel.Worksheet szWorksheetName in ThisWorkbook.Sheets) SheetsArray.Add(szWorksheetName.Name.ToString());
????????????????????????????
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | 5.00/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
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.
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
|
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)
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Ending in _ are hidden sheets. There can also be other calculated sheets etc. Always look for names ending in $.
"Ken sent me"
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |