...
Code Block |
---|
public void ChartImageReport() { using (PowerPointTemplate pptt = new PowerPointTemplate()) { pptt.Open(@"C:\Users\gabeg\Desktop\Internal Projects\PPTW Documentation\Testing Solutions\PPTWDoc\ChartImage\template.pptx"); //get the data to display with the chart DataTable dtChart = GetCSVData(@"C:\Users\gabeg\Desktop\Internal Projects\PPTW Documentation\Testing Solutions\PPTWDoc\ChartImage\data.csv"); pptt.BindData(dtChart, "UnitSales", pptt.CreateDataBindingProperties()); //get the Chart object[] chartImage = { System.IO.File.ReadAllBytes(@"C:\Users\gabeg\Desktop\Internal Projects\PPTW Documentation\Testing Solutions\PPTWDoc\ChartImage\chart.png") }; string[] chart = {"Chart"}; pptt.BindData(chartImage, chart, "Images", pptt.CreateDataBindingProperties()); pptt.Process(); //pass to Application object to align chart image PowerPointApplication ppta = new PowerPointApplication(); Presentation pres = ppta.Open(pptt); //Get a handle on the chart image Slide slide1 = pres.Slides[0]; Pictures allPics = slide1.Pictures; Picture pic = allPics[0]; int numPics = allPics.Count(); //Align the picture pic.Align(Alignment.Middle); ppta.Save(pres, Page.Response, "output.pptx", false); } ///<summary> /// Uses a 3rd party generic CSV parser #region Utility Methods //Uses CSV reader System.Data.DataTable GetCSVData(string csvFileName) { DataTable dt; using (GenericParserAdapter parser = new GenericParserAdapter(csvFileName)) { parser.ColumnDelimiter = ','; parser.FirstRowHasHeader = true; dt = parser.GetDataTable(); } return dt; } #endregion } |
...