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

Strange error

Nov 18, 2010 at 2:32 PM
Edited Nov 18, 2010 at 2:33 PM

I am using an .xlsm template with a sort button.  I can open the .xlsm file but when i try to utilize it, the package Workbook object returns a null value exception.  However, if i step the code and add a watch or mouse over the excelpackage object to expose its methods and properties the code will run fine.  Its very strange. 

I added the save line below to see if saving the template and opening it again would solve the issue,  it didn't.  For some reason the Workbook throws the null exception.


Any insight would be appreciated.  Thanks,  Code is as follows:

                string _template = "C:\\Source\\SortTemplate.xlsm";
                FileInfo tempFile = new FileInfo(_template);
                tempFile.IsReadOnly = false;
                //****************Loop through Area List
                if (dsArea.Tables.Count != 0)
                    foreach (DataRow dr in dsArea.Tables[0].Rows)

                        string _Area = dr["SalesAreaCode"].ToString();
                        _destFileFullName = "C:\\Source\\ASM" + _Area + "SummaryYTD.xlsm";
                        //****************Build An Area Package
                        FileInfo newFile = new FileInfo(_destFileFullName);

                        if (newFile.Exists)
                            newFile.Delete();  // ensures we create a new workbook

                        using (ExcelPackage packagetemplate = new ExcelPackage(tempFile))
                            packagetemplate.Save(); --Workbook returns a null value exception. if i add a watch or step the code and mouse over to expose methods and properties it runs correctly


Nov 19, 2010 at 7:47 AM


Hard to tell what the problem can be,but check that you don't have any defined names referensing external workbooks. That will not work.

If that not the case, create an issue and upload the template or provide me with the stack trace.