This KB illustrates that how to export the OLAP Client to CSV format. SolutionYou 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(); }
VBProtected 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
|
This page will automatically be redirected to the sign-in page in 10 seconds.