Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have data in my form. the data contains row and column format.

when i click the button, just i want to export data into excel from my form table data.

How to do that...?
Posted

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A quick google using your subject line as the search term gave me loads of hits.

Including an article on this very site: Export to Excel using VB.Net[^]
 
Share this answer
 
Hi try below code


C#
public static void DownloadExcel(string xlFilePath, string fileName)
{
if (System.IO.File.Exists(xlFilePath))
            {
                Page currentPage = HttpContext.Current.CurrentHandler as Page;
                currentPage.Response.Clear();
                currentPage.Response.Charset = "";
                currentPage.Response.ContentType = "sample.xls";
                currentPage.Response.AddHeader("content-disposition", "attachment;filename=" + fileName);
                byte[] DBuffer;
                using (FileStream objFileStream = new FileStream(xlFilePath, FileMode.Open, FileAccess.Read))
                {
                    DBuffer = new byte[(int)objFileStream.Length];
                    int index = 0;
                    int maxCount = 32767;
                    int remCount = DBuffer.Length;
                    while (index < DBuffer.Length)
                    {
                        if (maxCount > remCount)
                            maxCount = remCount;
                        objFileStream.Read(DBuffer,index,maxCount);
                        index = index + maxCount;
                        remCount = remCount - maxCount;
                    }
                }
                currentPage.Response.Buffer = true;
                currentPage.Response.BinaryWrite(DBuffer);
                currentPage.Response.End();
            }
        }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900