/// <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); } } } }
public static void ImportAscii(IWorksheetController ctrl, System.IO.Stream myStream) { AsciiImporter importer = new AsciiImporter(myStream); AsciiImportOptions recognizedOptions = importer.Analyze(30, new AsciiImportOptions()); importer.ImportAscii(recognizedOptions, ctrl.Doc); }
public static void ImportAsciiToSingleWorksheetVertically(this DataTable dataTable, string[] filenames, AsciiImportOptions importOptions) { if (null != importOptions) { AsciiImporter.ImportFromMultipleAsciiFilesVertically(dataTable, filenames, true, importOptions); } else { AsciiImporter.ImportFromMultipleAsciiFilesVertically(dataTable, filenames, true, true); } }
public static void ImportAsciiToMultipleWorksheets(string[] filenames, AsciiImportOptions importOptions) { if (null != importOptions) { AsciiImporter.ImportFilesIntoSeparateNewTables(Main.ProjectFolder.RootFolder, filenames, true, importOptions); } else { AsciiImporter.ImportFilesIntoSeparateNewTables(Main.ProjectFolder.RootFolder, filenames, true, true); } }
/// <summary> /// Gets a file stream of the first file for analysis purposes. Returns null without throwing an exception if the file is not available or could not be opened. /// </summary> /// <returns></returns> private System.IO.Stream GetFileStreamForAnalysis() { try { var str = AsciiImporter.GetAsciiInputFileStream(_doc.SourceFileName); return(str); } catch (Exception) { } return(null); }
/// <summary> /// Shows the ASCII analysis dialog. /// </summary> /// <param name="fileName">Name of the file to analyze.</param> /// <param name="importOptions">On return, contains the ASCII import options the user has confirmed.</param> /// <param name="analysisOptions">Options that specify how many lines are analyzed, and what number formats and date/time formats will be tested.</param> /// <returns><c>True</c> if the user confirms this dialog (clicks OK). False if the user cancels this dialog.</returns> public static bool ShowAsciiImportOptionsDialog(string fileName, AsciiDocumentAnalysisOptions analysisOptions, out AsciiImportOptions importOptions) { importOptions = new AsciiImportOptions(); using (FileStream str = AsciiImporter.GetAsciiInputFileStream(fileName)) { importOptions = AsciiDocumentAnalysis.Analyze(new AsciiImportOptions(), str, analysisOptions); object[] args = new object[] { importOptions, str }; var controller = (Altaxo.Gui.IMVCAController)Current.Gui.GetControllerAndControl(args, typeof(Altaxo.Gui.IMVCAController), Gui.UseDocument.Directly); if (!Current.Gui.ShowDialog(controller, "Choose Ascii import options")) { return(false); } importOptions = (AsciiImportOptions)controller.ModelObject; return(true); } }
/// <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); } } } }
public static void ImportAscii(this DataTable dataTable, System.IO.Stream myStream, string streamOriginHint) { AsciiImporter.ImportFromAsciiStream(dataTable, myStream, streamOriginHint); }
public static void ImportAsciiToSingleWorksheet(WorksheetController ctrl, string[] filenames) { Array.Sort(filenames); // Windows seems to store the filenames reverse to the clicking order or in arbitrary order AsciiImporter.ImportMultipleAscii(filenames, ctrl.Doc); }