Hi,
A while ago because the work needs, start gathering on the Internet how to use the program to generate PPT, PPT including the content of the text box, graphs, diagrams, tables, elements such as images, of course, content of the text box, and the location of the graphics, the chart of data source, the data in the table are dynamically loaded (the team),
Himself is a halfway decent code farmers, more thinking mainly comes from the predecessors experience and online resources, in CSDN obtained a lot of time to help (you read my post) is known, so this time is mainly focused on BBS search related resources, in order to complete the task,
However, whether through professional BBS, or directly baidu, search out resources is very little, and repetitive, so in the end, I'll use the most stupid way:. The Microsoft Office. Interop. PowerPoint related interfaces in the class, to the Microsoft website to view the document, and to complete to add, set, modify operations, such as
Just stick my program, below is summary about before all the help of man; 2 will also want to work if you have friends need to do to generate PPT, the hope can help them,
1. Refer to Microsoft PowerPoint is added in the project 14.0 Object Library
2. Using Microsoft. Office. Interop. PowerPoint;
3. Create a PPT, add a blank page
Microsoft. Office. Interop. PowerPoint. Application PPT.=new Microsoft Office. Interop. PowerPoint. The Application ();//create PPT application
Microsoft. Office. Interop. PowerPoint. The Presentation MyPres=null;//PPT application instance of the
. Microsoft. Office. Interop. PowerPoint Slide MySlide=null;//powerpoint slide
MyPres=PPT. Presentations. Open (" file path ", MsoTriState msoFalse, MsoTriState. MsoFalse, MsoTriState. MsoTrue);//here gave a powerpoint presentation instance MyPres
MySlide=MyPres. Slides TAB. Add (1, Microsoft Office. Interop. PowerPoint. PpSlideLayout. PpLayoutBlank);//as PPT example, add a blank page, the location is a "first page"
4. Add elements to the powerpoint slides
4.1 the textbox
Microsoft. Office. Interop. PowerPoint. TextRange MyTextRng=null;
MySlide. Shapes. AddTextbox (MsoTextOrientation msoTextOrientationHorizontal, 21.5 F and 365 F and 670 F and 270 F).
MyTextRng=MySlide. Shapes. [1]. TextFrame TextRange;//please note that the Shapes of the index, due to the text box is the first to add Shapes, so the index is 1,
MyTextRng. The Font. NameFarEast="Microsoft jas black";//in the text box, Chinese font
MyTextRng. The Font. NameAscii="Calibri";//in the text box, English and digital font
MyTextRng. Text="c # generate PPT";//display the contents of the
MyTextRng. The Font. Bold=MsoTriState. MsoTrue;//whether the bold
MyTextRng, the Font Color. The RGB=A + B + C * 256 * 256 * 256; ABC//font color, which can be directly through the number in the custom colors,
MyTextRng. Characters (1, 10). The Font Size=24;//the personalized design, the first character, length of 10 characters, the font size is 24.
MyTextRng. ParagraphFormat. Alignment=Microsoft. Office. Interop. PowerPoint. PpParagraphAlignment. PpAlignLeft;//text alignment (horizontal)
MySlide. Shapes [1]. TextFrame. VerticalAnchor=MsoVerticalAnchor. MsoAnchorMiddle; Text alignment (vertical direction)
Result: the most important Settings in the Font properties, other Settings, basic can refer to PPT element attributes set in ways to find, such as when I am writing the text level Alignment (left, center, right), in the PPT, we directly click "paragraph" the shortcut keys, so I just find "paragraph" in English, just the Alignment is the Alignment of meaning, so I find it,
4.2 graphics (rectangular)
MySlide. Shapes. AddShape (MsoAutoShapeType msoShapeRectangle, 8.5 F, 6.5 F and 705 F and 525 F).
MySlide. Shapes [1]. Line. ForeColor, RGB=A + B + C * 256 * 256 * 256;//change the line color
MySlide. Shapes [1]. The Fill. Transparency=1;//control fill color for transparent
MySlide. Shapes [1]. The Line. The Style=MsoLineStyle. MsoLineSingle;//change in the linear composite type
MySlide. Shapes [1]. Line. Weight=1 f;//change the line thickness
MySlide. Shapes [1]. Shadow. Style=MsoShadowStyle. MsoShadowStyleOuterShadow;//control shadow type
MySlide. Shapes [1]. Shadow. ForeColor. RGB=0;//control shadow color
MySlide. Shapes [1]. Shadow. Transparency=0.6 F;//control transparency
MySlide. Shapes [1]. Shadow. Size=100 f;//control size
MySlide. Shapes [1]. The Shadow. The Blur=4 f.//control functions
MySlide. Shapes [1]. Shadow. OffsetX=2.1 F;//control distance;
MySlide. Shapes [1]. Shadow. OffsetY=2.1 F;//and joint decision offsetX
Result: some basic requirements, through the English can distinguish, whether some of the attributes set in line with expectations, however, need to wait after graph generated further confirmed,
4.3 the picture
MySlide. Shapes. AddPicture (" file path ", MsoTriState msoFalse, MsoTriState. MsoTrue, 27 f, 24 f, 665 f and 333 f).
Table 4.4
Microsoft. Office. Interop. PowerPoint. Table MyTable=null;
MyTable=MySlide. Shapes. AddTable (19, 5, 40 f, 100 f, 10 f, 10 f). The Table;//create a specified width and height, not form the final size,
MyTable. Cell (k, j) Shape. TextFrame. TextRange. The Font, Size=10;
MyTable. Cell (k, j) Shape. TextFrame. TextRange. The Font, Color, RGB=A + B + C * 256 * 256 * 256;
MyTable. Cell (k, j) Shape. TextFrame. TextRange. The Font. NameAscii="Arial";
MyTable. Cell (k, j) Shape. TextFrame. TextRange. The Font. NameFarEast="Microsoft jas black";
MyTable. Cell (k, j) Shape. TextFrame. TextRange. The Font, Bold=MsoTriState. MsoTrue;
MyTable. Cell (k, j) Shape. TextFrame. TextRange. ParagraphFormat. Alignment=. Microsoft Office. Interop. PowerPoint. PpParagraphAlignment. PpAlignCenter;
MyTable. Cell (k, j) Shape. TextFrame. VerticalAnchor=MsoVerticalAnchor. MsoAnchorMiddle;
MyTable. Cell (k, j) Shape. The Fill. ForeColor. RGB=0;
MyTable. Cell (k, j) Shape. TextFrame. TextRange. Text="c # generate PPT";
Almost and Settings, here the text box, only need to the selected Cell, some personalized design, such as merger resolution Cell, border color, according to the general meaning can be found in English,
Chart 4.5
Microsoft. Office. Interop. PowerPoint. Chart MyChart=null;//chart
Microsoft. Office. Interop. PowerPoint. ChartData MyChartData=https://bbs.csdn.net/topics/null;//chart data
Microsoft. Office. Interop. PowerPoint. The Axis MyYvalaxis=null;//chart ordinate
Microsoft. Office. Interop. PowerPoint. The Axis MyXvalaxis=null;//chart abscissa
Microsoft. Office. Interop. PowerPoint. DataLabels MyDataLabels=null;//chart data tag
Microsoft. Office. Interop. PowerPoint. Series MySeries=null;//data series
Microsoft. Office. Interop. PowerPoint. ChartGroups MyChartGroups=null;//data series - a series of options
Microsoft. Office. Interop. PowerPoint. Points MyPoints=null;//data series
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull