//Here is the sample code..
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
//creating shape object...
Microsoft.Office.Interop.Excel.Shape[] myShapes = new Microsoft.Office.Interop.Excel.Shape[1];
//creating rectangle shape
xlWorkSheet.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, 47, 24, 500, 90);
//adding text box
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);
This is how your add a shape and format it using Interop.
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;
尝试myShapes[0].TextFrame2.TextRange.Font = 12
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.