1

Resolved

UriFormatException : Invalid Email in cell

description

Addon:
It seems to be a bug with the Uri class.
See http://connect.microsoft.com/VisualStudio/feedback/details/475897/uri-trycreate-throws-uriformatexception


Exception "Invalid URI: The hostname could not be parsed." thrown when reading Excel file.

Reproducible on 3.0.02 and 3.1 Beta.

DataSource:
Create a new Excel file (xlsx).
Key in the value 1@1.com;2@2.com into cell A1
Save (c:\file1.xlsx)

Source:
        //SourceFileInfo = new FileInfo(@"c:\file1.xlsx");
        using (ExcelPackage package = new ExcelPackage(SourceFileInfo))
        {
            int idx=0;
            foreach (ExcelWorksheet wks in package.Workbook.Worksheets)
            {                    
                result.Add(new BEWorksheetDetails(SourceFileInfo.Name, wks.Name, idx++, FetchData(wks.Name)));
            }
        }

comments

swmal wrote Jul 25, 2012 at 4:11 PM

SourceFileInfo = new FileInfo("c:\file1.xlsx");

... should rather be

new FileInfo(@"c:\file1.xlsx");

or

new FileInfo("c:\file1.xlsx");

Does that solve the problem?

charleslyk wrote Jul 26, 2012 at 12:14 AM

Hi Swmal,

The issue is not with new FileInfo... (commented)
I was trying to repro the minimal code and added in the commented line to be clearer. I've updated the comment to reflect the point you have raised.

Thanks.

swmal wrote Jul 26, 2012 at 3:14 PM

Ah, I see... I will see if we can do anything about this.

/Mats

charleslyk wrote Jul 26, 2012 at 3:46 PM

Hope this helps.

I tried the patch submitted in http://epplus.codeplex.com/workitem/14709

It does solve the issue by swallowing the exception and removing the hyperlink-ed value "mailto:1@1.com;2@2.com" in the cell and changing to a normal field.

Thanks.

JanKallman wrote Aug 31, 2012 at 7:04 AM

Try the lates source.