在excel中如何将单元格字体设置为BOLD [英] in excel how to set the cell font to be in BOLD
本文介绍了在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 = HorizontalAlignment.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 ;
解决方案
尝试chartRange.Font.Bold = true;
而不是chartRange.Cells.Font.Bold = true;
。
xlWorkSheet.get_Range(A1, D1)。Font.Bold = true;
请尝试上面的代码。
这里我展示了要设置的所有代码excel字体:
// 设置名称
sheet.Range [ A3:E3]。Style.Font.FontName = Comic Sans MS;
// 设置大小
sheet.Range [ A2:E2]。Style.Font.Size = 50 ;
// 将excel单元格数据设置为粗体
sheet.Range [< span class =code-string> A3:E3]。Style.Font.IsBold = 真跨度>;
// 将excel单元格数据设置为下划线
sheet.Range [< span class =code-string> A3:E3]。Style.Font.Underline = FontUnderlineType。单跨度>;
// 设置excel单元格数据颜色
sheet.Range [ A4:E14]。Style.Font.IsItalic = 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;
解决方案
TrychartRange.Font.Bold = true;
instead ofchartRange.Cells.Font.Bold = true;
.
xlWorkSheet.get_Range("A1", "D1").Font.Bold = true;
Please try the above code.
Here I show you all code to set excel font:
//set name sheet.Range["A3:E3"].Style.Font.FontName = "Comic Sans MS"; //set size sheet.Range["A2:E2"].Style.Font.Size = 50; //set excel cell data to be bold sheet.Range["A3:E3"].Style.Font.IsBold = true; //set excel cell data to be underline sheet.Range["A3:E3"].Style.Font.Underline = FontUnderlineType.Single; //set excel cell data color sheet.Range["A4:E14"].Style.Font.IsItalic = true;
这篇关于在excel中如何将单元格字体设置为BOLD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文