mkhuwaja / linqtoexcel

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

Leading space in worksheet names causes read error #92

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a workbook with one worksheet containing a leading space
2. Use Linq to Excel to try to read the data for worksheet 0
3. A System.Data.DataException error will be raised: ' Foo' is not a valid 
worksheet name. Valid worksheet names are:' Foo', 'Bar'"

What is the expected output? What do you see instead?
The data should be read, but there is an issue between the names in the 
workbook's schema and the worksheet being read.

What version of the product are you using? On what operating system?
Windows 7, LinqToExcel v1.7.0.0

Please provide any additional information below.
The issue is raised in the method below:
private bool CheckIfInvalidColumnNameUsed(SqlParts sql)
        {
            var usedColumns = sql.ColumnNamesUsed;
            var tableColumns = ExcelUtilities.GetColumnNames(_args.WorksheetName, _args.FileName);
            foreach (var column in usedColumns)
            {
                if (!tableColumns.Contains(column))
                {
                    throw new DataException(string.Format(
                        "'{0}' is not a valid column name. " +
                        "Valid column names are: '{1}'",
                        column,
                        string.Join("', '", tableColumns.ToArray())));
                }
            }
            return false;
        }

Original issue reported on code.google.com by andrewcr...@gmail.com on 10 Sep 2013 at 11:30