我的ASP.NET网站上有一个水晶报告,它已成功显示,但无法导出到Microsoft Access。客户端的操作系统是Windows 8 32位。以下是出现的错误:
我高度评价任何建议。提前谢谢。
答案 0 :(得分:0)
首先需要添加单选按钮,如下所示:
<tr>
<td>
</td>
<td>
<asp:RadioButtonList ID="rblFormat" runat="server" RepeatDirection="Horizontal" CssClass="Profiletitletxt">
<asp:ListItem Text="PDF" Value="1" Selected="True"></asp:ListItem>
<asp:ListItem Text="MS Word" Value="2"></asp:ListItem>
<asp:ListItem Text="MS Excel" Value="3"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
</td>
</tr>
在绑定报告的代码中添加:
If rblFormat.SelectedValue = 1 Then
cryRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")
ElseIf rblFormat.SelectedValue = 2 Then
cryRpt.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, True, "ExportedReport")
ElseIf rblFormat.SelectedValue = 3 Then
ExportDataSetToExcel(DT, "ExportedReport")
End If
对于Excel添加:
Public Shared Sub ExportDataSetToExcel(ByVal ds As DataTable, ByVal filename As String)
Dim response As HttpResponse = HttpContext.Current.Response
response.Clear()
response.Buffer = True
response.Charset = ""
response.ContentType = "application/vnd.ms-excel"
Using sw As New StringWriter()
Using htw As New HtmlTextWriter(sw)
Dim dg As New DataGrid()
dg.DataSource = ds
dg.DataBind()
dg.RenderControl(htw)
response.Charset = "UTF-8"
response.ContentEncoding = System.Text.Encoding.UTF8
response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble())
response.Output.Write(sw.ToString())
response.[End]()
End Using
End Using
End Sub