예제 #1
0
        private void convertXlsx()
        {
            try
            {
                LogText.Text            = "";
                ConvertButton.IsEnabled = false;
                XlsxConverter converter = new XlsxConverter(MappingFileText.Text, InputDirectoryText.Text, XlsxSettings.OutputDirectory, XlsxSettings.MoveDirectory, SchemaFileText.Text, SchematronFileText.Text);

                converter.LogEvent += delegate(string logText)
                {
                    Dispatcher.Invoke(() =>
                    {
                        LogText.Text += logText + "\n";
                    });
                };

                converter.ConversionComplete += delegate()
                {
                    Dispatcher.Invoke(() =>
                    {
                        MessageBox.Show("Done!");
                        EnableConvertButton();
                    });
                };

                Thread thr = new Thread(new ThreadStart(converter.Convert));
                thr.Start();
            }
            catch (Exception ex)
            {
                LogText.Text += "ERROR: " + ex.Message;
            }
        }
예제 #2
0
        public void HrExport
            (string bstrSourcePath
            , string bstrDestPath
            , string bstrClass
            , IConverterApplicationPreferences pcap
            , out IConverterPreferences ppcp
            , IConverterUICallback pcuic)
        {
//#if DEBUG
            UInt32 plcid;

            pcap.HrGetLcid(out plcid);
            String application;

            pcap.HrGetApplication(out application);
            Int32 pFormat;

            pcap.HrCheckFormat(out pFormat);

            //Int32 pid0;
            //pcuic.HrMessageBox(String.Format("bstrSourcePath: \"{0}\"\nbstrDestPath \"{1}\"\nbstrClass: \"{2}\"\nplcid: {3}, application: \"{4}\", pFormat: {5}", bstrSourcePath, bstrDestPath, bstrClass, plcid, application, pFormat), "HrExport", 0, out pid0);

            _traceSource.TraceInformation("Converter.HrExport\nbstrSourcePath: \"{0}\"\nbstrDestPath \"{1}\"\nbstrClass: \"{2}\"\nplcid: {3}, application: \"{4}\", pFormat: {5}", bstrSourcePath, bstrDestPath, bstrClass, plcid, application, pFormat);
// #endif

            ppcp = new ConverterPreferences();

            try
            {
                Encoding encoding = ComputeEncodeing(bstrClass);

                using (StreamWriter streamWriter = new StreamWriter(bstrDestPath, false, encoding))
                    using (CsvWriter csvWriter = new CsvWriter(streamWriter))
                    {
                        Rfc4180FileWriter  fileWriter         = new Rfc4180FileWriter(csvWriter);
                        WorksheetConverter worksheetConverter = new ProgressWorksheetConverter(pcuic.HrReportProgress);
                        XlsxConverter.Convert(bstrSourcePath, fileWriter, worksheetConverter);
                        fileWriter.Flush();
                        streamWriter.Flush();
                    }
            }
            catch (ActiveWorksheetException)
            {
                _errorMessage = "В книге активной листом является не таблица.\nПожалуйста, выберите лист с таблицей и попробуйте сохранить снова.";
                throw;
            }
            catch (Exception ex)
            {
                _errorMessage = "Возникла внутренняя ошибка. Невозможно сохранить файл.";

                _traceSource.TraceEvent(TraceEventType.Error, 1025, ex.ToString());
                Debug.Fail(ex.ToString());
                throw;
            }
        }
예제 #3
0
        public static void Test(String tempFolderName, String sourceSubfolderPath)
        {
            String subfolderName = Path.GetFileName(sourceSubfolderPath);

            String tempFolder     = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.WorkDirectory, @"Temp\XlsxConverterTesting"));
            String tempFolderPath = Path.Combine(tempFolder, subfolderName);

            String xlsxFilePath     = GetFilePath(Path.Combine(sourceSubfolderPath, "source.xlsx"));
            String templateFilePath = GetFilePath(Path.Combine(sourceSubfolderPath, "template.csv"));
            String csvFilePath      = PrepareCsvFile(Path.Combine(tempFolder, tempFolderName, subfolderName, "result.csv"));

            using (StreamWriter streamWriter = new StreamWriter(csvFilePath))
            {
                CsvWriter csvWriter = new CsvWriter(streamWriter);
                MoqDelimitedTextWriter delimitedTextWriter = new MoqDelimitedTextWriter(csvWriter);
                XlsxConverter.Convert(xlsxFilePath, delimitedTextWriter);
                delimitedTextWriter.Flush();
                streamWriter.Flush();
            }

            FileAssert.AreEqual(csvFilePath, templateFilePath);
        }
예제 #4
0
파일: Tester.cs 프로젝트: maliutin/csv-4180
 public void Test_001()
 {
     Assert.Catch <ActiveWorksheetException>(
         () =>
     {
         String xlsxFilePath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\XlsxConverterTesting\Tester+Files\001\source.xlsx"));
         String csvFilePath  = Path.GetTempFileName();
         try
         {
             using (StreamWriter streamWriter = new StreamWriter(csvFilePath))
             {
                 CsvWriter csvWriter = new CsvWriter(streamWriter);
                 MoqDelimitedTextWriter delimitedTextWriter = new MoqDelimitedTextWriter(csvWriter);
                 XlsxConverter.Convert(xlsxFilePath, delimitedTextWriter);
                 csvWriter.Flush();
                 streamWriter.Flush();
             }
         }
         finally
         {
             File.Delete(csvFilePath);
         }
     });
 }
예제 #5
0
        static void Main(string[] args)
        {
            var result = Parser.Default.ParseArguments <XLSXOptions, MDBOptions, DB2Options>(args)
                         .WithParsed <XLSXOptions>(o =>
            {
                XlsxConverter xlsxConverter = new XlsxConverter(o.MappingConfig, o.InputDirectory, o.OutputDirectory, o.MoveDirectory, o.SchemaPath, o.SchematronPath);
                xlsxConverter.LogEvent     += delegate(string logText)
                {
                    Console.WriteLine(logText);
                };
                xlsxConverter.Convert();
            })
                         .WithParsed <MDBOptions>(o =>
            {
                MSAccessConverter mdbConverter = new MSAccessConverter(o.MappingConfig, o.InputDirectory, o.OutputDirectory, o.MoveDirectory, o.SchemaPath, o.SchematronPath);
                mdbConverter.LogEvent         += delegate(string logText)
                {
                    Console.WriteLine(logText);
                };
                mdbConverter.Convert();
            })
                         .WithParsed <DB2Options>(o =>
            {
                DB2Converter db2Converter = new DB2Converter(o.MappingConfig, o.InputDirectory, o.Database, o.Username, o.Password, o.MoveDirectory, o.SchemaPath, o.SchematronPath);
                db2Converter.LogEvent    += delegate(string logText)
                {
                    Console.WriteLine(logText);
                };
                db2Converter.Convert();
            });

#if DEBUG
            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();
#endif
        }
예제 #6
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            this.btnExport.Enabled = false;
            this.btnCancel.Enabled = false;

            selectedProjects = projects.GetSelectedProjects();
            selectedCultures = cultures.SelectedCultures;

            if (SelectedProjects != null)
            {
                if (SelectedProjects.Count() == Solution.Projects.Count())
                {
                    saveFileDialog.FileName = Solution.Name;
                }
                else if (SelectedProjects.Count() > 1)
                {
                    saveFileDialog.FileName = SelectedProjects[0].Name + "-more";
                }
                else
                {
                    saveFileDialog.FileName = SelectedProjects[0].Name;
                }
            }
            else
            {
                saveFileDialog.FileName = Solution.Name;
            }

            if (SelectedCultures.Count() == 1)
            {
                if (SelectedCultures.First().Culture.Name != "")
                {
                    saveFileDialog.FileName += "-" + SelectedCultures.First().Culture.Name;
                }
            }
            else if (SelectedCultures.Count() == 2)
            {
                saveFileDialog.FileName += "-" + SelectedCultures.First().Culture.Name
                                           + "," + SelectedCultures.ElementAt(1).Culture.Name;
            }
            saveFileDialog.FileName += ".xlsx";

            DialogResult result = saveFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    XlsxConverter excel = null;
                    if (SelectedFileGroups.Count != 0)
                    {
                        excel = new XlsxConverter(SelectedFileGroups, Solution);
                    }
                    else if (SelectedProjects.Count != 0)
                    {
                        excel = new XlsxConverter(SelectedProjects);
                    }
                    else
                    {
                        excel = new XlsxConverter(Solution);
                    }

                    excel.ExportComments = cbkExportComments.Checked;
                    excel.ExportDiff     = cbkExportDiff.Checked;
                    excel.IncludeProjectsWithoutTranslations = cbkIncludeProjectsWithoutTranslations.Checked;
                    excel.AutoAdjustLayout        = cbkAutoAdjustLayout.Checked;
                    excel.IgnoreInternalResources = cbkIgnoreInternalResources.Checked;
                    excel.Cultures = cultures.SelectedCultures;

                    excel.Export(saveFileDialog.FileName);
                }
                catch
                {
                    throw;
                }
                finally
                {
                    this.btnExport.Enabled = true;
                    this.btnCancel.Enabled = true;
                }
            }

            this.Close();
        }