下面的示例将演示如何使用XtraReport将报表导出为HTML,首先需要在项目中添加一个新的报表(XtraReport1),并将报表控件拖放在项目中,然后执行下面的代码。
C#
using System.Drawing;
using System.Diagnostics;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
// ...
private void button1_Click(object sender, EventArgs e)
{
// A path to export a report.
string reportPath = "c:\\Test.html";
// Create a report instance.
XtraReport1 report = new XtraReport1();
// Get its HTML export options.
HtmlExportOptions htmlOptions = report.ExportOptions.Html;
// Set HTML-specific export options.
htmlOptions.CharacterSet = "UTF-8";
htmlOptions.RemoveSecondarySymbols = false;
htmlOptions.Title = "Test Title";
// Set the pages to be exported, and page-by-page options.
htmlOptions.ExportMode = HtmlExportMode.SingleFilePageByPage;
htmlOptions.PageRange = "1, 3-5";
htmlOptions.PageBorderColor = Color.Blue;
htmlOptions.PageBorderWidth = 3;
// Export the report to HTML.
report.ExportToHtml(reportPath);
// Show the result.
StartProcess(reportPath);
}
// Use this method if you want to automaically open
// the created HTML file in the default program.
public void StartProcess(string path)
{
Process process = new Process();
try
{
process.StartInfo.FileName = path;
process.Start();
process.WaitForInputIdle();
}
catch { }
}
VB
Imports System.Drawing
Imports System.Diagnostics
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
' ...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
' A path to export a report.
Dim reportPath As String = "c:\\Test.html"
' Create a report instance.
Dim report As New XtraReport1()
' Get its HTML export options.
Dim htmlOptions As HtmlExportOptions = report.ExportOptions.Html
' Set HTML-specific export options.
htmlOptions.CharacterSet = "UTF-8"
htmlOptions.RemoveSecondarySymbols = False
htmlOptions.Title = "Test Title"
' Set the pages to be exported, and page-by-page options.
htmlOptions.ExportMode = HtmlExportMode.SingleFilePageByPage
htmlOptions.PageRange = "1, 3-5"
htmlOptions.PageBorderColor = Color.Blue
htmlOptions.PageBorderWidth = 3
' Export the report to HTML.
report.ExportToHtml(reportPath)
' Show the result.
StartProcess(reportPath)
End Sub
' Use this method if you want to automaically open
' the created HTML file in the default program.
Public Sub StartProcess(ByVal path As String)
Dim process As New Process()
Try
process.StartInfo.FileName = path
process.Start()
process.WaitForInputIdle()
Catch
End Try
End Sub
标签:
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至hey@evget.com
文章转载自:慧都控件网