We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Display Comma elements in DataTable while exporting data into Excel with custom number formatting using Aspose.Cells for .NET in C#

Hi ,

I am trying to generate excel using Aspose… Some fields in DataTable have comma elements… It is not coming in generated Excel… Please help

Hi Punnoose,

Thank you for contacting Aspose support.

I believe you are referring to the thousand seperator (,) for number values in your DataTable. You can control this behaviour while using the ImportTableOptions.NumberFormats property, that will accept an array of strings as format for the columns containing number values (in DataTable they could be string). The following code snippet demonstrates the usage as discussed above. You may review it to adjust your code accordingly. In case the problem persist, please create a sample application demonstrating the problem. Please note, you have to create the DataTable dynamically so that we do not require the database connectivity while executing your sample project on our side.


DataTable table = new DataTable();
table.Columns.Add(“Id”, typeof(int));
table.Columns.Add(“number 1”, typeof(string));
table.Columns.Add(“number 2”, typeof(string));

table.Rows.Add(1, “1,200.00”, “2,222.00”);
table.Rows.Add(3, “3,456.9”, “2.9”);

var book = new Workbook();
var sheet = book.Worksheets[0];
var cells = sheet.Cells;
cells.ImportData(table, 0, 0, new ImportTableOptions() { IsFieldNameShown = true, NumberFormats = new string[] {null, “#,##0.00”, “#,##0.00” }, ConvertNumericData = true });
book.Save(dir + “output.xlsx”);