如何在excel中使用Microsoft.Office.Interop.Excel在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中testing了它:
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";