none
Export Chart Into CSV

    Pregunta

  • I have a page with a chart. To export the data to CSV is already success. How can i export include the chart into the CSV file?

    current code

    Protected Sub ExportToCSV(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExpCSV.Click
    
    openConn("smsadminv2")
    
            If Me.slcview.SelectedValue = 1 Then
    
                If chkKeyword.Checked = False Then
                    strSQL = "SELECT day(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and Month(s.datecreated) ='" & Me.slcMonth.SelectedValue & "' and s.status=1 and p.keyword ='" & Me.slcKW.SelectedValue & "' GROUP BY day(s.date_unsubs) ORDER BY day(s.date_unsubs)"
                Else
                    strSQL = "SELECT day(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and Month(s.datecreated) ='" & Me.slcMonth.SelectedValue & "' and s.status=1 GROUP BY day(s.date_unsubs) ORDER BY day(s.date_unsubs)"
                End If
    
            ElseIf Me.slcview.SelectedValue = 2 Then
                Session("fromdate") = Me.slcMonth.SelectedValue - 1
                If chkKeyword.Checked = False Then
                    strSQL = "SELECT day(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and p.keyword ='" & Me.slcKW.SelectedValue & "' and  s.status=1 and s.date_unsubs>='" & Now.Date.AddDays(-7).ToString("MM/dd/yyyy") & "' and s.date_unsubs<'" & Now.Date.ToString("MM/dd/yyyy") & "' and Month(s.datecreated) ='" & Session("fromdate") & "' GROUP BY day(s.date_unsubs) ORDER BY day(s.date_unsubs)"
                Else
                    strSQL = "SELECT day(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and s.status=1 and s.date_unsubs>='" & Now.Date.AddDays(-7).ToString("MM/dd/yyyy") & "' and s.date_unsubs<'" & Now.Date.ToString("MM/dd/yyyy") & "' and Month(s.datecreated) ='" & Me.slcMonth.SelectedValue & "' GROUP BY day(s.date_unsubs) ORDER BY day(s.date_unsubs)"
                End If
    
            ElseIf Me.slcview.SelectedValue = 3 Then
                Session("fromdate") = "1/1/" & Year(Now)
                If chkKeyword.Checked = False Then
                    strSQL = "SELECT MONTH(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and p.keyword ='" & Me.slcKW.SelectedValue & "' and s.status=1 and s.date_unsubs>='" & Session("fromdate") & "' and s.date_unsubs<'" & Now.Date.ToString("MM/dd/yyyy") & "' GROUP BY MONTH(s.date_unsubs) ORDER BY MONTH(s.date_unsubs)"
                Else
                    strSQL = "SELECT MONTH(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and s.status=1 and s.date_unsubs>='" & Session("fromdate") & "' and s.date_unsubs<'" & Now.Date.ToString("MM/dd/yyyy") & "' GROUP BY MONTH(s.date_unsubs) ORDER BY MONTH(s.date_unsubs)"
                End If
    
            ElseIf Me.slcview.SelectedValue = 4 Then
                Session("fromdate") = "1/1/" & Year(Now) - 1
                Session("todate") = "12/30/" & Year(Now) - 1
    
                If chkKeyword.Checked = False Then
                    strSQL = "SELECT MONTH(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and s.status=1 and p.keyword ='" & Me.slcKW.SelectedValue & "' and s.date_unsubs>='" & Session("fromdate") & "' and s.date_unsubs<'" & Session("todate") & "' GROUP BY MONTH(s.date_unsubs) ORDER BY MONTH(s.date_unsubs)"
                Else
                    strSQL = "SELECT MONTH(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and s.status=1 and s.date_unsubs>='" & Session("fromdate") & "' and s.date_unsubs<'" & Session("todate") & "' GROUP BY MONTH(s.date_unsubs) ORDER BY MONTH(s.date_unsubs)"
                End If
    
            ElseIf Me.slcview.SelectedValue = 5 Then
                Session("fromdate") = "1/1/" & Year(Now) - 1
                Session("todate") = "12/30/" & Year(Now) - 1
    
                If chkKeyword.Checked = False Then
                    strSQL = "SELECT year(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and s.status=1 and p.keyword ='" & Me.slcKW.SelectedValue & "' and s.date_unsubs<'" & Now.Date.ToString("MM/dd/yyyy") & "' GROUP BY year(s.date_unsubs) ORDER BY year(s.date_unsubs)"
                Else
                    strSQL = "SELECT year(s.date_unsubs) as Day, count(s.msisdn) as Total FROM tblSubscriber AS s INNER JOIN tblProvDet AS p ON s.provid = p.provid WHERE (p.provider_id = 146) and s.status=1 and s.date_unsubs<'" & Now.Date.ToString("MM/dd/yyyy") & "' GROUP BY year(s.date_unsubs) ORDER BY year(s.date_unsubs)"
                End If
    
            End If
    
            Dim dt As New DataTable
            adp = New SqlDataAdapter(strSQL, cn)
            adp.Fill(dt)
    
    
            Response.Clear()
            Response.Buffer = True
            Response.AddHeader("content-disposition", _
                    "attachment;filename=Total_Un-Subscribers.csv")
            Response.Charset = ""
            Response.ContentType = "application/text"
    
            Dim sb As New StringBuilder()
            For k As Integer = 0 To dt.Columns.Count - 1
                sb.Append(dt.Columns(k).ColumnName + ","c)
            Next
    
            sb.Append(vbCr & vbLf)
            For i As Integer = 0 To dt.Rows.Count - 1
                For k As Integer = 0 To dt.Columns.Count - 1
      
                    sb.Append(dt.Rows(i)(k).ToString().Replace(",", ";") + ","c)
                Next
                sb.Append(vbCr & vbLf)
            Next
            Response.Output.Write(sb.ToString())
            Response.Flush()
            Response.End()



    jueves, 31 de mayo de 2012 10:01

Respuestas

Todas las respuestas