title: streamwriter : csv file
body: <p>I use <code>StreamWriter</code> to write data to a csv file. When I open the csv file using Excel, everything is fine except that some of the cells have the hash symbol instead of the data written to the cell. This data, however, becomes visible on increasing the cell size. Is there any way to overcome this problem of the hash(<code>#</code>) symbols without having to manually increase cell sizes.</p>
  
  <pre><code>int cols;
  //open file 
  //StreamWriter wr = new StreamWriter(@"O:\C_2013_MRO_Software Database\Manpowerdata.csv");
  StreamWriter wr = new StreamWriter(@"C:\Manpowerdata.csv");
  
  //determine the number of columns and write columns to file 
  var dgvStock = dataGridView3;
  cols = dgvStock.Columns.Count;
  for (int i = 0; i &lt; cols - 1; i++)
  {
      wr.Write(dgvStock.Columns[i].Name.ToString().ToUpper() + ",");
  }
  wr.WriteLine();
  
  //write rows to excel file
  for (int i = 0; i &lt; (dgvStock.Rows.Count - 1); i++)
  {
      for (int j = 0; j &lt; cols; j++)
      {
          if (dgvStock.Rows[i].Cells[j].Value != null)
          {
              wr.Write(dgvStock.Rows[i].Cells[j].Value + ",");
          }
          else
          {
              wr.Write(",");
          }
      }
      wr.WriteLine();
  }
  
  //close file
  wr.Close();
  </code></pre>