C# Tutorials and offshore development in India

Tutorials Resources Forum Reviews Interview Jobs Projects Training Your Ad Here


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...




Forums » .NET » .NET »

how can i save the contents of datagridview in excel pl give code in vb.net


Posted Date: 14 Jul 2006      Posted By: vrk      Member Level: Gold     Points: 2   Responses: 2



i want to save the contents of datagridview to excel.

every time it has to save in differnt excel sheet.

ex: ie when pressing save btn it has to show the dialogbox and take the file name with extension and save the contents of datagrid veiw.............pl it is very urgent





Responses

Author: Abhishek Arya    14 Jul 2006Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

use this code

Include Microsoft Excel 10.0 Object Library from Com components to your
project reference.
In this code ticketsList is a data set which is populated and shown in a
grid.
Hope this is helpful.
Excel.ApplicationClass excel = new Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
DataTable table = ticketsList.Tables[0];
int cIndex = 0;
foreach(DataColumn col in table.Columns)
{
cIndex++;
excel.Cells[1,cIndex]=col.ColumnName;
}
int rIndex=0;
foreach(DataRow row in table.Rows)
{
rIndex++;
cIndex=0;
foreach(DataColumn col in table.Columns)
{
cIndex++;
excel.Cells[rIndex+1,cIndex] = row[col.ColumnName].ToString();
}
}
excel.Save("New.xls");



Author: ali udmilov    20 Aug 2007Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

:) Now you can use the DataGridView Extension. With its help you can export to Excel, Html ... soon pdf. Also you can search for text in the grid, theme managment and many more...
find it on http://www.completit.com/Products/DGVE/Overview.aspx



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : How to convert excel file to Binary file in VB.NET?
Previous : Crystal Report - How to Solve an "Logon Failed" Error in Crystal report
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages




About Us    Contact Us    Privacy Policy    Terms Of Use