Конвертирование Excel файла в DOCX, PDF, RTF на C# и .NET


Полный код

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 });
        }
    }
}

Download

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

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.