Exemplo n.º 1
0
        /// <summary>
        /// Asks for file name(s) and imports the file(s) into one or multiple worksheets. After the user chooses one or multiple files, one of the chosen files is used for analysis.
        /// The result of the structure analysis of this file is then presented to the user. The user may change some of the options and starts a re-analysis. Finally, the import options
        /// are confirmed by the user and the import process can start.
        /// </summary>
        /// <param name="dataTable">The data table to import to. Can be null if <paramref name="toMultipleWorksheets"/> is set to <c>true</c>.</param>
        /// <param name="toMultipleWorksheets">If true, multiple files are imported into multiple worksheets. New worksheets were then created automatically.</param>
        /// <param name="vertically">If <c>toMultipleWorksheets</c> is false, and this option is true, the data will be exported vertically (in the same columns) instead of horizontally.</param>
        public static void ShowImportAsciiDialogAndOptions(this DataTable dataTable, bool toMultipleWorksheets, bool vertically)
        {
            var options = new Altaxo.Gui.OpenFileOptions();

            options.AddFilter("*.csv;*.dat;*.txt", "Text files (*.csv;*.dat;*.txt)");
            options.AddFilter("*.*", "All files (*.*)");
            options.FilterIndex      = 0;
            options.RestoreDirectory = true;
            options.Multiselect      = true;

            if (Current.Gui.ShowOpenFileDialog(options) && options.FileNames.Length > 0)
            {
                var analysisOptions = dataTable.GetPropertyValue(AsciiDocumentAnalysisOptions.PropertyKeyAsciiDocumentAnalysisOptions, null);
                if (!ShowAsciiImportOptionsDialog(options.FileName, analysisOptions, out var importOptions))
                {
                    return;
                }

                if (toMultipleWorksheets)
                {
                    AsciiImporter.ImportFilesIntoSeparateNewTables(Main.ProjectFolder.RootFolder, options.FileNames, true, importOptions);
                }
                else
                {
                    if (vertically)
                    {
                        AsciiImporter.ImportFromMultipleAsciiFilesVertically(dataTable, options.FileNames, true, importOptions);
                    }
                    else
                    {
                        AsciiImporter.ImportFromMultipleAsciiFilesHorizontally(dataTable, options.FileNames, true, importOptions);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public static void ImportAsciiToSingleWorksheetHorizontally(this DataTable dataTable, string[] filenames, AsciiImportOptions importOptions)
 {
     if (null != importOptions)
     {
         AsciiImporter.ImportFromMultipleAsciiFilesHorizontally(dataTable, filenames, true, importOptions);
     }
     else
     {
         AsciiImporter.ImportFromMultipleAsciiFilesHorizontally(dataTable, filenames, true, true);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Asks for file name(s) and imports the file(s) into one or multiple worksheets.
        /// </summary>
        /// <param name="dataTable">The data table to import to. Can be null if <paramref name="toMultipleWorksheets"/> is set to <c>true</c>.</param>
        /// <param name="toMultipleWorksheets">If true, multiple files are imported into multiple worksheets. New worksheets were then created automatically.</param>
        /// <param name="vertically">If <c>toMultipleWorksheets</c> is false, and this option is true, the data will be exported vertically (in the same columns) instead of horizontally.</param>
        public static void ShowImportAsciiDialog(this DataTable dataTable, bool toMultipleWorksheets, bool vertically)
        {
            var options = new Altaxo.Gui.OpenFileOptions();

            options.AddFilter("*.csv;*.dat;*.txt", "Text files (*.csv;*.dat;*.txt)");
            options.AddFilter("*.*", "All files (*.*)");
            options.FilterIndex      = 0;
            options.RestoreDirectory = true;
            options.Multiselect      = true;

            if (Current.Gui.ShowOpenFileDialog(options) && options.FileNames.Length > 0)
            {
                if (toMultipleWorksheets)
                {
                    if (options.FileNames.Length == 1 && null != dataTable)
                    {
                        AsciiImporter.ImportFromAsciiFile(dataTable, options.FileName);
                    }
                    else
                    {
                        AsciiImporter.ImportFilesIntoSeparateNewTables(Main.ProjectFolder.RootFolder, options.FileNames, true, false);
                    }
                }
                else
                {
                    if (vertically)
                    {
                        AsciiImporter.ImportFromMultipleAsciiFilesVertically(dataTable, options.FileNames, true, false);
                    }
                    else
                    {
                        AsciiImporter.ImportFromMultipleAsciiFilesHorizontally(dataTable, options.FileNames, true, false);
                    }
                }
            }
        }