c# - write data to csv file sheet 2 -


i want write data datatable csv file starting sheet 2 in c#. please. have following function create csv file.

public void createcsvfile(datatable dt, string strfilepath) {          // create csv file grid data exported.         streamwriter sw = new streamwriter(strfilepath, false);         // first write headers.         //datatable dt = m_dsproducts.tables[0];         int icolcount = dt.columns.count;         (int = 0; < icolcount; i++)         {             sw.write(dt.columns[i]);              if (i < icolcount - 1)             {                 sw.write(",");             }         }          sw.write(sw.newline);         // write rows.         foreach (datarow dr in dt.rows)         {             (int = 0; < icolcount; i++)             {                 if (!convert.isdbnull(dr[i]))                 {                     sw.write(dr[i].tostring());                 }                 if (i < icolcount - 1)                 {                     sw.write(",");                 }             }             sw.write(sw.newline);         }          sw.close();      } 

as strong suggestion: don't try invent own csv writer / reader. seems easy, there dragons in water, lots of dragons. escaping strings fun - how manage line

escaping thin takes lot of work.

so go ahead , use library like: http://kbcsv.codeplex.com/ it's free, fast , saves days of work.

as further questions: sheet 2 excel file?


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -