public DataTable Format(string text, IFormatOptions formatOptions, ITableOptions tableOptions) { if (string.IsNullOrWhiteSpace(text)) { return(new DataTable()); } ITableDetector detector = this.ConstructDetector(text, formatOptions); return(this.Process(detector, tableOptions ?? TableOptions.Default)); }
private DataTable Process(ITableDetector detector, ITableOptions tableOptions) { string[,] array = detector.Detect(); int length = array.GetLength(0); int length2 = array.GetLength(1); DataTable dataTable = new DataTable(); if (length > 0 && length2 > 0) { object[][] array2 = new object[length2][]; for (int i = tableOptions.UseRowHeader ? 1 : 0; i < length2; i++) { string[] array3 = new string[length]; for (int j = 0; j < length; j++) { array3[j] = array[j, i]; } Type dataType; array2[i] = this.AutoDetectType(array3, tableOptions, out dataType); DataColumn dataColumn = new DataColumn(tableOptions.UseColumnHeader ? array[0, i] : string.Empty, dataType); dataTable.Columns.Add(dataColumn); dataColumn.Caption = string.Empty; } for (int k = tableOptions.UseColumnHeader ? 1 : 0; k < length; k++) { DataRow dataRow = dataTable.NewRow(); dataTable.Rows.Add(dataRow); int num = tableOptions.UseRowHeader ? 1 : 0; int num2 = 0; while (num2 + num < length2) { dataRow[num2] = array2[num2 + num][k]; num2++; } } } return(dataTable); }