/// <summary> /// For given selected columns and selected rows, the procedure removes all nonnumeric cells. Furthermore, if either selectedColumns or selectedRows /// is empty, the collection is filled by the really used rows/columns. /// </summary> /// <param name="srctable">The source table.</param> /// <param name="selectedRows">On entry, contains the selectedRows (or empty if now rows selected). On output, is the row collection.</param> /// <param name="selectedColumns">On entry, conains the selected columns (or emtpy if only rows selected). On output, contains all numeric columns.</param> public static void RemoveNonNumericCells(Altaxo.Data.DataTable srctable, Altaxo.Collections.AscendingIntegerCollection selectedRows, Altaxo.Collections.AscendingIntegerCollection selectedColumns) { // first the columns if (0 != selectedColumns.Count) { for (int i = 0; i < selectedColumns.Count; i++) { int idx = selectedColumns[i]; if (!(srctable[idx] is Altaxo.Data.INumericColumn)) { selectedColumns.Remove(idx); } } } else // if no columns where selected, select all that are numeric { int end = srctable.DataColumnCount; for (int i = 0; i < end; i++) { if (srctable[i] is Altaxo.Data.INumericColumn) selectedColumns.Add(i); } } // if now rows selected, then test the max row count of the selected columns // and add it // check the number of rows if (0 == selectedRows.Count) { int numrows = 0; int end = selectedColumns.Count; for (int i = 0; i < end; i++) { int idx = selectedColumns[i]; numrows = Math.Max(numrows, srctable[idx].Count); } selectedRows.Add(ContiguousIntegerRange.FromStartAndCount(0, numrows)); } }
/// <summary> /// This function searches for patterns like aaa=bbb in the provided string. If it finds such a item, it creates a column named aaa /// and stores the value bbb at the same position in it as in the text column. /// </summary> /// <param name="strg">The string where to search for the patterns described above.</param> /// <param name="store">The column collection where to store the newly created columns of properties.</param> /// <param name="index">The index into the column where to store the property value.</param> public static void ExtractPropertiesFromString(string strg, Altaxo.Data.DataColumnCollection store, int index) { string pat; pat = @"(\S+)=(\S+)"; Regex r = new Regex(pat, RegexOptions.Compiled | RegexOptions.IgnoreCase); for ( Match m = r.Match(strg); m.Success; m = m.NextMatch()) { string propname = m.Groups[1].ToString(); string propvalue = m.Groups[2].ToString(); // System.Diagnostics.Trace.WriteLine("Found the pair " + propname + " : " + propvalue); if(!store.ContainsColumn(propname)) { Altaxo.Data.DataColumn col; if(Altaxo.Serialization.DateTimeParsing.IsDateTime(propvalue)) col = new Altaxo.Data.DateTimeColumn(); else if(Altaxo.Serialization.NumberConversion.IsNumeric(propvalue)) col = new Altaxo.Data.DoubleColumn(); else col = new Altaxo.Data.TextColumn(); store.Add(col,propname); // add the column to the collection } // now the column is present we can store the value in it. store[propname][index] = new Altaxo.Data.AltaxoVariant(propvalue); } }