EPPlus LoadFromDatatable at nth cell is not Working.....

Dec 18, 2012 at 9:08 AM

Hi,

    When exporting to excel with LoadFromDatatble to 'AA' Column i am getting following error!!!

"Specified argument was out of the range of valid values.Parameter name: Start cell Address must be less or equal to End cell address"

Please let me know about this..

is there any way to write to any column in Excel at once from Datatable.

 

 

Dec 18, 2012 at 2:22 PM

If you refer to the cell address in number format it should work:  worksheet.Cells[1,27].LoadFromDataTable(datatable, true) would load it from the top left at row 1, column 27 (AA). 

 

 

 

Dec 19, 2012 at 3:53 AM

Hi,

  i am using like this.  [ NewSheet.Cells [1 , 27].LoadFromDataTable (dt , true); ], am still getting the Error!!!

"Specified argument was out of the range of valid values.Parameter name: Start cell Address must be less or equal to End cell address"

 

Dec 19, 2012 at 9:11 AM

If you could post as much code as you can I can have a look at it in visual studio.  Btw I am a novice programmer but I like to help out where I can as website like stackoverflow.com that have guidance from seasoned programmers are very useful to me.

Dec 19, 2012 at 9:23 AM

 

my code is just simple writing to Excel at "AA" column using Template.. 

 

public void GenerateTemplateFromIEnumerableColl (DataTable dt  , int ToColumnVal)

 {

    FileInfo Template ="Template path here";

    FileInfo NewFile ="Path to save excel file";

   using (ExcelPackage ExlPackage = new ExcelPackage (NewFile , Template)) {

          NewSheet.Cells [1 , 27].LoadFromDataTable (dt , true); // This line is capturing error!!!

        ExlPackage.Save ();

     }

}

Dec 19, 2012 at 12:23 PM

From the code fragment you have posted there is no declaration for a new worksheet that is part of ExcelPackage->ExlPackage.

You would need to add:  ExcelWorksheet NewSheet = ExlPackage.Workbook.Worksheets.Add("worksheet name");

But Visual Studio should flag an error that you have not declared NewSheet in the first place.

Dec 24, 2012 at 2:24 PM
Edited Dec 24, 2012 at 2:25 PM

I am getting the exact same error!! And it has nothing to do with the Package or the worksheet!

For example, I can run the following code without error:

       .Cells(2, 20).LoadFromDataTable(dtMyTable,True)

BUT When I change it to this:

     .Cells(2, 26).LoadFromDataTable(dtMyTable,True)

I get an ArgumentOutOfRangeException - Specified argument was out of the range of valid values. Parameter name: Start cell Address must be less or equal to End cell address.

Anyone have any thoughts??

Dec 24, 2012 at 2:45 PM

As added info on the question, when I changed my EPPlus from Version 3.1.2 to 3.0, it now works again...