以下是示例代码..
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
答案 0 :(得分:3)
我不是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";
答案 1 :(得分:2)
我只是使用文本框。
Excel.Shape textbox = xlShapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 20, 20, 150, 20);
textbox.TextFrame.Characters(missing, missing).Text = "Hey";