如何使用C#在Excel单元格中设置字体颜色 [英] How to Set font color in Excel Cell Using C#
本文介绍了如何使用C#在Excel单元格中设置字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hello All,
我使用工作表将数据添加到Excel工作表。细胞[Row,Col] =数据;
工作表相应地定义了。
现在我需要给这个单元格一个特定的格式,行号为Row,列号为Col。我尝试使用get_range方法并设置颜色或字体大小,但它不起作用。有什么方法可以做到这一点。
解决方案
创建一个命名范围:
Microsoft.Office.Tools.Excel.NamedRange Range1 = this.Controls.AddNamedRange(this.Range [A1:B20]NamedRange1);
设置字体颜色
range1.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing) .Color.Red);
希望有帮助
单元字体颜色
Excel.Range formatRange;
formatRange = xlWorkSheet.get_Range( b1, b1);
formatRange.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
单元格背景颜色
Excel.Range formatRange;
formatRange = xlWorkSheet.get_Range( b1, b1);
formatRange.Interior.Color = System.Drawing。
ColorTranslator.ToOle(System.Drawing.Color.Red);
更多信息...... Excel细胞格式化
Niva
MSDN上有一个示例项目,介绍如何在C#中设置Excel中的字体样式。希望这是你的选择。
https://code.msdn.microsoft.com/Set-Excel-Font-Style-in-C-8b1e3d11 [ ^ ]
Hello All,
I have added data to Excel Worksheet using worksheet.Cells[Row, Col] = Data;
worksheet is defined accordingly.
Now i need to give a specific format to this cell with Row number "Row" and column number "Col" . i tried using the get_range method and setting the color or font size, but its not working. is there any way i can do this.
解决方案
Create a named range:
Microsoft.Office.Tools.Excel.NamedRange Range1 = this.Controls.AddNamedRange(this.Range["A1:B20"] "NamedRange1");
Set Font Color
range1.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
Hope that helps
Cell Font Color
Excel.Range formatRange; formatRange = xlWorkSheet.get_Range("b1", "b1"); formatRange.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
Cell Background color
Excel.Range formatRange; formatRange = xlWorkSheet.get_Range("b1", "b1"); formatRange.Interior.Color = System.Drawing. ColorTranslator.ToOle(System.Drawing.Color.Red);
More info...Excel Cell Formatting
Niva
There is a sample project on MSDN that presents how to set font style in Excel in C#. Hope this an option for you.
https://code.msdn.microsoft.com/Set-Excel-Font-Style-in-C-8b1e3d11[^]
这篇关于如何使用C#在Excel单元格中设置字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文