There is a time for all good things to come to an end, and the time has come to shut down OpenXmlDeveloper.org.
Screen-casts and blog posts: Content on OpenXmlDeveloper.org will be moving to EricWhite.com.
Forums: We are moving the forums to EricWhite.com and StackOverflow.com. Please do not post in the forums on OpenXmlDeveloper.org. Instead, please post in the forums at EricWhite.com or at StackOverflow.com.
Please see this blog post for more information about my plans moving forward. Cheers, Eric
Article by: Vijayeta.t of SONATA SOFTWARE LIMITED
This article explains how to fetch data from a database and use that data to create a PresentationML document. Each slide in the presentation consists of a heading and a subtitle, and the data for these textboxes is retrieved from a table in database.
The attached sample application provides the user with a GUI, wherein the user has the option to choose the slide contents.
The user can select the database using the textbox provided, which displays the connection string.
The dropdown listbox contains all the topics for which the slides can be generated. On selection of a particular topic, the slide headings for that topic, and a brief data about the particular slide heading is displayed in the list view.
Among the slide headings displayed, user can select the titles required for the presentation document.
The presentation document is then generated, where slides would hold the selected headings and corresponding subtitles.
Initially the combo box drops down displaying the slides available. When a topic is selected,at the backend all the records corresponding the topic are fetched from the database, i.e. the table containing the Slide Titles and a brief description about the Title, and are mapped to the Listview.
string selectstatement = "select Title,Description from mainTable " ;
SqlDataAdapter myAdpt = new SqlDataAdapter(selectstatement, conn);
DataSet ds=new DataSet ();
table = ds.Tables["mainTable"];
// Clear the ListView control
for (int i = 0; i < table.Rows.Count; i++)
DataRow drow = table.Rows[i];
listView1.GridLines = true;
ListViewItem lvi = new ListViewItem(drow["Title"].ToString());
lvi.SubItems .Add (drow ["Description"].ToString ());
On selection of the required titles, all the rows from the table containing the Titles and Subtitles are fetched and a comparison is done between the rows fetched and the items selected in the Listview, hence the slides are generated for the selected titles.
string selectstatement = "select Title,SubTitle from " + tableName;
DataSet ds = new DataSet();
table = ds.Tables[tableName];
for (int i = 0; i <table.Rows.Count; i++)
DataRow drow = table.Rows[i];
for (int j = 0; j <listView1.SelectedItems.Count; j++)
if (listView1.SelectedItems[j].ToString().Remove(0, 15).TrimEnd('}') == (drow.ToString()))
Heading.Add ( drow.ToString());
SubTitle.Add ( drow.ToString());
The files such as SlideX.xml that holds the contents of slides and presentation.xml that describes the relationship Id of each of the slides, are created programatically.
Additional xml files in the Presentation document are the standard files such as SlideLayouts, SlideMaster, NotesMaster and Themes. Since these files are not created programatically,they are added along with the .exe file, which are then read and packaged to form the presentation package. These files could also be created programatically as part of package.
The Application code and table structure required for the application to run is attached.