Ejemplo n.º 1
0
        private static void Main(string[] args)
        {
            string directoryWithExcelFiles;

            if (args.Length == 0)
            {
                // If no directory path is passed as argument, consider the current process directory
                directoryWithExcelFiles = Directory.GetCurrentDirectory();
            }
            else
            {
                directoryWithExcelFiles = Path.GetFullPath(args[0]);
            }

            var excelFilesToConvert             = Directory.EnumerateFiles(directoryWithExcelFiles, "*.xls");
            var excelInteropExcelToPdfConverter = new ExcelInteropExcelToPdfConverter();

            try
            {
                excelInteropExcelToPdfConverter.ConvertToPdf(excelFilesToConvert);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine($"Something went wrong: {ex.Message}");
                Environment.ExitCode = -1;
                return;
            }

            Console.WriteLine("Operation completed");
        }
Ejemplo n.º 2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            string directoryWithExcelFiles;
            string sourceFolder      = tbSource.Text;
            string destinationFolder = tbDestination.Text;
            string sMsg = @"Sit back and Relax, Your Excel(s) are being Converted to PDF...";

            Log.Write($"Source : {sourceFolder}");
            Log.Write($"Destination : {destinationFolder}");

            tbDestination.Hide();
            tbSource.Hide();
            btnConvert.Hide();
            btnSource.Hide();
            btnDestination.Hide();
            lblMsg.Text = sMsg;
            lblMsg.Show();

            if (sourceFolder.Length == 0)
            {
                // If no directory path is passed as argument, consider the current process directory
                //directoryWithExcelFiles = Directory.GetCurrentDirectory();
                MessageBox.Show("Select Source Folder.", "Select Folder");
            }
            else
            {
                directoryWithExcelFiles = Path.GetFullPath(sourceFolder);

                if (destinationFolder.Length == 0)
                {
                    destinationFolder = sourceFolder;
                }

                var excelFilesToConvert = Directory.EnumerateFiles(directoryWithExcelFiles, "*.xls");

                Log.Write($"" +
                          $"Files to Convert :" +
                          $"================");
                var i = 1;
                foreach (var sPath in excelFilesToConvert)
                {
                    Log.Write($"File ({i}) : {sPath.ToString()}");
                    i++;
                }

                var excelInteropExcelToPdfConverter = new ExcelInteropExcelToPdfConverter();

                try
                {
                    excelInteropExcelToPdfConverter.ConvertToPdf(excelFilesToConvert, destinationFolder);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Something went wrong: {ex.Message}");
                    Log.Write($"Something went wrong: {ex.Message}");

                    Environment.ExitCode = -1;

                    tbDestination.Show();
                    tbSource.Show();
                    btnConvert.Show();
                    btnSource.Show();
                    btnDestination.Show();
                    lblMsg.Text = sMsg;
                    lblMsg.Hide();

                    return;
                }
            }

            MessageBox.Show("Operation completed");
        }