asp.net mvc 4 - Using C# remove unnecessary “TABLE_NAME” from Excel worksheets -


can tell me, going upload excel file, file has unnecessary table "_xlnm#print_titles" need remove or delete field. method. not work remove or delete.

static string[] getexcelsheetnames(string connectionstring) {     oledbconnection con = null;     datatable dt = null;      con = new oledbconnection(connectionstring);     con.open();      dt = con.getoledbschematable(oledbschemaguid.tables, null);                 if ((dt == null) )     {         return null;     }      string[] excelsheetnames = new string[dt.rows.count];      int = 0;      foreach (datarow row in dt.rows)     {         excelsheetnames[i] = row["table_name"].tostring();          if ((excelsheetnames[i].contains("_xlnm#print_titles") || (excelsheetnames[i].contains("print_titles"))))         {             if (true)             {                 row.table.rows.remove(row);                 dt.acceptchanges();             }         }          i++;     }      return excelsheetnames; } 

instead of removing items in foreach loop, we'll find them , add them list, we'll go through list , remove them data table.

static string[] getexcelsheetnames(string connectionstring)     {         oledbconnection con = null;         datatable dt = null;          con = new oledbconnection(connectionstring);         con.open();          dt = con.getoledbschematable(oledbschemaguid.tables, null);          if ((dt == null))         {             return null;         }          string[] excelsheetnames = new string[dt.rows.count];          var rowstoremove = new list<datarow>();         (int = 0; < dt.rows.count; i++)         {             var row = dt.rows[i];             excelsheetnames[i] = row["table_name"].tostring();              if ((excelsheetnames[i].contains("_xlnm#print_titles") || (excelsheetnames[i].contains("print_titles"))))             {                    rowstoremove.add(dt.rows[i]);             }              i++;         }          foreach (var datarow in rowstoremove)         {             dt.rows.remove(datarow);         }          return excelsheetnames;     } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -