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 }); }
static void Main(string[] args) { // Convert Excel file to DOCX file ExcelToPdf x = new ExcelToPdf(); // Set DOCX as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Docx; string excelFile = Path.GetFullPath(@"..\..\test.xls"); string docxFile = Path.ChangeExtension(excelFile, ".docx");; try { x.ConvertFile(excelFile, docxFile); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docxFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
static void Main(string[] args) { // Set custom sheets to convert. ExcelToPdf x = new ExcelToPdf(); x.PageStyle.PageSize.Letter(); // Set PDF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf; // Let's convert only sheets: 1,3. x.Sheets.Custom(new int[] { 1, 3 }); string excelFile = Path.GetFullPath(@"..\..\test.xlsx"); string pdfFile = Path.ChangeExtension(excelFile, ".pdf");; try { x.ConvertFile(excelFile, pdfFile); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
static void Main(string[] args) { // Convert Excel file to DOCX file ExcelToPdf x = new ExcelToPdf(); // You may download the latest version of SDK here: // www.sautinsoft.com/convert-excel-xls-to-pdf/free-download-spreadsheet-xls-excel-to-pdf-component.php // Set DOCX as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Docx; string excelFile = Path.GetFullPath(@"d:\Download\test.xls"); string docxFile = Path.ChangeExtension(excelFile, ".docx");; try { x.ConvertFile(excelFile, docxFile); System.Diagnostics.Process.Start(docxFile); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
static void Main(string[] args) { // Fit each sheet to a single page fixed size. ExcelToPdf x = new ExcelToPdf(); // Fit each sheet to single PDF page, A4 format. x.PageStyle.PageSize.A4(); x.PageStyle.PageScale.Auto(); // Set PDF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf; string excelFile = Path.GetFullPath(@"..\..\test.xlsx"); string pdfFile = Path.ChangeExtension(excelFile, ".pdf");; try { x.ConvertFile(excelFile, pdfFile); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
static void Main(string[] args) { // Convert a password protected workbook ExcelToPdf x = new ExcelToPdf(); // Set PDF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf; // Set the password for protected workbook. x.Password = "******"; string excelFile = Path.GetFullPath(@"..\..\test.xls"); string pdfFile = Path.ChangeExtension(excelFile, ".pdf");; try { x.ConvertFile(excelFile, pdfFile); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
static void Main(string[] args) { // Add page numbers in the resulting PDF. ExcelToPdf x = new ExcelToPdf(); // Set PDF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf; // Set page numbers in format "Page 1 of N" formatted by Arial, 14 pt. x.PageStyle.PageNumFormat.Text = "Page {page} of {numPages}"; x.PageStyle.PageNumFormat.FontFace = "Arial"; x.PageStyle.PageNumFormat.FontSize = 14; string excelFile = Path.GetFullPath(@"..\..\test.xlsx"); string pdfFile = Path.ChangeExtension(excelFile, ".pdf");; try { x.ConvertFile(excelFile, pdfFile); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
private void dönüştür_Click(object sender, EventArgs e) { ExcelToPdf x = new ExcelToPdf(); x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Docx; try { x.ConvertFile(excelFile, docxFile); MessageBox.Show("Dönüştürme işlemi başarılı ."); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
static void Main(string[] args) { // Split PDF by pages. // 1. Let's get a PDF with 3 pages from .xlsx. // 2. Let's split it by 3 PDF files and show them. ExcelToPdf x = new ExcelToPdf(); x.PageStyle.PageSize.Letter(); x.PageStyle.PageMarginTop.mm(5); // Set PDF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf; string excelFile = Path.GetFullPath(@"..\..\test.xlsx"); FileInfo pdfFile = new FileInfo(Path.ChangeExtension(excelFile, ".pdf")); try { // 1. Let's get a PDF with 3 pages from .xlsx. x.ConvertFile(excelFile, pdfFile.FullName); // 2. Let's split it by 3 PDF files and show them. // Create a directory for storing separate PDFs. DirectoryInfo pdfDir = pdfFile.Directory.CreateSubdirectory("My Pages"); x.SplitPDFFileToPDFFolder(pdfFile.FullName, pdfDir.FullName); // Show result FileInfo[] pageFiles = pdfDir.GetFiles("*.pdf"); Console.WriteLine("Resulting PDF files:\n"); foreach (FileInfo pageFile in pageFiles) { Console.WriteLine(pageFile.Name); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); }
static void Main(string[] args) { // Merge two PDF files. // 1. Let's get a PDF from .xlsx. // 2. Let's merge this PDF with itself. ExcelToPdf x = new ExcelToPdf(); x.PageStyle.PageSize.Letter(); x.PageStyle.PageMarginTop.mm(5); // Set PDF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf; // Let's convert only 3rd page. x.Sheets.Custom(new int[] { 3 }); string excelFile = Path.GetFullPath(@"..\..\test.xlsx"); FileInfo pdfFile = new FileInfo(Path.ChangeExtension(excelFile, ".pdf")); string singlePdf = Path.Combine(pdfFile.Directory.FullName, "Single.pdf"); try { // 1. Convert Excel to PDF. x.ConvertFile(excelFile, pdfFile.FullName); // 2. Merge the PDF file with itself. x.MergePDFFileArrayToPDFFile(new string[] { pdfFile.FullName, pdfFile.FullName }, singlePdf); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(singlePdf) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }