I want to generate Excel report identical that we use before (with old version of Excel). The only problem is that all cells in old style reports were presented as strings with apostrophe character:
I created basically the same report with the next code:
oleDbConnection = new System.Data.OleDb.OleDbConnection(
"provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
fileFullPath +
";Extended Properties='Excel 12.0 Xml;HDR=YES' ");
oleDbConnection.Open();
oleDbCommand.Connection = oleDbConnection;
string commandHeader = String.Join("] char(255), [", headers);
commandHeader = "[" + commandHeader + "]";
commandHeader = "CREATE TABLE data (" + commandHeader + " char(255))";
oleDbCommand.CommandText = commandHeader;
oleDbCommand.ExecuteNonQuery();
foreach (var item in exportList)
{
string line = String.Join("\",\"\'", new string[] {item.Foreman_ID, item.DateApp.Date.ToString("yyyyMMdd"), item.TimeApp,
item.Employee_ID, item.ProductionOrder, item.OperationNumber,
item.ConfirmationNumber, item.date.Date.ToString("yyyyMMdd"), item.TotalHours.ToString("0.000").Replace(",", "."), item.SalaryType, item.TimeType,
item.ExtraPrice.ToString("0.00").Replace(",", "."), item.ExtraHours, item.ActualPC, item.PcPriceSplit, item.CostCenter});
line = line.Replace(" ", String.Empty);
line = "\"\'" + line + "\"";
oleDbCommand.CommandText = "Insert into data values(" + line + ")";
oleDbCommand.ExecuteNonQuery();
}
oleDbConnection.Close();
This code generate the same rows where every cell begins with apostrophe character. But if I open generated Excel, then I still see my apostrophe:
If I press on the cell and then will press enter, then this apostrophe will dissapear.