![](/img/trans.png)
[英]How to format the text box of excel to change the font style,size,name using c#,Microsoft.Office.Interop.Excel
[英]How to write a text inside a rectangle in excel using Microsoft.Office.Interop.Excel in c#
这是示例代码..
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
//Rectangle shape
xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, 47, 280, 140, 90);
//using this below code i can write the text but the text is showing with special effects.
xlWorkSheet.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, "simple text", "Arial", 14, MsoTriState.msoTrue, MsoTriState.msoFalse, 67, 320);
我需要带有粗体效果和大小的纯文本(16)...我正在使用 Visual Studio 2008
我不是 C# 编码员,但我相信这可以编译并满足您的需求。 我在 C# 2010 和 Excel 2010 中对其进行了测试:
using Excel = Microsoft.Office.Interop.Excel;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Shape shp;
shp = xlWorkSheet.Shapes.AddShape(Office.MsoAutoShapeType.msoShapeRectangle, 47, 280, 140, 90);
shp.Fill.Visible = Office.MsoTriState.msoFalse;
shp.TextFrame2.TextRange.Font.Bold = Office.MsoTriState.msoTrue;
shp.TextFrame2.TextRange.Font.Name = "Arial";
shp.TextFrame2.TextRange.Font.Size = 16;
shp.TextFrame2.TextRange.Font.Fill.Visible = Office.MsoTriState.msoTrue;
shp.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = (int)Excel.XlRgbColor.rgbBlack;
shp.TextFrame2.TextRange.Characters.Text = "Test";
我只是使用文本框。
Excel.Shape textbox = xlShapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 20, 20, 150, 20);
textbox.TextFrame.Characters(missing, missing).Text = "Hey";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.