title: [C#]Export DatagridView in xls for openOffice Calc
body: <p>I have this function that export a datagridView in Excel sheet : </p>
  
  <pre><code> public void ExportGridToExcel(DataGridView TheGrid, string FileName)
      {
  
              using (System.IO.StreamWriter fs = new System.IO.StreamWriter(FileName, false))
              {
                  fs.WriteLine("&lt;?xml version=\"1.0\"?&gt;");
                  fs.WriteLine("&lt;?mso-application progid=\"Excel.Sheet\"?&gt;");
                  fs.WriteLine("&lt;ss:Workbook xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"&gt;");
                  fs.WriteLine("    &lt;ss:Styles&gt;");
                  fs.WriteLine("        &lt;ss:Style ss:ID=\"1\"&gt;");
                  fs.WriteLine("           &lt;ss:Font ss:Bold=\"1\"/&gt;");
                  fs.WriteLine("        &lt;/ss:Style&gt;");
                  fs.WriteLine("    &lt;/ss:Styles&gt;");
                  fs.WriteLine("    &lt;ss:Worksheet ss:Name=\"Sheet1\"&gt;");
                  fs.WriteLine("        &lt;ss:Table&gt;");
                  for (int x = 0; x &lt;= TheGrid.Columns.Count - 1; x++)
                  {
                      fs.WriteLine("            &lt;ss:Column ss:Width=\"{0}\"/&gt;", TheGrid.Columns[x].Width);
                  }
                  fs.WriteLine("            &lt;ss:Row ss:StyleID=\"1\"&gt;");
                  for (int i = 0; i &lt;= TheGrid.Columns.Count - 1; i++)
                  {
                      fs.WriteLine("                &lt;ss:Cell&gt;");
                      fs.WriteLine(string.Format("                   &lt;ss:Data ss:Type=\"String\"&gt;{0}&lt;/ss:Data&gt;", TheGrid.Columns[i].HeaderText));
                      fs.WriteLine("                &lt;/ss:Cell&gt;");
                  }
                  fs.WriteLine("            &lt;/ss:Row&gt;");
                  for (int intRow = 0; intRow &lt;= TheGrid.RowCount - 2; intRow++)
                  {
                      fs.WriteLine(string.Format("            &lt;ss:Row ss:Height =\"{0}\"&gt;", TheGrid.Rows[intRow].Height));
                      for (int intCol = 0; intCol &lt;= TheGrid.Columns.Count - 1; intCol++)
                      {
                          fs.WriteLine("                &lt;ss:Cell&gt;");
                          fs.WriteLine(string.Format("                   &lt;ss:Data ss:Type=\"String\"&gt;{0}&lt;/ss:Data&gt;", (TheGrid.Rows[intRow].Cells[intCol].Value != null) ? TheGrid.Rows[intRow].Cells[intCol].Value.ToString() : string.Empty));
                          fs.WriteLine("                &lt;/ss:Cell&gt;");
                      }
                      fs.WriteLine("            &lt;/ss:Row&gt;");
                  }
                  fs.WriteLine("        &lt;/ss:Table&gt;");
                  fs.WriteLine("    &lt;/ss:Worksheet&gt;");
                  fs.WriteLine("&lt;/ss:Workbook&gt;");
              }
  }
  </code></pre>
  
  <p>If i try to open the generated XLS with Microsoft Excel everything is ok, but if try to open with OpenOffice Calc, give me an import screen and i can't open the spredsheet.</p>
  
  <p>Why ?
  How can i do for export an Excel sheet compatibile with openoffice calc ?</p>