public static void ConvertExcelAsByteArray() { // Convert Excel to RTF in memory ExcelToPdf x = new ExcelToPdf(); // Set RTF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Rtf; // Let's create trace file. x.CreateTraceFile = true; x.TraceFilePath = Path.GetFullPath(@"..\..\trace.txt"); string excelFile = Path.GetFullPath(@"..\..\test.xls"); string rtfFile = Path.ChangeExtension(excelFile, ".rtf");; byte[] excelBytes = File.ReadAllBytes(excelFile); byte[] rtfBytes = null; try { rtfBytes = x.ConvertBytes(excelBytes); // Save rtfBytes to a file for demonstration purposes. File.WriteAllBytes(rtfFile, rtfBytes); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(rtfFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
public static void ConvertExcelAsMemoryStream() { // Convert Excel to DOCX in memory 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"); byte[] docxBytes = null; try { // Let us say, we have a memory stream with Excel data. using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(excelFile))) { docxBytes = x.ConvertBytes(ms.ToArray()); } // Save docxBytes to a file for demonstration purposes. File.WriteAllBytes(docxFile, docxBytes); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docxFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
public static void ConvertExcelAsByteArray() { // Convert Excel to PDF in memory ExcelToPdf x = new ExcelToPdf(); // Set PDF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf; string excelFile = Path.GetFullPath(@"..\..\test.xls"); string pdfFile = Path.ChangeExtension(excelFile, ".pdf");; byte[] excelBytes = File.ReadAllBytes(excelFile); byte[] pdfBytes = null; try { pdfBytes = x.ConvertBytes(excelBytes); // Save pdfBytes to a file for demonstration purposes. File.WriteAllBytes(pdfFile, pdfBytes); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pdfFile) { UseShellExecute = true }); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
private void Button_Click2(object sender, RoutedEventArgs e) //.xlsx { //SautinSoft.ExcelToPdf convert.xls and .xlsx to PDF, RTF, DOCX //SautinSoft.ExcelToPdf x = new SautinSoft.ExcelToPdf(); ////x.ConvertFile(@"C:\Users\user\Desktop\kkkkkkkk\d\d\dokum\Business-Budget.xlsx", @"d:C:\Users\user\Desktop\kkkkkkkk\d\d\dokum\Table.pdf"); //Convert Excel to PDF in memory ExcelToPdf x = new ExcelToPdf(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.CheckFileExists = true; openFileDialog.Multiselect = true; //openFileDialog.Filter = "Doc files (*.xls)|*.xls|All files (*.*)|*.*"; openFileDialog.Filter = "Doc files (*.xlsx)|*.xlsx|All files (*.*)|*.*"; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); Nullable <bool> result = openFileDialog.ShowDialog(); if (result == true) { string excelFile = openFileDialog.FileName; // Open document string pdfFile = @"C:\Users\Mariia\Desktop\Convertor\PDFfromXLS.pdf"; // Set PDF as output format. x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf; byte[] pdfBytes = null; try { // Let us say, we have a memory stream with Excel data. using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(excelFile))) { pdfBytes = x.ConvertBytes(ms.ToArray()); } // Save pdfBytes to a file for demonstration purposes. File.WriteAllBytes(pdfFile, pdfBytes); System.Diagnostics.Process.Start(pdfFile); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } } //string excelFile = @"D:\Desktop\1ДЗ\Курсач\d3 (1)\d3\d\d\dokum\Business-Budget.xlsx"; //string pdfFile = System.IO.Path.ChangeExtension(excelFile, ".pdf"); }