Insert data from Data table to first blank row in excel using C# EPPlus RRS feed

  • Question

  • Hi all,

    I have insert my data from a data table to first empty row of blank cell using EPPlus. First row contains header already, but when I execute below code it insert data in first row itself and later it pastes continuously. Please help me on this issue.

    var filePath = new FileInfo(@"D:\Network Issue Tracker V1.0.xlsx");
                if (filePath.Exists)
                    using (ExcelPackage ep = new ExcelPackage(filePath))
                        var workSheet = ep.Workbook.Worksheets[1];
                        var i = workSheet.Dimension.End.Row;
                        workSheet.Cells[i,1].LoadFromDataTable(dt, false);

    It has to paste from A2 as A1 is filled with header already. But it is pasting in A1 and header is replaced.

    Thanks in Advance.

    Friday, January 19, 2018 4:45 AM

All replies

  • Please post all your Excel questions in the Excel for Developers forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, January 19, 2018 3:36 PM
  • Hi, am not familiar with EPPluse, i'd like to recommend you use Spire.XLS to write datatable to worksheet at the specified row and column.

    XlsWorksheet.InsertDataTable(DataTable dataTable, bool columnHeaders, int firstRow, int firstColumn)

    Here is the code for your reference

    Workbook wb = new Workbook();
    Worksheet sheet = wb.Worksheets[0];
    int rowNum = sheet.AllocatedRange.RowCount;
    sheet.InsertDataTable(dataTable, true, rowNum + 1, 1);

    • Edited by Ezreal93 Monday, January 22, 2018 7:34 AM
    Monday, January 22, 2018 6:49 AM
  • Hello Dineshkumar Palanisamy,

    This forum(Excel for Developers) is for development issues related to Excel Object Model. Since Epplus is a third-part api, I would suggest you contact with Epplus's support team for help. For current thread, we will move it to Off-Topic forum. Thanks for understanding.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 22, 2018 7:33 AM