2012-01-05 35 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; 
相關問題