This sample demonstrates how to export data table into rtf file.
private void btnRTF_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection oleDbConnection1
= new System.Data.OleDb.OleDbConnection();
oleDbConnection1.ConnectionString
= @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\Database\demo.mdb";
System.Data.OleDb.OleDbCommand oleDbCommand1
= new System.Data.OleDb.OleDbCommand();
oleDbCommand1.CommandText = "select * from parts";
oleDbCommand1.Connection = oleDbConnection1;
Spire.DataExport.RTF.RTFExport rtfExport1
= new Spire.DataExport.RTF.RTFExport();
rtfExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
rtfExport1.DataFormats.CultureName = "zh-CN";
rtfExport1.DataFormats.Currency = "c";
rtfExport1.DataFormats.DateTime = "yyyy-M-d H:mm";
rtfExport1.DataFormats.Float = "g";
rtfExport1.DataFormats.Integer = "g";
rtfExport1.DataFormats.Time = "H:mm";
rtfExport1.FileName = "sample.doc";
rtfExport1.RTFOptions.DataStyle.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
rtfExport1.RTFOptions.FooterStyle.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
rtfExport1.RTFOptions.HeaderStyle.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World);
rtfExport1.RTFOptions.TitleStyle.Alignment = Spire.DataExport.RTF.RtfTextAlignment.Center;
rtfExport1.RTFOptions.TitleStyle.Font = new System.Drawing.Font("Arial", 10F, System.Drawing.FontStyle.Bold);
rtfExport1.SQLCommand = oleDbCommand1;
oleDbConnection1.Open();
rtfExport1.SaveToFile();
}
Private Sub btnRTF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRTF.Click
Dim oleDbConnection1 As New System.Data.OleDb.OleDbConnection()
oleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\Database\demo.mdb"
Dim oleDbCommand1 As New System.Data.OleDb.OleDbCommand()
oleDbCommand1.CommandText = "select * from parts"
oleDbCommand1.Connection = oleDbConnection1
Dim rtfExport1 As New Spire.DataExport.RTF.RTFExport()
rtfExport1.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView
rtfExport1.DataFormats.CultureName = "zh-CN"
rtfExport1.DataFormats.Currency = "c"
rtfExport1.DataFormats.DateTime = "yyyy-M-d H:mm"
rtfExport1.DataFormats.Float = "g"
rtfExport1.DataFormats.[Integer] = "g"
rtfExport1.DataFormats.Time = "H:mm"
rtfExport1.FileName = "sample.doc"
rtfExport1.RTFOptions.DataStyle.Font = New System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World)
rtfExport1.RTFOptions.FooterStyle.Font = New System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World)
rtfExport1.RTFOptions.HeaderStyle.Font = New System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World)
rtfExport1.RTFOptions.TitleStyle.Alignment = Spire.DataExport.RTF.RtfTextAlignment.Center
rtfExport1.RTFOptions.TitleStyle.Font = New System.Drawing.Font("Arial", 10.0F, System.Drawing.FontStyle.Bold)
rtfExport1.SQLCommand = oleDbCommand1
oleDbConnection1.Open()
rtfExport1.SaveToFile()
End Sub