How to format cells in excel sheet programmatically?

前端 未结 1 1199
南笙
南笙 2020-12-03 14:36

We have an asp.net c# program that reads a sheet from an Excel file and writes it out in a new sheet (also adding one column if data come from a Sql Server table).

I

相关标签:
1条回答
  • 2020-12-03 14:48

    Just set the appropriate property on your cell (Range) objects.

    Set NumberFormat to control the cell number formatting, i.e.:

    newSheet.Cells[i, j].NumberFormat = "m/d/yyyy"
    

    Set HorizontalAlignment to control the alignment, i.e.:

    newSheet.Cells[i, j].HorizontalAlignment = ExcelAlignment.xlLeft; //or Excel.XlHAlign.xlHAlignLeft
    
    0 讨论(0)
提交回复
热议问题