void show_xls_out() { int col = 0; MSOfficeTools.exportExcel(xls_out.FileName, table, "Registry", x => { if (x == Value_Dots) { x = Value_Question; } else if (x == Value_Batsu) { x = Value_Question; } else if (x == MachineInfo.NOTREACHABLE) { x = Value_Question; } else { x = x.Replace(Value_Dots, ""); x = x.Replace('\n', '¤'); } return(x); }, x => "C" + (col++) + ":\n" + x.Replace('\n', '¤')); }
private void xls_out_FileOk(object sender, CancelEventArgs e) { MSOfficeTools.exportExcel(xls_out.FileName, table, GetType().Name, x => { if (x == Value_Dots) { return(Value_Question); } else if (x == Value_Batsu) { return(Value_Question); } else if (x == MachineInfo.NOTREACHABLE) { return(Value_Question); } else { return(x.Replace(Value_Dots, "")); } }); }
private void xls_in_FileOk(object sender, CancelEventArgs e) { System.Data.DataTable t = MSOfficeTools.loadExcelFile(xls_in.FileName, false); if (t != null) { string INVALID = null; StringBuilder contents = new StringBuilder(); { int max = 10; foreach (DataRow row in t.Rows) { if (max-- == 0) { break; } else { foreach (object o in row.ItemArray) { contents.Append(o + " "); } contents.AppendLine(); } } } bool first = true; foreach (DataRow row in t.Rows) { if (row.ItemArray.Length > 0) { if (first) { first = false; DataRow header = row; int colCount = header.ItemArray.Length; if (colCount != table.Columns.Count) { INVALID = "The Excel workseet has " + (colCount > table.Columns.Count ? "more" : "less") + " columns than the template.\n" + colCount + (colCount > table.Columns.Count ? " > " : " < ") + table.Columns.Count; break; } else { int j = 0; foreach (object o in header.ItemArray) { if (("" + table.Columns[j].HeaderText.Replace('\n', ' ')) != ("" + o)) { INVALID = "The Excel column C" + j + " has a different name rather than in the template.\n\n\t'" + o + "' not equal to '" + table.Columns[j].HeaderText.Replace('\n', ' ') + "'\n\n\t" + contents.Replace(' ', '\u00A0'); break; } else { j++; } } if (INVALID != null) { break; } } } else { try { int i = table.Rows.Add(row.ItemArray); table.Rows[i].HeaderCell.Value = "" + (i + 1); } catch (Exception ee) { INVALID = "While adding row " + (table.Rows.Count + 1) + ": " + ee.Message; } } } } table.Sort(table.Columns[0], ListSortDirection.Ascending); bool VALID = INVALID == null; SaveButton.Enabled = Go.Enabled = ClearButton.Enabled = VALID; Hint2.Visible = Hint.Visible = !VALID; if (INVALID != null) { MessageBox.Show(this, "Invalid Excel File:\n\n\t" + xls_in.FileName + "\n\n\nReason:\n\n\t" + INVALID); } } }
private void xls_in_FileOk(object sender, CancelEventArgs e) { System.Data.DataTable t = MSOfficeTools.loadExcelFile(xls_in.FileName, false); if (t != null) { string INVALID = null; StringBuilder contents = new StringBuilder(); { int max = 10; foreach (DataRow row in t.Rows) { while (max-- > 0) { foreach (object o in row.ItemArray) { contents.Append(o + " "); } contents.AppendLine(); } } } int i = 0; foreach (DataRow row in t.Rows) { if (i++ == 0) { DataRow header = row; int colCount = header.ItemArray.Length; if (colCount != table.Columns.Count) { INVALID = "The Excel workseet has " + (colCount > table.Columns.Count ? "more" : "less") + " columns than the template.\n" + colCount + (colCount > table.Columns.Count ? " > " : " < ") + table.Columns.Count; break; } else { int j = 0; foreach (object o in header.ItemArray) { if (("" + table.Columns[j].HeaderText) != ("" + o)) { INVALID = "The Excel column C" + j + " has a different name rather than in the template.\n\n\t'" + o + "' not equal to '" + table.Columns[j].HeaderText + "'\n\n\t" + contents; break; } else { j++; } } if (INVALID != null) { break; } } } else { try { table.Rows.Add(row.ItemArray); table.Rows[i].HeaderCell.Value = "" + (i + 1); } catch (Exception ee) { INVALID = "While adding row " + i + ": " + ee.Message; } } } Clear.Visible = INVALID == null; Go.Visible = INVALID == null; Save.Visible = INVALID == null; if (INVALID != null) { MessageBox.Show(this, "Invalid Excel File:\n\n\t" + xls_in.FileName + "\n\n\nReason:\n\n\t" + INVALID); } } }
private void xls_in_FileOk(object sender, CancelEventArgs e) { System.Data.DataTable t = MSOfficeTools.loadExcelFile(xls_in.FileName, false); if (t != null) { string INVALID = null; StringBuilder contents = new StringBuilder(); { int maxrow = 5; foreach (DataRow row in t.Rows) { int maxcol = 5; foreach (object o in row.ItemArray) { contents.Append(o + " "); if (maxcol-- < 0) { break; } } contents.AppendLine(); if (maxrow-- < 0) { break; } } } int i = 0; foreach (DataRow row in t.Rows) { if (i == 0) { DataRow header = row; int colCount = header.ItemArray.Length; if (colCount != table.Columns.Count) { INVALID = "The Excel workseet has " + (colCount > table.Columns.Count ? "more" : "less") + " columns than the template.\n" + colCount + (colCount > table.Columns.Count ? " > " : " < ") + table.Columns.Count + "'\n\nSheet starts with:\n" + contents; break; } else { int j = 0; foreach (object o in header.ItemArray) { string curcol = "" + table.Columns[j].HeaderText; string col = Regex.Replace(("" + o).Replace("¤", "\n"), @"^C\d+:\n", ""); if (curcol != col) { INVALID = "The Excel column C" + j + " has a different name rather than in the template.\n\n\t'" + ("" + o).Replace("¤", "\n").Replace("\r", "\\r").Replace("\n", "\\n") + "' not equal to '" + table.Columns[j].HeaderText.Replace("\r", "\\r").Replace("\n", "\\n") + "'\n\nSheet starts with:\n" + contents; break; } else { j++; } } if (INVALID != null) { break; } } } else { int j = 0; try { table.Rows.Add(); for (j = 0; j < table.Rows[i - 1].Cells.Count; j++) { if (j < row.ItemArray.Length) { table.Rows[i - 1].Cells[j].Value = row.ItemArray[j]; } } //table.Rows.Add(row.ItemArray); table.Rows[i - 1].HeaderCell.Value = "" + i; } catch (Exception ee) { INVALID = "While adding row " + i + ":\n" + ee.Message + "\n\n" //+ " i=" + i + " table.Rows.Count=" + table.Rows.Count //+ " j=" + j + " table.Rows[i].Cells.Count=" + table.Rows[i].Cells.Count //+ " row.ItemArray.Length=" + row.ItemArray.Length ; } } i++; } Clear.Visible = Go.Visible = Save.Visible = INVALID == null; if (Go.Visible) { Hint0.Visible = HintTarget.Visible = HintOpen.Visible = false; } if (INVALID != null) { MessageBox.Show(this, "Invalid Excel File:\n\n\t" + xls_in.FileName + "\n\n\nReason:\n\n\t" + INVALID); } } }