L'export de contacts dans le file csv forme automatiquement les numéros mobiles en scientifiques

Dans mon projet lors de l'export de contacts dans le file csv, le formatting automatique des numéros mobiles commence par 91 en science.

p.ex. mobile no dans l'export de données

919433454320

mobile no dans le file csv lorsque le format scientifique

9.194E + 11

après le format de cellule comme numéro avec 0 décimales

919430000000

Pour exporter des contacts dans mon projet, j'utilise Microsoft.Office.Interop.Excel.Application

Le cahier d'exercices est mon 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]; } } ssortingng[] callchar = new ssortingng[] {"range of my excel sheet (eg from a to Bz"}; ssortingng excelRange = callchar[0] + "1:" + callchar[DataTable.Columns.Count - 1] + (DataTable.Rows.Count + 1).ToSsortingng(); 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(); 

Vous pouvez utiliser une binding tardive pour exporter des données:

  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); // essayez d'ouvrir excel  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); Type typeExcelApplication = Type.GetTypeFromProgID ("Excel.Application");  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); si (typeExcelApplication == null)  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); lancer une nouvelle exception ("Excel n'est pas installé (Excel.Application n'est pas trouvé)");  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); object objExcelApplication = Activator.CreateInstance (typeExcelApplication);  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); object objWorkBooks = objExcelApplication.GetType (). InvokeMember ("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null);  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); object objWorkBook = objWorkBooks.GetType (). InvokeMember ("Ajouter", BindingFlags.InvokeMethod, null, objWorkBooks, null);  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); object objWorkSheet = objWorkBook.GetType (). InvokeMember ("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null);  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); // remplit datatables (placez l'object obj dans la cellule [1,1])  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); objWorkSheet.GetType (). InvokeMember ("Cells", BindingFlags.SetProperty, null, objWorkSheet, nouvel object [] {1, 1, obj});  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); // afficher excel  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); typeExcelApplication.InvokeMember ("Visible", BindingFlags.SetProperty, null, objExcelApplication, nouvel object [] {true});  // try to open excel Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Type typeExcelApplication = Type.GetTypeFromProgID("Excel.Application"); if (typeExcelApplication == null) throw new Exception("Excel is not installed (Excel.Application is not found)"); object objExcelApplication = Activator.CreateInstance(typeExcelApplication); object objWorkBooks = objExcelApplication.GetType().InvokeMember("Workbooks", BindingFlags.GetProperty, null, objExcelApplication, null); object objWorkBook = objWorkBooks.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, null, objWorkBooks, null); object objWorkSheet = objWorkBook.GetType().InvokeMember("ActiveSheet", BindingFlags.GetProperty, null, objWorkBook, null); // fill data (put object obj into cell [1,1]) objWorkSheet.GetType().InvokeMember("Cells", BindingFlags.SetProperty, null, objWorkSheet, new object[] { 1, 1, obj}); // display excel typeExcelApplication.InvokeMember("Visible", BindingFlags.SetProperty, null, objExcelApplication, new object[] { true }); Marshal.ReleaseComObject(objExcelApplication); 

Excel devrait traiter correctement les types, donc si vous fournissez obj tant que ssortingng – il ne tentera pas de créer un nombre (scientifique?).