emmanuelkhumbudzo / linqtoexcel

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

Issue reading sheet names that contain apostrophe #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Okay, I promise I'm not trying to deliberately find errors, these are actually 
things coming up in my use cases. Suffice to say, the excel sources I'm using 
are awful... 

What steps will reproduce the problem?

    protected void Button1_Click(object sender, EventArgs e)
    {
    ExcelQueryFactory excel = new ExcelQueryFactory(@"C:\test.xls");
    List<string> worksheetNames = excel.GetWorksheetNames().ToList();

    foreach (string worksheetName in worksheetNames)
    {
    /* Throws exception at the following line.
    *  Text of exception for sample sheet is:
    *  'Steves Data' is not a valid worksheet name. 
    *  Valid worksheet names are: 'Steves Data', 'Data', 'Sheet3'
    */
    int countNum = (from someRow in excel.Worksheet(worksheetName)
    select someRow).Count();
    Trace.Write(countNum.ToString());
    }

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

** Expected output is either the sheet-name with the apostrophe, or being able 
to read the "normalized" version without the apostrophe

What version of the product are you using? On what operating system?

** Using ASP.NET on Microsoft Visual Studio 2010

Please provide any additional information below.

** I've attached the sample file I used, and the stack trace for the error. I'd 
also love to learn how to debug and help support this project so that I don't 
have to keep opening bug reports, and can instead just help with patching, but 
I'm less than stellar with the Linq structure. If someone doesn't mind helping 
me work through my own problems, I'd be game for that as well.

~Steve

Original issue reported on code.google.com by steven.v...@gmail.com on 14 Apr 2011 at 6:21

Attachments:

GoogleCodeExporter commented 9 years ago
Additionally, this technique actually fails with the same error:

 string countNum = (from someRow in excel.WorksheetNoHeader(0)
                           select someRow[0]).First();
        Trace.Write(countNum.ToString());

However, if I deliberately do: 

 string countNum = (from someRow in excel.WorksheetNoHeader("Steve's Data")
                           select someRow[0]).First();
        Trace.Write(countNum.ToString());

It works correctly, so it seems that the issue has to do with the algorithm 
that returns sheet-names. Hope this helps in the debugging process.

Original comment by steven.v...@gmail.com on 14 Apr 2011 at 5:15

GoogleCodeExporter commented 9 years ago
If you use the google code project at 
http://code.google.com/p/excellibrary/
then the following can get sheet names...

public static List<string> getSheetNames(string strFilename)
        {
            Workbook book = Workbook.Load(strFilename);
            List<string> sheetNames = new List<string>();

            foreach (Worksheet sheet in book.Worksheets)
            {
                sheetNames.Add(sheet.Name);
            }
            return sheetNames;
        }

The issue only occurs when someone is using the sheetnames from 
GetWorksheetNames() or indexing with bad sheet names, so this is (at the least) 
a workaround, or at most, a potential way of patching. Just figured I'd share 
in case someone else is having the issue.

Original comment by steven.v...@gmail.com on 19 Apr 2011 at 11:55

GoogleCodeExporter commented 9 years ago
This issue is now fixed in version 1.5.1  You can either download it from NuGet 
or from this site.

Original comment by paulyo...@gmail.com on 21 Apr 2011 at 6:52