Home Forums Programming General Visual Studio C# project. Export DataTable to Excel formatting of column RE: Visual Studio C# project. Export DataTable to Excel formatting of column

  • I figured out part of the answer.

    In the Export function, I added the line range[2, 7].EntireColumn.NumberFormat="#.##%;. This now displays the calculated value as Percentage on export. I still have a minor issue where it addes the decimal point after a resulting value of 100%, so I still need to work on that one.


                for (var b = 0; b < dt.Columns.Count; b++)
                {
                    xlWorkSheet.Cells[1, b + 1] = dt.Columns.ColumnName;
                    range = xlWorkSheet.Cells[1, b + 1];
                    range.Interior.ColorIndex = 15;
                    range.Font.Bold = true;
                    //range = (Excel.Range)xlWorkSheet.Cells[1, 7];
                    range[2, 7].EntireColumn.NumberFormat = "#.##%";
                }

    Retired Navy Chief Petty Officer, Consulting Systems Engineer, C# Programmer, SQL Beginner