codeice / linqtoexcel

Automatically exported from code.google.com/p/linqtoexcel
0 stars 0 forks source link

GetWorksheetNames() #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. LinqToExcel.ExcelQueryFactory book = new 
LinqToExcel.ExcelQueryFactory("c:/file.xls");
2. book.GetWorksheetNames()

What is the expected output? What do you see instead?

Expected output is strings' collection with the name of worksheets. Beside 
worhsheets name I receive strange additional string in this collection: 
"Excel_BuiltIn__FilterDatabase_3"

What version of the product are you using? On what operating system?
1.4.79. Windows XP SP3, Visual Studio 2010 (C#)

Original issue reported on code.google.com by toudi...@o2.pl on 29 Jun 2010 at 12:21

GoogleCodeExporter commented 8 years ago
Can you attach the spreadsheet you are working with.

Original comment by paulyo...@gmail.com on 29 Jun 2010 at 12:25

GoogleCodeExporter commented 8 years ago
Here it is

Original comment by toudi...@o2.pl on 30 Jun 2010 at 6:28

Attachments:

GoogleCodeExporter commented 8 years ago
I did half an hour of research on the web and couldn't find out why the 
spreadsheet has this hidden name.

Original comment by paulyo...@gmail.com on 7 Jul 2010 at 5:44

GoogleCodeExporter commented 8 years ago
Like PrintArea FilterDatabases are hidden worksheets. In my opinion 
GetWorksheetNames should not return names of hidden worksheets. See the 
following code that runs into an exception:

         var excel = new ExcelQueryFactory(Filename);
         var workSheetsNames = excel.GetWorksheetNames();
         foreach(var name in workSheetsNames)
         {
            Console.WriteLine("Columns of Worksheet '{0}':",name);
            var columnNames = excel.GetColumnNames(name);
            foreach (var columnName in columnNames)
            {
               Console.WriteLine("\t{0}",columnName);
            }
         }

Please note the $ sign in the name below

System.Data.OleDb.OleDbException : 'Excel_BuiltIn__FilterDatabase_3$' is not a 
valid name.  Make sure that it does not include invalid characters or 
punctuation and that it is not too long.
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult 
hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS 
dbParams, ref Object executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(ref Object executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, ref 
Object executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior 
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReader()
at LinqToExcel.Query.ExcelUtilities.GetColumnNames(String WorksheetName, String 
FileName)
at LinqToExcel.ExcelQueryFactory.GetColumnNames(String WorksheetName)
at My.Tests.ExcelFileReaderTest.ExcelWorkBookTest() in ExcelFileReaderTest.cs: 
line 22 

Original comment by pietvred...@gmail.com on 6 Sep 2010 at 10:06

GoogleCodeExporter commented 8 years ago
In order to get it working for me I've replaced the 
ExcelUtilities.GetWorksheetNames
with the following code:

        internal static IEnumerable<string> GetWorksheetNames(string fileName)
        {
            var worksheetNames = new List<string>();
            using (var conn = new OleDbConnection(GetConnectionString(fileName)))
            {
               conn.Open();
               using (var excelTables = conn.GetOleDbSchemaTable(
                  OleDbSchemaGuid.Tables,
                  new Object[] {null, null, null, "TABLE"}))
               {
                  worksheetNames.AddRange(
                     (from DataRow row in excelTables.Rows
                      let worksheetName = row["TABLE_NAME"].ToString()
                      select worksheetName.Remove(worksheetName.IndexOf("$")).Replace("'", "")).Distinct());
               }
            }
            return worksheetNames;
        }

But for real i still don't understand the Excel_BuiltIn__FilterDatabase_3 
problem...

Original comment by pietvred...@gmail.com on 6 Sep 2010 at 12:27

GoogleCodeExporter commented 8 years ago
I agree. I'll work on apply the patch.

Original comment by paulyo...@gmail.com on 7 Sep 2010 at 4:11

GoogleCodeExporter commented 8 years ago
This is fixed in version 1.4.81

Original comment by paulyo...@gmail.com on 21 Sep 2010 at 2:37