Click here to Skip to main content
15,796,738 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am writing one small application,that contains grid view data,i can fill that grid view by using some functions,that part is completed.But i need to write that gridview data to excel or csv file.In that grid view am combining some rows and make it as a single row,in which fields am writing in to excel,am taking an object and all the fields are assign to that object,that is also completed.The main problem is am unable to write that object data to excel or csv file.
How can i write that object data to excel or csv,can any one help me please,it is very urgent for me.

1 solution

For exporting to Excel copy and paste the below event handler into MainPage.xaml.cs. Here we’re using the AutomationFactory to create an instance of Excel. Then we construct a worksheet.

Write this code in the Code Behind!

void ExcelButton_Click(object sender, RoutedEventArgs e)
        dynamic excel = AutomationFactory.CreateObject("Excel.Application");
        excel.Visible = true;
        dynamic workbook = excel.workbooks;
        dynamic sheet = excel.ActiveSheet;
        dynamic cell = null;
        int i = 1;
        // Populate the excel sheet
        foreach (var item in (LayoutRoot.DataContext as Bookmarks).Sites)
                cell = sheet.Cells[i, 1];
                cell.Value = item.Title;
                cell = sheet.Cells[i, 2];
                cell.Value = item.Uri;
                cell.ColumnWidth = 100;
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