Into my project when i m exporting Contacts into csv file automatically format mobile numbers starts with 91 into scientific.
e.g mobile no into exporting data
919433454320
mobile no into csv file when scientific format
9.194E+11
after format cell as number with 0 decimal places
919430000000
For exporting contacts into my project i m using Microsoft.Office.Interop.Excel.Application
Workbook here is my code
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
app.Visible = false;
Workbook wb = app.Workbooks.Add();
Worksheet ws = (Worksheet)wb.Worksheets.get_Item(1);
object[,] rawData = new object[DataTable.Rows.Count + 1, DataTable.Columns.Count];
for (int col = 0; col < DataTable.Columns.Count; col++)
{
rawData[0, col] = DataTable.Columns[col].ColumnName;
}
for (int col = 0; col < DataTable.Columns.Count; col++)
{
for (int row = 0; row < DataTable.Rows.Count; row++)
{
rawData[row + 1, col] = DataTable.Rows[row].ItemArray[col];
}
}
string[] callchar = new string[] {"range of my excel sheet (e.g from a to Bz"};
string excelRange = callchar[0] + "1:" + callchar[DataTable.Columns.Count - 1] + (DataTable.Rows.Count + 1).ToString();
Range r = ws.Cells.EntireColumn.NumberFormat;
ws.get_Range(excelRange, Type.Missing).Value2 = rawData;
wb.SaveAs(Filename: FilePath, FileFormat: XlFileFormat.xlCSVWindows, ReadOnlyRecommended: false);
wb.Close();
app.Quit();
You can use late binding to export data:
Excel should properly process types, so if you supply
obj
as astring
- it will not try to make a number (scientific?) from it.