使用 ActiveReports 时如何导出报告
-
26-09-2019 - |
题
我在 VB 程序中使用 Active Reports 根据我的数据生成报告。现在我的报告打开得很好,它允许用户打印、复制、查找等。我不确定如何添加功能以让用户在程序运行后选择导出图表。
我看过很多教程,但总有一些东西使它无法在我的程序中工作。例如 这 论坛提供了我想要的确切代码,因为他们将导出按钮添加到工具栏,然后将功能添加到按钮。不幸的是我无法访问工具栏。他们通过以下方式访问它 Me.Toolbar
我无法通过这种方式访问它。
另一个论坛 这里 不会将导出添加到工具栏,而是将其直接插入代码中,但我不确定要导入什么才能允许我这样做,因为我的项目无法识别 ActiveReportsPDFExport.ARExportPDF
.
更新:
找到了一种通过在设计格式中添加到ActiveReport中来导出为PDF的方法 DataDynamics.ActiveReports.Export.Pdf.PdfExport
然后从我的代码调用 PdfExport1.Export(Me.Document, "D:\Kyra\HELP.pdf")
问题:
- 这是在打开活动报告的函数末尾调用的。我希望用户能够选择导出报告,然后可以选择他们想要保存报告的格式和位置。
解决方案
下面是使用 VB.NET 和 ActiveReports 6 将 PDF 导出按钮添加到 ActiveReports 工具栏的代码:
Const pdfExportToolID As Long = 42
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myExportTool As DataDynamics.ActiveReports.Toolbar.Button
myExportTool = New DataDynamics.ActiveReports.Toolbar.Button()
myExportTool.ButtonStyle = DataDynamics.ActiveReports.Toolbar.ButtonStyle.Text
myExportTool.Caption = "Export to PDF"
myExportTool.Id = pdfExportToolID
Me.Viewer1.Toolbar.Tools.Add(myExportTool)
' load report:
Dim rpt As New NewActiveReport1()
Me.Viewer1.Document = rpt.Document
rpt.Run(False)
End Sub
Private Sub Viewer1_ToolClick(ByVal sender As System.Object, ByVal e As DataDynamics.ActiveReports.Toolbar.ToolClickEventArgs) Handles Viewer1.ToolClick
If (e.Tool.Id = pdfExportToolID) Then
Dim pdf As New DataDynamics.ActiveReports.Export.Pdf.PdfExport()
pdf.Export(Me.Viewer1.Document, "C:\users\scott\junk\myActiveReport.pdf")
End If
End Sub
此代码在名为“Viewer1”的表单上具有 ActiveReports Viewer 的表单内部运行。
希望这可以帮助,
Scott Willeke
GrapeCity
其他提示
只需按照说明进行操作即可 这里. 。具体来说,他们添加了“cmdExport”按钮,让用户开始导出。
这段代码对我有用,只需将其传递给 Webviewer 对象即可。
ABC.Run();
ARWebViewer.Report = ABC;
ExportToExcel(ARWebViewer); // call ExportToExcel method,
public void ExportToExcel(DataDynamics.ActiveReports.Web.WebViewer objWebviewer)
{
DataDynamics.ActiveReports.Export.Xls.XlsExport XLSexport = new DataDynamics.ActiveReports.Export.Xls.XlsExport();
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
if (XLSexport == null)
XLSexport = new DataDynamics.ActiveReports.Export.Xls.XlsExport();
XLSexport.AutoRowHeight = true;
XLSexport.MinColumnWidth = (float)0.2;
XLSexport.RemoveVerticalSpace = true;
XLSexport.UseCellMerging = true;
XLSexport.Export(objWebviewer.Report.Document, memStream);
memStream.Position = 0;
Response.ContentType = "application/Xls";
Response.AddHeader("content-disposition", "attachment; filename=" + ajDoc + ".Xls");
Response.BinaryWrite(memStream.ToArray());
Response.End();
XLSexport = null;
}
不隶属于 StackOverflow