Convert Excel to DOCX, PDF, RTF using C# and .NET
Complete code
using SautinSoft;
using System.IO;
namespace Sample
{
internal class Sample
{
private static void Main(string[] args)
{
//Prepare variables with path.
string excelFile = Path.GetFullPath(@"..\..\..\test.xlsx");
string docxFile = Path.ChangeExtension(excelFile, ".docx"); ;
string rtfFile = Path.ChangeExtension(excelFile, ".rtf"); ;
string pdfFile = Path.ChangeExtension(excelFile, ".pdf"); ;
ExcelToPdf x = new ExcelToPdf();
// Set DOCX as output format.
x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Docx;
x.ConvertFile(excelFile, docxFile);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docxFile) { UseShellExecute = true });
// Set RTF as output format.
x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Rtf;
x.ConvertFile(excelFile, rtfFile);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(rtfFile) { UseShellExecute = true });
// Set PDF as output format.
x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf;
x.ConvertFile(excelFile, pdfFile);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfFile) { UseShellExecute = true });
}
}
}
Imports System.IO
Imports SautinSoft
Module Sample
Sub Main()
' Prepare variables with path.
Dim excelFile As String = Path.GetFullPath("..\..\..\test.xlsx")
Dim docxFile As String = Path.ChangeExtension(excelFile, ".docx")
Dim rtfFile As String = Path.ChangeExtension(excelFile, ".rtf")
Dim pdfFile As String = Path.ChangeExtension(excelFile, ".pdf")
Dim x As New ExcelToPdf()
' Set DOCX as output format.
x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Docx
x.ConvertFile(excelFile, docxFile)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(docxFile) With {.UseShellExecute = True})
' Set RTF as output format.
x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Rtf
x.ConvertFile(excelFile, rtfFile)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(rtfFile) With {.UseShellExecute = True})
' Set PDF as output format.
x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf
x.ConvertFile(excelFile, pdfFile)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfFile) With {.UseShellExecute = True})
End Sub
End Module
If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: