Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Export to ExcelExport to Excel
Previous
 
Next
New Post
12/20/2007 3:08 AM
 

Hello,

I have an ASPX page WITH Grid View with data in below format:

Title
------------------------------------
c# book
------------------------------------
ID AUTHOR ISBN
------------------------------------
1 Andrew 1233456
------------------------------------
Title
------------------------------------
Learn asp.net in 20 days
------------------------------------
ID AUTHOR ISBN
-------------------------------------
2 ROB 412123123
-------------------------------------

Now I want to export this data to excel in following format (Each data in one row)

Title ID AUTHOR ISBN
Learn asp.net 2 ROB 412123123

How can I achive this? Do I need to take a seprate Gridview which is hidden [but do not know how to achive this]?

Or is there a way i can directly export the datatable to Excel. I will not be using Miscosoft excel component to use it in any case.

Please suggest

 
New Post
8/15/2008 11:18 PM
 

private void ExcelExport()
{
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment; filename=FileName.xls");
        Response.Charset = "";

        // If you want the option to open the Excel file without saving than
        // comment out the line below
        // Response.Cache.SetCacheability(HttpCacheability.NoCache);

        Response.ContentType = "application/vnd.xls";

        System.IO.StringWriter stringWrite = new System.IO.StringWriter();

        System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
        GridView1.RenderControl(htmlWrite);
        Response.Write(stringWrite.ToString());

        Response.End();
}       


Eric Garza
EGI Consulting
Dallas, TX
(972) 767-5930
View my profile on LinkedIn

Are you looking for DotNetNuke ModulesDotNetNuke Skins or DotNetNuke Support?

 
New Post
8/16/2008 12:00 PM
 

The method above works and here's an alternative too that goes after the datatable in question

If Not IsNothing(hypExcelIcon.CommandName) Then
                'Lets create a datatable to hold the values and then push it out to the user.
                Dim dtExcel As New DataTable()
                dtExcel.Columns.Add(New DataColumn("Product Family", GetType(String)))
                dtExcel.Columns.Add(New DataColumn("PartID", GetType(String)))
                dtExcel.Columns.Add(New DataColumn("Description", GetType(String)))
                dtExcel.Columns.Add(New DataColumn("Is Pronto Part", GetType(String)))
                dtExcel.Columns.Add(New DataColumn("List Price", GetType(String)))
                dtExcel.Columns.Add(New DataColumn("Discount", GetType(String)))
                dtExcel.Columns.Add(New DataColumn("Your Price", GetType(String)))

                'Now lets loop thru the table and get the rows.
                For Each drFilterRow As DataRow In drFilterRows
                    Dim dtTable As DataTable = GETXXXXXX(drFilterRow("COMMODITYID"))
                    'Now we loop thru the series.
                    For Each drRow As DataRow In dtTable.Rows
                        Dim drExcel As DataRow = dtExcel.NewRow()
                        drExcel("Product Family") = drFilterRow("PRICEBOOK_NAME").ToString()
                        drExcel("PartID") = drRow("PARTNAME").ToString()
                        drExcel("Description") = drRow("DESCRIPTION").ToString()
                        drExcel("Is Pronto Part") = IIf(String.IsNullOrEmpty(drRow("PRONTO_PART").ToString()), "No", "Yes")
                        drExcel("Discount") = formatPercent(_discountCode / 100)
                    
                        dtExcel.Rows.Add(drExcel)
                    Next
                Next

                'Now lets push this to the client.
                Response.Clear()
                Response.AddHeader("Content-Disposition", "attachment;filename=" & fileName & ".xls")
                Response.Charset() = ""
                Response.ContentType = "application/vnd.ms-excel"

                Dim tab As String = ""
                For Each dc As DataColumn In dtExcel.Columns
                    Response.Write(tab & dc.ColumnName)
                    tab = vbTab
                Next
                Response.Write(vbCr)

                'write the rows.
                Dim i As Integer = 0
                For Each datarow As DataRow In dtExcel.Rows
                    tab = ""
                    For i = 0 To dtExcel.Columns.Count - 1
                        Response.Write(tab & datarow(i).ToString())
                        tab = vbTab
                    Next
                    Response.Write(vbCr)
                Next
                Response.End()
            End If


AcuitiDP - Oracle Data Provider for DotNetNuke
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Export to ExcelExport to Excel


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out