Create new sheet when Row Limit exceeds during Excel Export in Windows Application using C#

on Mar 20, 2018 02:32 AM


export from datagridview to excel is working fine.. i want a little extension from this export..

i want to export data from datagridview to new excel automatically if existing excel sheet's limit exceeds ..


can anyone help to me to do this ..


thanks in advance



Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Mar 20, 2018 02:34 AM

Explain in more details what exactly mean if excel sheets’ limit exceeds.


on Mar 20, 2018 03:21 AM

i want to export large volume of data from datagridview to excel sheet if the limit of excel file is about 2l then the remaining data of datagridview should be exported automatically to next excel file ... and here is the current code its working file i need that extension feature alone can you please guide me to do this 

Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
            // creating new Excelsheet in workbook  
            Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
            // see the excel sheet behind the program  
            app.Visible = true;
            // get the reference of first sheet. By default its name is Sheet1.  
            // store its reference to worksheet  
            worksheet = workbook.Sheets["Sheet1"];
            worksheet = workbook.ActiveSheet;
            // changing the name of active sheet  
            worksheet.Name = "Exported from gridview";
            // storing header part in Excel  
            for (int i = 1; i < dataGridView1.Columns.Count + 1; i++)
                worksheet.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;
            // storing Each row and column value to excel sheet  
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                for (int j = 0; j < dataGridView1.Columns.Count; j++)
                    worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();
            // save the application  
            workbook.SaveAs("D:\\DatagridviewDowloadEmails.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            // Exit from the application  
            MessageBox.Show("Your Exported file is in D:");


on Mar 20, 2018 04:44 AM

1. Add RowNumber to your Table rows and get data page wise.

2. i.e. Get first 1 lac records, export to one Excel, then second 1 lac and so on.

3. For getting data Page Wise from SQL Server refer.

Implement Paging DataGridView in Windows Forms (WinForms) Application using C# and VB.Net