|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Features
PowerPoint 2003 is Full of BugsMy first experiments using PowerPoint 2003 failed because PP 2003 is !FULL! of ugly bugs. Example: There were a lot of other things which did not work in PP 2003 and all had one thing in common: they were exremely strange and did not make any sense. I wasted two entire days searching for a workaround: without success. Finally I found the solution: Using PowerPoint 2007 which does not have these bugs anymore. When I started the project I didn't want to use PowerPoint 2007 because I wanted to create PPP documents which can also be played on PP 2003. But then I found that my documents created on PP 2007 will also play on PP 2002 and PP 2003 without problems. IMPORTANT: Read in the last chapter what you have to install additionally to PP 2007! The PowerPointCreator ProjectThis project demonstrates the creation of a Sales Report of a fictitious company "Ipsum Colors Inc." which sells paints. The following animation shows a PowerPoint Presentation consisting of 5 slides which have been created from the scratch with PowerPointCreator:
Using the Class PPPcreatorLet's have a look how to create the first page (the start slide) string s_TemplatePath = Directory.GetCurrentDirectory() + "\\Templates";
PPPcreator i_PppCreator = new PPPcreator(s_TemplatePath, true);
Hashtable i_Replacements = new Hashtable();
i_Replacements["CurrentDate"] = DateTime.Today.ToString("dd. MMMM yyyy");
i_PppCreator.InsertTemplateSlide(-1, null, "Template_StartSlide.xml", i_Replacements);
It's really that simple! These 5 lines of code create an entire PowerPoint slide! You specify an XML template "Template_StartSlide.xml" and a hashtable with replacements for all dynmic data which is to be inserted into the template (here the current date). The second parameter of the You can also insert new slides into an already existing presentation: i_PppCreator.LoadPresentation (@"C:\My Documents\....\SalesReport.ppt");
i_PppCreator.InsertTemplateSlide(5, "Template_Background.pot", "Template_XYZ.xml",
i_Replacements);
The first parameter of The second parameter of The XML TemplatesThe structure of the XML templates is very similar to HTML files. The templates completely define how the resulting Presentation will look. They contain two main tags:
The Shapes tag contains all PowerPoint Shapes you want to insert into the document like TextBoxes, Tables, Pictures or Lines. ATTENTION: The XML - Shapes Section<Shapes>
<Textbox Top="60" Left="120" Width="580" Style="TitleBox" Name="Title">
Sales Report</Textbox>
<Picture Top="155" Left="120" Width="250" Height="195">Company_Logo.gif</Picture>
<Table Top="75" Left="45" ColumnWidths="100,120,100,150" MaxHeight="405">
<Row Height="20">
<Cell Style="CellCommon,CellDark">First Cell</Cell>
<Cell Style="CellCommon,CellBright">Second Cell</Cell>
<Cell Style="CellCommon,CellBright" ColSpan="2">Third and Fourth Cell</Cell>
</Row>
</Table>
<Line BeginX="120" BeginY="465" EndX="120" EndY="494" Style="GreenLine" />
</Shapes>
All Shapes use absolute positioning, so the attributes Every Shape can have an optional Textboxes: Pictures: Tables:The Table in the above example has 4 columns whose widths (100,120,100,150) you specify in the attribute The As the cells in the above example show, you can specify In the Styles section of the XML file (see below) The
The XML - Styles Section<Styles>
<TitleBox Shape.TextFrame.MarginLeft="10"
Shape.TextFrame.TextRange.Font.Name="Arial"
Shape.TextFrame.TextRange.Font.Size="22"
Shape.TextFrame.TextRange.Font.Bold="true"
Shape.TextFrame.TextRange.Font.Color.RGB="#373C71"
Shape.TextFrame.TextRange.ParagraphFormat.Alignment="ppAlignCenter"
/>
<CellCommon Borders.ppBorderTop.Weight="1"
Borders.ppBorderBottom.Weight="1"
Borders.ppBorderLeft.Weight="1"
Borders.ppBorderRight.Weight="1"
Borders.ppBorderLeft.ForeColor.RGB="#373C71"
Borders.ppBorderRight.ForeColor.RGB="#373C71"
Borders.ppBorderBottom.ForeColor.RGB="#373C71"
Shape.TextFrame.TextRange.Font.Name="Arial"
Shape.TextFrame.TextRange.Font.Size="10"
Shape.Fill.Solid="true"
/>
<CellDark Borders.ppBorderTop.ForeColor.RGB="#FFFFFF"
Shape.TextFrame.TextRange.Font.Bold="true"
Shape.TextFrame.TextRange.Font.Color.RGB="#FFFFFF"
Shape.Fill.ForeColor.RGB="#373C71"
/>
etc....
</Shape>
All entries have exactly the same name as the corresponding objects in the namespace Don't try to abbreviate these attributes!! For example: A cell may specify border settings (LineFormat), also a row and a Line use the same properties. There are multiple objects which allow you to specify a ForeColor or BackColor. You will run into a big confusion if you try to simplify these long properties! If you need additional properties which are not yet supported by the Table Cell BordersWhen you define the cell borders you have to be careful. For each cell you can specify width, color, etc.. for it's top border, bottom border, left border and right border separately. But each cell shares its borders with its neigbours...
To obtain a table as you see in this image the cell C must define a top border which is white, but Cell B must define a top border which is blue, while the bottom border of all Cells A-C may be defined as ANYthing which will be ignored as the next row overwrites it with its own settings! The bottom border will ONLY be of importance in the very last row. If you study the file "Template_Table.xml" thoroughly you will understand how it works:
That means that the TopBorder color in Cell B:
<Cell Style="CellCommon,CellDark,CellTopDark">Priority</Cell>
Cell C:
<Cell Style="CellCommon,CellDark">Finished</Cell>
The ReplacementsThe Replacements make the templates really dynamic. To insert a dynamic title into a PP slide write in the XML file: <Shapes>
<Textbox Top="60" Left="120" Width="580" Style="TitleBox">%Title%</Textbox>
</Shapes>
The data to be insterted may come from a database, you can read it from a XML file, or get it from wherever you like. You have to store it into a hashtable and pass it to Hashtable i_Replacements = new Hashtable(); i_Replacements["Title"] = "Sales Report"; i_PppCreator.InsertTemplateSlide(-1, null, "Template_Table.xml", i_Replacements); You can do the same with text in table cells or picture files. Also, the values of Attributes can be defined dynamically. For example, if your template defines different title styles you can decide at runtime which style to use for the title: <Shapes> <Textbox Top="60" Left="120" Width="580" Style="%TitleStyle%">Sales Report</Textbox> </Shapes> Dynamic ListsAnd what if I want to create a list with a variable count of rows (for example from a database)? No problem! Write in the XML file: <Shapes>
<Table Top="100" Left="65" ColumnWidths="360,77,77,77" MaxHeight="405">
<Row Height="15" DataSource="SalesData">
<Cell Style="xyz">%SalesData#Product%</Cell>
<Cell Style="xyz">%SalesData#Sold%</Cell>
<Cell Style="xyz">%SalesData#Profit%</Cell>
<Cell Style="xyz">%SalesData#Percent%</Cell>
</Row>
</Table>
</Shapes>
The row will be repeated as often as your DataSource has row entries. The replacements must be of the form DataSource i_SalesData = new DataSource(new string[]{ "Product", "Sold", "Profit",
"Percent" });
i_SalesData.AddRow(new string[]{"LA553 - Gallon Ultra Premium Flat Wall Paint",
"353.912", "$3.267.000", "25,7%"});
i_SalesData.AddRow(new string[]{"IN965 - Interior Wall Paint 10 litre Acryl",
"270.733", "$2.332.000", "22,4%"});
etc...
Hashtable i_Replacements = new Hashtable();
i_Replacements["SalesData"] = i_SalesData;
i_PppCreator.InsertTemplateSlide(-1, "Template_Background.pot",
"Template_DynamicList.xml", i_Replacements);
The Above you will find an example of everything I've explained in the PowerPointCreator project. RestrictionsPowerPoint is very slow. When you create a presentation "live" you will see how it draws every single table cell and prints the text. PowerPoint is quite primitive (like the entire Office package). For example, it does not allow you to put a picture into a table cell. This is not possible. Also you cannot append a table row to the end of a table. If the previous row has merged cells (uses ColSpan) the new row would merge the same cells although you never did program that. For all these things A documentation for the PowerPoint API does not exist. What you find in the MSDN is ridiculous. You have to find out all by trial and error. Some functions which exist in the PowerPoint API are not implemented. (for example Slide.Shapes.AddDiagram(...)) The Helper GridAll PowerPoint presentations use the odd coordinate system of 720 x 540 pixels. To ease the definition of coordinates when creating the XML file, PowerPointCreator draws a helper grid when compiled in Debug mode. Every 20 pixels a dashed line is drawn and every 100 units a solid line:
SourcecodeYou will find a very clean and well structured C# sourcecode with plenty comments, written by a very experienced programmer. The code is reusable, so you can easily put it into your own projects:
Requirementsto compile or run this project:
Future VersionsThe current version 2.0 contains a lot of useful functionality. Probably future versions, which will be published on Codeproject, will contain more functionality like dynamic generation of diagrams, etc.. Elmü
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||