This project has moved and is read-only. For the latest updates, please go here.


Nov 5, 2011 at 3:39 PM
Edited Nov 5, 2011 at 3:40 PM


I download the latest DLL and there is an exception message on my win7 64 bits.

The Exception message:

"A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll"

was output to console somewhere when I save the worksheet.

Tracking the source code I found it is in "foreach (ExcelCell cell in _cells)" in fuction    UpdateRowCellData(StreamWriter sw)

Test many times the exception was thrown out 100%, but the excel file is saved with on problem.

So,is it a Bug?

My code (copy form example) is listed as below, hopefully there is no problem in my code:


  public  static void WriteAllLines(string filename, string[] lines){
             //save CSV to xlsx
             ExcelPackage package = new ExcelPackage(new FileInfo(filename));
             // add a new worksheet to the empty workbook

             ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Worksheet 1");
             var namedStyle = package.Workbook.Styles.CreateNamedStyle("HyperLink");   //This one is language dependent
             namedStyle.Style.Font.UnderLine = true;

             //Add the data
             for (int i = 0; i < lines.Length;i++ )
                 if (lines[i]!="")
                    if (lines[i].Contains(","))
                        string[] subline = lines[i].Split(',');
                        for (int j = 0; j < subline.Length;j++ )
                          worksheet.Cells[i + 1, j + 1].Value = subline[j];

                    }   else{
                        worksheet.Cells[i + 1, 1].Value = lines[i]; 
             // set some document properties
             package.Workbook.Properties.Title = "WorkSheet";
             package.Workbook.Properties.Author = "myname";
             package.Workbook.Properties.Comments = "myname";

             // set some extended property values
             package.Workbook.Properties.Company = "mynameInc.";

             // set some custom property values
             package.Workbook.Properties.SetCustomPropertyValue("Checked by", "myname");
             package.Workbook.Properties.SetCustomPropertyValue("AssemblyName", "myname");

             // save our new workbook and we are done!
//win7 64bits VS2008 SP1 C#
Nov 17, 2011 at 6:28 AM

Hard to tell what the problem is, I cant see any problem with your code. Make sure you write to a valid path and have permission to write.