Demetri avait écrit le 31.07.2006 :
No tangible example but its not that hard.
You have a web folder setup where the file will be written out to. Make sure
permissions are setup for ASPNet User to write out the files there.
Your method that extracts the data from the grid then converts that data to
an excel format (most common is CSV) and then outputs it to a file in the web
folder mentioned above.
Then at the end of that method it does a Redirect to that file.
--
-Demetri
"Amirallia" wrote:
>Demetri a formulé la demande :
>>You could write it out to disk and then redirect to it, providing the
directory the file is written to is a virtual one.
--
-Demetri
"Amirallia" wrote:
Hello
Here's my code to export a datagrid to Exel :
Response.Clear( )
Response.Buffer = True
Response.Conten tType = "applicatio n/vnd.ms-excel"
Response.Charse t = ""
Dim monStringWriter As StringWriter = New StringWriter
Dim monHtmlTextWrit er As HtmlTextWriter = New
HtmlTextWrit er(monStringWri ter)
monDG.RenderCon trol(monHtmlTex tWriter)
Response.Write( monStringWriter .ToString())
Response.End()
It's work perfectly, but when my datagrid displays for exeample 10000
rows,
the export doesn't work.
Instead I have the page impossible to display !!!!
Any idea ?
Do you have an example ?
Thanks
sorry but it makes the same thing, directly redirect to a white page.
If I put a break point in my code, when I click on the button, It'
doesn't stop... Here'is my code
Dim Separator As String = ";"
Dim lLigne, lCol As Integer
Dim item As DataGridColumn
Dim strValeur As String
Dim monStreamWriter As System.IO.Strea mWriter = New
System.IO.Strea mWriter(Server. MapPath("./") & "upload\xxx.csv ")
Try
For Each item In dg.Columns
monStreamWriter .WriteLine(item .HeaderText & Separator)
Next item
monStreamWriter .WriteLine(Cont rolChars.NewLin e)
For lLigne = 1 To Me.dg.Items.Cou nt - 1
For lCol = 0 To Me.dg.Items(lLi gne).Cells.Coun t - 1
If Me.dg.Items(lLi gne).Cells(lCol ).Text = " "
Then
strValeur = ""
Else
strValeur =
Me.dg.Items(lLi gne).Cells(lCol ).Text
End If
strValeur = strValeur & Separator
Next
monStreamWriter .WriteLine(strV aleur & Separator)
monStreamWriter .WriteLine(Cont rolChars.NewLin e)
Next
monStreamWriter .Close()
Response.Redire ct("Upload\xxx. csv")