Beispiel #1
0
        private void TreeContextMenu_OutputCSV_Click(object sender, EventArgs e)
        {
            if (CSVSaver.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    using (var sw = new StreamWriter(CSVSaver.FileName, false, Utility.Configuration.Config.Log.FileEncoding))
                    {
                        var root = JsonTreeView.SelectedNode;

                        sw.WriteLine(BuildCSVHeader(new StringBuilder(), "", ((dynamic)root.Tag)[0]).ToString());

                        foreach (dynamic elem in (dynamic)root.Tag)
                        {
                            sw.WriteLine(BuildCSVContent(new StringBuilder(), elem).ToString());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Utility.ErrorReporter.SendErrorReport(ex, "JSON: CSV 出力に失敗しました。");
                    MessageBox.Show("CSV 出力に失敗しました。\r\n" + ex.Message, "出力エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        //saves instances to csv format
        public static void SaveCSV(Instances insts, string filename)
        {
            if (insts == null)
            {
                Console.WriteLine("instances empty null");
                return;
            }
            var saver = new CSVSaver();

            saver.setInstances(insts);
            saver.setFile(new java.io.File(filename + ".csv"));
            saver.writeBatch();
        }
Beispiel #3
0
        /// <summary>
        /// Guardamos los datos como CSV
        /// </summary>
        /// <returns></returns>
        public static bool GuardarComoCSV(Instances datos, string directorio)
        {
            // TODO: Cambiar esto de workspace??? Probar si funciona

            // objeto para guardar
            CSVSaver guardar = new CSVSaver();

            // guardamos las instancias en el objeto para guardar
            guardar.setInstances(datos);

            // Creamos el directorio donde se quiere escribir
            guardar.setFile(new File(directorio));

            // escribir
            guardar.writeBatch();

            throw new Exception();
        }
Beispiel #4
0
        public cFeedBackMessage Run()
        {
            if (this.Input == null)
            {
                FeedBackMessage.IsSucceed = false;
                FeedBackMessage.Message = "No input data defined.";
                return FeedBackMessage;
            }

            string PathForImages;

            if (IsDisplayUIForFilePath)
            {
                SaveFileDialog CurrSaveFileDialog = new SaveFileDialog();
                CurrSaveFileDialog.Filter = "CSV file (*.csv)|*.csv| XLS file (*.xls)|*.xls| ARFF file (*.arff)|*.arff";
                System.Windows.Forms.DialogResult Res = CurrSaveFileDialog.ShowDialog();
                if (Res != System.Windows.Forms.DialogResult.OK)
                {
                    FeedBackMessage.IsSucceed = false;
                    FeedBackMessage.Message = "Incorrect File Name.";
                    return FeedBackMessage;
                }
                FilePath = CurrSaveFileDialog.FileName;
                if (CurrSaveFileDialog.FilterIndex == 1)
                    this.FileType = eFileType.CSV;
                else if (CurrSaveFileDialog.FilterIndex == 2)
                    this.FileType = eFileType.XLS;
                else
                    this.FileType = eFileType.ARFF;
            }
            else if (IsIncludeImageAsComment)
            {
                this.FileType = eFileType.XLS;

                var dlg1 = new Ionic.Utils.FolderBrowserDialogEx();
                dlg1.Description = "Create a folder that will contain your file and the images.";
                dlg1.ShowNewFolderButton = true;
                dlg1.ShowEditBox = true;
                //dlg1.NewStyle = false;
                //  dlg1.SelectedPath = txtExtractDirectory.Text;
                dlg1.ShowFullPathInEditBox = true;
                dlg1.RootFolder = System.Environment.SpecialFolder.Desktop;

                // Show the FolderBrowserDialog.
                DialogResult result = dlg1.ShowDialog();
                if (result != DialogResult.OK)
                {
                    FeedBackMessage.IsSucceed = false;
                    FeedBackMessage.Message = "Incorrect File Name.";
                    return FeedBackMessage;
                }

                PathForImages = dlg1.SelectedPath;
                if (Directory.Exists(PathForImages) == false)
                {
                    FeedBackMessage.IsSucceed = false;
                    FeedBackMessage.Message = "Incorrect File Name.";
                    return FeedBackMessage;
                }

            }
            else
            {
                if (this.FilePath == "")
                {
                    FeedBackMessage.IsSucceed = false;
                    FeedBackMessage.Message = "Incorrect File Name.";
                    return FeedBackMessage;
                }

            }

            if (this.FileType == eFileType.CSV)
            {
                if (IsTagToBeSaved == false)
                {
                    using (StreamWriter myFile = new StreamWriter(FilePath, this.IsAppend, Encoding.Default))
                    {
                        // Export titles:
                        string sHeaders = "";

                        if (this.Input.ListRowNames != null)
                            sHeaders += this.Separator;

                        for (int j = 0; j < this.Input.Count; j++) { sHeaders = sHeaders.ToString() + this.Input[j].Name + Separator; }
                        sHeaders = sHeaders.Remove(sHeaders.Length - 1);

                        myFile.WriteLine(sHeaders);

                        // Export data.
                        for (int i = 0; i < this.Input[0].Count; i++)
                        {
                            string stLine = "";

                            if ((this.Input.ListRowNames != null) && (this.Input.ListRowNames.Count > i))
                                stLine += this.Input.ListRowNames[i] + this.Separator;

                            for (int j = 0; j < this.Input.Count; j++) { stLine = stLine.ToString() + this.Input[j][i] + Separator; }

                            stLine = stLine.Remove(stLine.Length - 1);
                            myFile.WriteLine(stLine);
                        }
                        myFile.Close();
                    }
                }

            }
            else if (this.FileType == eFileType.XLS)
            {
              //  ExportToExcel(this.Input, FilePath, PathForImages);

                //Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
                //Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
                //Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
                //object misValue = System.Reflection.Missing.Value;

                //// xlApp = new Excel.ApplicationClass();
                //xlWorkBook = xlApp.Workbooks.Add(misValue);
                //xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                //// Microsoft.Office.Interop.Excel.Range cell = GetMyPictureCELL(taperSheet);

                ////xlWorkSheet.Cells[j + 2, 1].AddComment(" ");
                ////xlWorkSheet.Cells[j + 2, 1].Comment.Shape.Fill.UserPicture(imagenames[j]);

                //xlWorkBook.SaveAs(FilePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue,
                //               Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                //xlWorkBook.Close(true, misValue, misValue);
                //xlApp.Quit();
                //releaseObject(xlWorkSheet);
                //releaseObject(xlWorkBook);
                //releaseObject(xlApp);

            }
            else if (this.FileType == eFileType.ARFF)
            {
                Instances insts = this.Input.CreateWekaInstances();
                ArffSaver saver = new ArffSaver();
                CSVSaver savercsv = new CSVSaver();
                saver.setInstances(insts);
                saver.setFile(new java.io.File(FilePath));
                saver.writeBatch();

                //    System.Diagnostics.Process proc1 = new System.Diagnostics.Process();
                //   proc1.StartInfo.FileName = "C:\\Program Files\\Weka-3-6\\RunWeka.bat explorer";
                //  proc1.StartInfo.Arguments = FilePath;
                //    proc1.Start();

            }

            if (this.IsRunEXCEL)
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = "excel";
                proc.StartInfo.Arguments = FilePath;
                proc.Start();

            }

            return FeedBackMessage;
        }