本文介绍了在excel中如何将单元格字体设置为BOLD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 在excel中,如何以编程方式将单元格字体设置为粗体? 我的代码到目前为止: dr = GFun.ReadSql(SQL); xlRow = 3 ; while (dr.Read()) { // ColName.Name = dr [0] .ToString()。Trim(); xlWorkSheet.Cells [xlRow, 1 ] = dr [ 0 ]。ToString()。Trim(); chartRange = xlWorkSheet.get_Range( + xlRow, E + xlRow); chartRange.MergeCells = true ; chartRange.Cells.Font.Bold = true ; chartRange.Cells.Font.FontStyle = Horizo​​ntalAlignment.Center; xlRow = xlRow + 1 ; xlWorkSheet.Cells [xlRow, 1 ] = 日期; xlWorkSheet.Cells [xlRow, 2 ] = 第1节; xlWorkSheet.Cells [xlRow, 3 ] = 第2节; xlWorkSheet.Cells [xlRow, 4 ] = 第3节; xlWorkSheet.Cells [xlRow, 5 ] = 第4节; xlRow = xlRow + 1 ; } 我在下面写了一行,但在excel中它不是粗体。我怎样才能做到这一点?从下面的代码中,出现了什么错误?请帮帮我。 chartRange.Cells.Font.Bold = true ; 解决方案 In excel, how do I set the cell font to be bold programatically?My code so far follows:dr = GFun.ReadSql(sql);xlRow = 3;while (dr.Read()){ //ColName.Name = dr[0].ToString().Trim(); xlWorkSheet.Cells[xlRow,1] = dr[0].ToString().Trim(); chartRange = xlWorkSheet.get_Range("A" + xlRow, "E" + xlRow); chartRange.MergeCells = true; chartRange.Cells.Font.Bold = true; chartRange.Cells.Font.FontStyle = HorizontalAlignment.Center; xlRow = xlRow + 1; xlWorkSheet.Cells[xlRow, 1] = "Date"; xlWorkSheet.Cells[xlRow, 2] = "Session 1"; xlWorkSheet.Cells[xlRow, 3] = "Session 2"; xlWorkSheet.Cells[xlRow, 4] = "Session 3"; xlWorkSheet.Cells[xlRow, 5] = "Session 4"; xlRow = xlRow + 1;}I wrote the line below but in excel it is not bold. How can I do this? From my code below, what is the mistake? Please help me.chartRange.Cells.Font.Bold = true; 解决方案 这篇关于在excel中如何将单元格字体设置为BOLD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-17 06:02