原創(chuàng)|其它|編輯:郝浩|2012-12-03 14:09:22.000|閱讀 1968 次
概述:下面的例子演示了如何使用XtraReport將報(bào)表導(dǎo)出為XLS格式。在這個(gè)過程中會(huì)用到XtraReport.ExportToXls方法。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
下面的例子演示了如何使用XtraReport將報(bào)表導(dǎo)出為XLS格式。在這個(gè)過程中會(huì)用到XtraReport.ExportToXls方法。
在示例之前,您首先需要添加一個(gè)新報(bào)表(命名為XtraReport1)到你的項(xiàng)目中,將一些報(bào)表控件拖放其中,然后執(zhí)行下面的代碼。
C#:Form1.cs
using System; using System.Windows.Forms; using System.Diagnostics; using DevExpress.XtraPrinting; using DevExpress.XtraReports.UI; // ... namespace ExportToXlsCS { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // A path to export a report. string reportPath = "c:\\Test.xls"; // Create a report instance. XtraReport1 report = new XtraReport1(); // Get its XLS export options. XlsExportOptions xlsOptions = report.ExportOptions.Xls; // Set XLS-specific export options. xlsOptions.ShowGridLines = true; xlsOptions.TextExportMode = TextExportMode.Value; // Export the report to XLS. report.ExportToXls(reportPath); // Show the result. StartProcess(reportPath); } // Use this method if you want to automaically open // the created XLS 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:Form1.vb
Imports Microsoft.VisualBasic Imports System Imports System.Windows.Forms Imports System.Diagnostics Imports DevExpress.XtraPrinting Imports DevExpress.XtraReports.UI ' ... Namespace ExportToXlsCS Partial Public Class Form1 Inherits Form Public Sub New() InitializeComponent() End Sub Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click ' A path to export a report. Dim reportPath As String = "c:\Test.xls" ' Create a report instance. Dim report As New XtraReport1() ' Get its XLS export options. Dim xlsOptions As XlsExportOptions = report.ExportOptions.Xls ' Set XLS-specific export options. xlsOptions.ShowGridLines = True xlsOptions.TextExportMode = TextExportMode.Value ' Export the report to XLS. report.ExportToXls(reportPath) ' Show the result. StartProcess(reportPath) End Sub ' Use this method if you want to automaically open ' the created XLS 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 End Class End Namespace
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)