private void fromTableToText() { TextTableProcessor processor = new TextTableProcessor(editor.Text, textBox.Text); IRelation relation = new DefaultRelation(); String[] columns = new String[dataGrid.Columns.Count]; for (int i = 0; i < dataGrid.Columns.Count; i++) { columns[i] = dataGrid.Columns[i].HeaderText; } String[][] data = new String[dataGrid.Rows.Count][]; for (int i = 0; i < dataGrid.Rows.Count; i++) { String[] row = new String[columns.Length]; for (int j = 0; j < columns.Length; j++) { object cell_value = dataGrid.Rows[i].Cells[j].Value; row[j] = cell_value != null?cell_value.ToString() : ""; } data[i] = row; } relation.setData(data); relation.setColumns(columns); textBox.Text = processor.process(relation); tabControl.SelectedIndex = 0; }
public IRelation createRelationFromText(string text) { evaluateColumnNames(); String[] lines = text.Split('\n'); String[][] dataArray = new String[lines.Count()][]; PlainItemDescription[] idesc = itemDescriptions.ToArray(); for (int lineIndex = 0; lineIndex < lines.Count(); lineIndex++) { String textLine = lines[lineIndex]; String[] row = new String[columnNames.Count()]; for (int columnIndex = 0; columnIndex < idesc.Count(); columnIndex++) { int length = idesc[columnIndex].length(); if (textLine.Length >= idesc[columnIndex].from - 1 + length) { //dataArray[lineIndex, columnIndex] = // textLine.Substring(idesc[columnIndex].from - 1, length); int index = idesc[columnIndex].from - 1; row[columnIndex] = textLine.Substring(index, length).Trim(); } } dataArray[lineIndex] = row; } DefaultRelation defaultRelation = new DefaultRelation(); defaultRelation.setColumns(columnNames); defaultRelation.setData(dataArray); return(defaultRelation); }