)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to export the OLAP Client to CSV format?

Platform: ASP.NET Web Forms (Classic) |
Control: OlapClient |
Published Date: March 12, 2015 |
Last Revised Date: July 2, 2019

This KB illustrates that how to export the OLAP Client to CSV format.

Solution

You can export the OLAP Client to CSV format by using the following code examples.

HTML

<asp:Button ID="btnCSV" runat="server" Text="Export to CSV" OnClick=" btnCSV_Click" />

 

C#

protected void btnCSV_Click(object sender, EventArgs e)
{
    string csvContent = string.Empty, csvLine = String.Empty;
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=sample.csv");
    HttpContext.Current.Response.ContentType = "text/csv";
    HttpContext.Current.Response.AddHeader("Pragma", "public");
    for (int i = 0; i < this.OlapClient1.OlapDataManager.PivotEngine.TableColumns[0].Cells.Count; i++)
    {
        foreach (var column in this.OlapClient1.OlapDataManager.PivotEngine.TableColumns)
        {
            if (column.Cells[i].CellValue != null)
                csvContent = csvContent + (column.Cells[i].CellValue.Replace(",", "") + ",");
            else
                csvContent = csvContent + ",";
         }
         csvContent = csvContent + "\n";
     }
     HttpContext.Current.Response.Write(csvContent.ToString());
     HttpContext.Current.Response.Write(Environment.NewLine);
     HttpContext.Current.Response.End();
}

 

VB

Protected Sub btnCSV_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim csvContent As String = String.Empty, csvLine As String = String.Empty
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=sample.csv")
HttpContext.Current.Response.ContentType = "text/csv"
HttpContext.Current.Response.AddHeader("Pragma", "public")
    For i As Integer = 0 To Me.OlapClient1.OlapDataManager.PivotEngine.TableColumns(0).Cells.Count - 1
    For Each Dim column In Me.OlapClient1.OlapDataManager.PivotEngine.TableColumns
    If column.Cells(i).CellValue IsNot Nothing Then
       csvContent = csvContent & (column.Cells(i).CellValue.Replace(",", "") & ",")
    Else
       csvContent = csvContent & ","
     End If
   Next column
      csvContent = csvContent & Constants.vbLf
   Next i
 HttpContext.Current.Response.Write(csvContent.ToString())
 HttpContext.Current.Response.Write(Environment.NewLine)
 HttpContext.Current.Response.End()
End Sub

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon