Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel file created with OleDbConnection uses invalid CultureInfo
    text
    copied!<p>I'm using an OleDbConnection to create an Excel file:</p> <pre><code> String bewegungenDateiname = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), ".xls"); string strConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.IO.Path.GetDirectoryName(bewegungenDateiname) + @"\" + System.IO.Path.GetFileName(bewegungenDateiname) + @";Extended Properties='Excel 8.0;HDR=YES'"; using (System.Data.OleDb.OleDbConnection objConn = new System.Data.OleDb.OleDbConnection(strConnectionString)) using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("", objConn)) { objConn.Open(); cmd.CommandText = "CREATE TABLE [Test] ([MyDecimal] DECIMAL NULL)"; cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); Decimal value = 12.34m; cmd.Parameters.AddWithValue("@P01", value); cmd.CommandText = "INSERT INTO [Test$] ([MyDecimal]) VALUES (@P01)"; cmd.ExecuteNonQuery(); } System.Diagnostics.Process.Start(bewegungenDateiname); </code></pre> <p>Now when Excel 2013 opens the Excel file it will Show:</p> <pre><code>MyDecimal 1234 </code></pre> <p>So in my case Excel is losing the dot. Now I'm running a german Version of Windows/Office and if I use the following line to add the Parameter it will work:</p> <pre><code> cmd.Parameters.AddWithValue("@P01", value.ToString()); </code></pre> <p>German localization of numbers uses a colon instead of the dot to separate the fractions from the number value (meaning 12,34 instead of 12.34). So it seems the OleDbConnection uses the wrong culture variant to write the Excel file?</p> <p>I fear my Version might break with a different Version of Excel or a different locale - is there a way to fix this and get decimal values to Excel without such risks? I would use some other way to create Excel files, if it is without this flaw.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload