2012-01-05 140 views
0

//下面是示例代码..如何格式化Excel中的文本框中更改字体样式,大小,使用名称C#,的Microsoft.Office.Interop.Excel

Excel.Application xlApp; 
Excel.Workbook xlWorkBook; 
Excel.Worksheet xlWorkSheet; 

//创建形状对象...

Microsoft.Office.Interop.Excel.Shape[] myShapes = new Microsoft.Office.Interop.Excel.Shape[1]; 

//创建矩形

xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, 47, 24, 500, 90); 

//添加文本框

myShapes[0] = xlWorkSheet.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, 75, 64,60, 30); 
      myShapes[0].TextFrame.Characters(misValue, misValue).Text = "simple text"; 
      myShapes[0].Line.Visible = MsoTriState.msoFalse; 
      myShapes[0].Select(true); 

回答

0

尝试myShapes[0].TextFrame2.TextRange.Font = 12

0

这是怎么了你添加图形,并使用互操作格式化。

Shape sh = myWorksheet.Shapes.AddPicture("...\\Images\\test.png", 
            Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, 
            603,116, 162, 221); // Set Left,Top,Width, height 
    sh.Placement = XlPlacement.xlFreeFloating; 
    sh.TextFrame.Characters(Type.Missing, Type.Missing).Insert("This is sample text !!"); 
         sh.TextFrame.Characters(Type.Missing, Type.Missing).Font.Size = 13; 
    sh.TextFrame.Orientation = Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal; 
    sh.TextFrame.VerticalAlignment = XlVAlign.xlVAlignCenter; 
    sh.TextFrame.HorizontalAlignment = XlHAlign.xlHAlignLeft; 
    sh.TextFrame.Characters(Type.Missing, Type.Missing).Font.ColorIndex = 2; 
    sh.TextFrame.HorizontalAlignment = XlHAlign.xlHAlignCenter; 

    int titleBg = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.FromArgb(51, 204, 204)); 
    sh.Fill.ForeColor.RGB = titleBg; 
    sh.Fill.ForeColor.SchemeColor = 41; 
    sh.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse; 
相关问题