/// <summary> /// Creates charts in a presentation. /// </summary> private void BtnCreatePresn_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { //Creates a new instance of the PowerPoint Presentation file. using IPresentation presentation = Presentation.Create(); //Creates slides with chart. CreateChart(presentation); using MemoryStream ms = new(); if (presentationdoc.IsChecked == true) { //Saves the presentation to the memory stream. presentation.Save(ms); ms.Position = 0; //Saves the memory stream as file. SaveAndLaunch.Save("Chart.pptx", ms); } else { //Converts the PowerPoint Presentation to PDF document. using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(presentation)) { //Saves the converted PDF document to MemoryStream. pdfDocument.Save(ms); ms.Position = 0; } //Saves the memory stream as file. SaveAndLaunch.Save("Chart.pdf", ms); } }
private void Button_Click_6(object sender, RoutedEventArgs e) { //Create a new instance of PowerPoint Presentation file IPresentation pptxDoc = Presentation.Create(); //Add a new slide to file and apply background color ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleOnly); //Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide IShape titleShape = slide.Shapes[0] as IShape; titleShape.TextBody.AddParagraph(titleWord.Text).HorizontalAlignment = HorizontalAlignmentType.Center; //Add description content to the slide by adding a new TextBox IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70); descriptionShape.TextBody.Text = bodyPPT.Text; //Gets a picture as stream. Stream pictureStream = File.Open("C:/ImagesForPowerPoint/ImagesForPowerPoint/Images/image6.png", FileMode.Open); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16); pictureStream.Close(); //Save the PowerPoint Presentation //pptxDoc.Save("Sample.pptx"); //Close the PowerPoint presentation //pptxDoc.Close(); }
public ActionResult SmartArtCreation(FormCollection form) { IPresentation presentation = Presentation.Create(); //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. //Method call to edit slides SmartArt1(presentation); SmartArt2(presentation); SmartArt3(presentation); SmartArt4(presentation); string choice = form["File Type"]; if (choice == "PPTX") { // Saves the presentation return(new PresentationResult(presentation, "SmartArtSample.pptx", HttpContext.ApplicationInstance.Response)); } else { PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings(); settings.ShowHiddenSlides = true; //Instance to create pdf document from presentation PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings); //Saves the pdf document return(new Syncfusion.Mvc.Pdf.PdfResult(doc, "PPTXToPDF.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
public FileStreamResult GeneratePPT(List <ViewData> viewDataList) { //Creates a PowerPoint instance IPresentation pptxDoc = Presentation.Create(); ExcelEngine excelEngine = new ExcelEngine(); IApplication excelApplication = excelEngine.Excel; excelApplication.DefaultVersion = ExcelVersion.Excel2016; foreach (var item in viewDataList) { if (String.IsNullOrEmpty(item.ChartType)) { continue; } IWorkbook wb = excelApplication.Workbooks.Open(item.DataStream, ExcelOpenType.CSV); IWorksheet worksheet = wb.Worksheets[0]; worksheet.Name = item.Name; DataTable dataTable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames | ExcelExportDataTableOptions.DetectColumnTypes); if (dataTable == null) { continue; } wb.Close(); ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Handle error here to continue after chart testing is done. try { if (item.ChartType.Equals("Table")) { CreateTable(dataTable, slide, item); } else { CreateChart(slide, dataTable, item); } } catch (Exception e) { _logger.LogError(e.Message); continue; } } MemoryStream stream = new MemoryStream(); pptxDoc.Save(stream); //Set the position as '0'. stream.Position = 0; //Download the PowerPoint file in the browser FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/powerpoint"); fileStreamResult.FileDownloadName = "Editable-" + DateTime.Now.ToString() + ".pptx"; //WorkbookTuple.Item2.Close(); pptxDoc.Close(); return(fileStreamResult); }
//Create slide using SyncFusion framework private void btnCreateSlide_Click(object sender, EventArgs e) { user.Title = txtTitle.Text; user.TextField = txtTextField.Text; IPresentation powerpointDoc = Presentation.Create(); ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.Blank); IShape title = slide.AddTextBox(50, 40, 500, 100); title.TextBody.AddParagraph(user.Title); title.TextBody.Paragraphs[0].Font.FontSize = 24; IShape textfield = slide.AddTextBox(100, 110, 800, 300); textfield.TextBody.AddParagraph(user.TextField); for (int imgCt = 1; imgCt <= user.Images.Count; imgCt++) { var ms = new MemoryStream(); user.Images[imgCt - 1].Save(ms, ImageFormat.Png); IPicture picture = slide.Pictures.AddPicture(ms, ReturnImgLength(imgCt), 350, user.Images[imgCt - 1].Width * 1.25, user.Images[imgCt - 1].Height * 1.25); } powerpointDoc.Save("GeneratedPowerpoint.pptx"); powerpointDoc.Close(); ResetSelection(); }
private void btnCreateImage_Click(object sender, RoutedEventArgs e) { try { //Getting data from file string dataPath = @"..\..\..\..\..\..\Common\Data\Presentation\"; //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); //Method call to create SmartArt and add it into slides. CreateSlide1(presentation, dataPath); presentation.Save("ChartSample.pptx"); if (System.Windows.MessageBox.Show("Do you want to view the generated PowerPoint Presentation?", "Excel Data To Chart", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process.Start("ChartSample.pptx"); this.Close(); } } catch (Exception exception) { System.Windows.MessageBox.Show("This Presentation could not be created, please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!", MessageBoxButton.OK); this.Close(); } }
private void btnCreatePowerPoint_Click(object sender, RoutedEventArgs e) { //Create a new PowerPoint presentation IPresentation powerpointDoc = Presentation.Create(); //Add a blank slide to the presentation ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.Blank); //Add a textbox to the slide IShape shape = slide.AddTextBox(400, 100, 500, 100); shape.TextBody.AddParagraph(titleAreaText.Text); //Add a text to the textbox. //shape.TextBody.AddParagraph(titleAreaText.Text); shape.TextBody.AddParagraph(textAreaText.Text); //Save the PowerPoint presentation powerpointDoc.Save("Sample.pptx"); //Close the PowerPoint presentation powerpointDoc.Close(); //Open the PowerPoint presentation System.Diagnostics.Process.Start("Sample.pptx"); }
public ScreenTests() { DomainEvents.ClearCallbacks(); testPresentation1 = Presentation.Create("testPresentation1", null, null, null, "media/medium1.mp4"); testPresentation2 = Presentation.Create("testPresentation2", null, null, null, "media/medium2.mp4"); }
public ActionResult SmartArt(string Browser) { IPresentation presentation = Presentation.Create(); //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. //Method call to edit slides CreateSlide1(presentation); CreateSlide2(presentation); CreateSlide3(presentation); CreateSlide4(presentation); MemoryStream ms = new MemoryStream(); //Saves the presentation to the memory stream. presentation.Save(ms); //Set the position of the stream to beginning. ms.Position = 0; //Initialize the file stream to download the presentation. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/vnd.openxmlformats-officedocument.presentationml.presentation"); //Set the file name. fileStreamResult.FileDownloadName = "SmartArt.pptx"; return(fileStreamResult); }
public void GeerateTablePPT() { try { using (var powerpointDoc = Presentation.Create()) { ISlide slide = powerpointDoc.Slides.Add(SlideLayoutType.Blank); ITable table = slide.Shapes.AddTable(2, 2, 100, 120, 300, 200); int rowIndex = 0, colIndex; foreach (IRow rows in table.Rows) { colIndex = 0; foreach (ICell cell in rows.Cells) { cell.TextBody.AddParagraph("(" + rowIndex.ToString() + " , " + colIndex.ToString() + ")"); colIndex++; } rowIndex++; } powerpointDoc.Save(GeneratePath()); } } catch (Exception) { throw; } }
public ActionResult CreateDocument() { // create a powerpoint instance IPresentation pptxDoc = Presentation.Create(); //Add slide to the the Powerpoint presentation ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Addd a textbox to the slide IShape shape = slide.AddTextBox(10, 10, 500, 100); //Add a textbox to the text box shape.TextBody.AddParagraph("Welcome to Powerpoint"); //Save the PowerPoint Presentation pptxDoc.Save("Sample.pptx", FormatType.Pptx, HttpContext.ApplicationInstance.Response); // Close the PowerPoint presentation pptxDoc.Close(); ViewBag.Message = "Create A new SlideShow."; return(View()); }
private void btnCreatePresn_Click(object sender, EventArgs e) { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); //Add slide with titleonly layout to presentation ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); //Get the title placeholder IShape titleShape = slide.Shapes[0] as IShape; //Set size and position of the title shape titleShape.Left = 0.92 * 72; titleShape.Top = 0.4 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.01 * 72; //Add title content titleShape.TextBody.AddParagraph("Ole Object Demo"); //Set the title content as bold titleShape.TextBody.Paragraphs[0].Font.Bold = true; //Set the horizontal alignment as center titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Center; //Add text box of specific size and position IShape heading = slide.Shapes.AddTextBox(3.2 * 72, 1.51 * 72, 1.86 * 72, 0.71 * 72); //Add paragraph to text box heading.TextBody.AddParagraph("MS Excel Object"); //Set the text content as italic heading.TextBody.Paragraphs[0].Font.Italic = true; //Set the text content as bold heading.TextBody.Paragraphs[0].Font.Bold = true; //Set the font size heading.TextBody.Paragraphs[0].Font.FontSize = 18; string excelPath = @"..\..\..\..\..\..\..\Common\Data\Presentation\OleTemplate.xlsx"; //Get the excel file as stream Stream excelStream = File.Open(excelPath, FileMode.Open); string imagePath = @"..\..\..\..\..\..\..\Common\Images\Presentation\OlePicture.png"; //Image to be displayed, This can be any image Stream imageStream = File.Open(imagePath, FileMode.Open); //Add ole object to the slide IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Excel.Sheet.12", excelStream); //Set size and position of the ole object oleObject.Left = 3.29 * 72; oleObject.Top = 2.01 * 72; oleObject.Width = 6.94 * 72; oleObject.Height = 5.13 * 72; //Save the presentation presentation.Save("OleObjectSample.pptx"); //Close the presentation presentation.Close(); if (System.Windows.MessageBox.Show("Do you want to view the generated Presentation?", "Presentation Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process.Start("OleObjectSample.pptx"); this.Close(); } }
public void CreatePresentation() { var rep = new MediaRepository(); var item = Presentation.Create("Test", DateTime.Now, DateTime.MaxValue, 0, "/movies/test.mp4"); rep.Insert(item); }
private void btnCreateImage_Click(object sender, RoutedEventArgs e) { try { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. using (IPresentation presentation = Presentation.Create()) { //Method call to create SmartArt and add it into slides. CreateSlide1(presentation); CreateSlide2(presentation); CreateSlide3(presentation); CreateSlide4(presentation); if (this.radioButton.IsChecked.Value) { presentation.Save("SmartArtCreation.pptx"); if (System.Windows.MessageBox.Show("Do you want to view the generated PowerPoint Presentation?", "SmartArt Creation", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("SmartArtCreation.pptx") { UseShellExecute = true }; process.Start(); } } else if (this.radioButton1.IsChecked.Value) { //To set each slide in a pdf page. PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings(); settings.ShowHiddenSlides = true; //Instance to create pdf document from presentation using (PdfDocument doc = PresentationToPdfConverter.Convert(presentation, settings)) { //Saves the pdf document doc.Save("Sample.pdf"); } if (System.Windows.MessageBox.Show("Do you want to view the generated PDF document?", "SmartArt Creation", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); } } } } catch (Exception exception) { System.Windows.MessageBox.Show("This file could not be converted, please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!", MessageBoxButton.OK); } }
public void Handle(TaskFinishedEvent args) { _taskRepository.Delete(args.Task.Id); var hubContext = GlobalHost.ConnectionManager.GetHubContext <TaskSchedulerHub>(); var originalfilename = Path.GetFileName(args.Task.OriginalFile); var filename = Path.GetFileNameWithoutExtension(originalfilename) + ".mp4"; var directory = Path.GetDirectoryName(args.Task.OutputFile); var folders = directory.Split('\\'); var folder = ""; switch (args.Task.TaskType) { case TaskType.Presentation: folder = ConfigurationManager.AppSettings["PresentationsFolder"]; break; case TaskType.Video: folder = ConfigurationManager.AppSettings["VideosFolder"]; break; } string userId = folders[folders.Length - 1]; string virtualPath = folder + @"/" + userId + @"/" + filename; Medium medium = null; switch (args.Task.TaskType) { case TaskType.Video: medium = Movie.Create(Path.GetFileNameWithoutExtension(originalfilename), DateTime.Now, DateTime.MaxValue, 0, virtualPath); medium.CreatedBy = userId; medium.ModifiedBy = userId; _mediaRepository.Insert(medium); break; case TaskType.Presentation: medium = Presentation.Create(Path.GetFileNameWithoutExtension(originalfilename), DateTime.Now, DateTime.MaxValue, 0, virtualPath); medium.CreatedBy = userId; medium.ModifiedBy = userId; _mediaRepository.Insert(medium); break; } File.Delete(args.Task.InputFile); hubContext.Clients.All.finishTask(medium.Id.ToString(), virtualPath, originalfilename, medium.Title); EventLog eventLog = new EventLog() { Source = "EyeBoard Scheduler", Log = "EyeBoard Management" }; eventLog.WriteEntry("Task finished: " + args.Task.OutputFile, System.Diagnostics.EventLogEntryType.Information, 1004); }
private void btnCreateImage_Click(object sender, RoutedEventArgs e) { try { //Opens the existing presentation stream. using (IPresentation presentation = Presentation.Create()) { ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IParagraph paragraph = ((IShape)slide.Shapes[0]).TextBody.Paragraphs.Add(); //Apply center alignment to the paragraph paragraph.HorizontalAlignment = HorizontalAlignmentType.Center; //Add slide title ITextPart textPart = paragraph.AddTextPart("Northwind Management Report"); textPart.Font.Color = ColorObject.FromArgb(46, 116, 181); //Get chart data from xml file DataSet dataSet = new DataSet(); dataSet.ReadXml(@"..\..\..\..\..\..\..\Common\Data\Presentation\Products.xml"); //Add a new chart to the presentation slide IPresentationChart chart = slide.Charts.AddChart(44.64, 133.2, 870.48, 380.16); //Set chart type chart.ChartType = OfficeChartType.Pie; //Set chart title chart.ChartTitle = "Best Selling Products"; //Set chart properties font name and size chart.ChartTitleArea.FontName = "Calibri (Body)"; chart.ChartTitleArea.Size = 14; for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++) { chart.ChartData.SetValue(i + 2, 1, dataSet.Tables[0].Rows[i].ItemArray[1]); chart.ChartData.SetValue(i + 2, 2, dataSet.Tables[0].Rows[i].ItemArray[2]); } //Create a new chart series with the name “Sales” AddSeriesForChart(chart); //Setting the font size of the legend. chart.Legend.TextArea.Size = 14; //Setting background color chart.ChartArea.Fill.ForeColor = System.Drawing.Color.FromArgb(242, 242, 242); chart.PlotArea.Fill.ForeColor = System.Drawing.Color.FromArgb(242, 242, 242); chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 11, 1]; //Saves the presentation instance to the stream. presentation.Save("ChartCreationSample.pptx"); if (System.Windows.MessageBox.Show("Do you want to view the generated PowerPoint Presentation?", "Chart Creation", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process.Start("ChartCreationSample.pptx"); this.Close(); } } } catch (Exception exception) { System.Windows.MessageBox.Show("This Presentation could not be created, please contact Syncfusion Direct-Trac system at http://www.syncfusion.com/support/default.aspx for any queries. ", "OOPS..Sorry!", MessageBoxButton.OK); this.Close(); } }
public static void Main() { /* Take in values for numbers of slides and images to parse from HTML */ Console.WriteLine("How many items do you need?: "); string input = Console.ReadLine(); int number; Int32.TryParse(input, out number); /* Take in user response for image content */ Console.WriteLine("What would you like to search for?: "); var search = Console.ReadLine(); /* Load Shutterstock site and create new WebClient and scrape searching for <img src> tag */ var document = new HtmlWeb().Load("https://www.shutterstock.com/search/" + search); WebClient client = new WebClient(); var urls = document.DocumentNode.Descendants("img") .Select(e => e.GetAttributeValue("src", null)) .Where(s => !String.IsNullOrEmpty(s)); int x = 0; /* Initialize new PPT Presentation using SyncFusion */ IPresentation pptxDoc = Presentation.Create(); /* Iterate over urls of images, download to local directory number of specified images */ foreach (string item in urls) { if (x == number) { break; } client.DownloadFile(item, search + x + ".jpg"); Console.WriteLine(item); /* Create new Blank slide, take in User title text */ ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); Console.WriteLine("Enter title text: "); var title = Console.ReadLine(); /* Open local image files scraped from web and add to slide with user defined title of each slide */ Stream pictureStream = File.Open("./" + search + x + ".jpg", FileMode.Open); slide.Pictures.AddPicture(pictureStream, slide.SlideSize.Width / 2, slide.SlideSize.Height / 2, 250, 250); IShape titleTextBox = slide.AddTextBox(slide.SlideSize.Width / 2, 10, 500, 500); IParagraph paragraph = titleTextBox.TextBody.AddParagraph(); ITextPart textPart = paragraph.AddTextPart(); textPart.Text = title; pictureStream.Dispose(); x++; } /* Save PPT project */ pptxDoc.Save("Sample.pptx"); pptxDoc.Close(); Console.ReadLine(); }
/// <summary> /// Manipulates the chart sample. /// </summary> private void ManipulateSample() { MemoryStream stream = new MemoryStream(); //Opens the existing presentation stream. using (IPresentation presentation = Presentation.Create()) { ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IParagraph paragraph = ((IShape)slide.Shapes[0]).TextBody.Paragraphs.Add(); //Apply center alignment to the paragraph paragraph.HorizontalAlignment = HorizontalAlignmentType.Center; //Add slide title ITextPart textPart = paragraph.AddTextPart("Northwind Management Report"); textPart.Font.Color = ColorObject.FromArgb(46, 116, 181); //Get chart data from xml file List <ProductDetails> Products = LoadXMLData(); //Add a new chart to the presentation slide IPresentationChart chart = slide.Charts.AddChart(44.64, 133.2, 870.48, 380.16); //Set chart type chart.ChartType = OfficeChartType.Pie; //Set chart title chart.ChartTitle = "Best Selling Products"; //Set chart properties font name and size chart.ChartTitleArea.FontName = "Calibri (Body)"; chart.ChartTitleArea.Size = 14; for (int i = 0; i < Products.Count; i++) { ProductDetails product = Products[i]; chart.ChartData.SetValue(i + 2, 1, product.ProductName); chart.ChartData.SetValue(i + 2, 2, product.Sum); } //Create a new chart series with the name “Sales” AddSeriesForChart(chart); //Setting the font size of the legend. chart.Legend.TextArea.Size = 14; //Setting background color chart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); chart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 11, 1]; //Saves the presentation instance to the stream. presentation.Save(stream); } stream.Position = 0; if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("ChartsSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("ChartsSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } }
public MemoryStream CreatePowerPoint() { IPresentation presentation = Presentation.Create(); presentation.Slides.Add(SlideLayoutType.Title); CreateDefaultSlide(presentation); MemoryStream memoryStream = new MemoryStream(); presentation.Save(memoryStream); memoryStream.Position = 0; return(memoryStream); }
public ActionResult ExcelDataToChart(string Browser) { IPresentation presentation = Presentation.Create(); // New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. // Method call to create slides CreateChart2(presentation); // Saves the presentation return(new PresentationResult(presentation, "Chart.pptx", HttpContext.ApplicationInstance.Response)); }
private void btnCreatePresn_Click(object sender, EventArgs e) { //Creates a new instance of the presentation. using (IPresentation presentation = Presentation.Create()) { #region Slide1 //To add a slide to PowerPoint presentation ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); //To set the table title in a slide SetTableTitle(slide); //Get table data from xml file DataSet dataSet = new DataSet(); dataSet.ReadXml(@"Assets\Presentation\TableData.xml"); int columnCount = dataSet.Tables[0].Rows.Count + 1; int rowCount = dataSet.Tables.Count - 1; //To add a new table in slide. ITable table = slide.Shapes.AddTable(rowCount, columnCount, 61.92, 95.76, 856.8, 378.72); //To set the style for the table. table.BuiltInStyle = BuiltInTableStyle.MediumStyle2Accent6; //To set category title SetCategoryTitle(table); //Iterates and sets the values to the table cells. for (int rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++) { IRow row = table.Rows[rowIndex]; if (rowIndex == 0) { AddHeaderRow(row, dataSet.Tables[0].Rows); } else { AddCell(row, dataSet.Tables[rowIndex + 1]); } } #endregion //Saves the presentation presentation.Save("Tables.pptx"); if (System.Windows.MessageBox.Show("Do you want to view the generated Presentation?", "Presentation Created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Tables.pptx") { UseShellExecute = true }; process.Start(); } } }
public ActionResult ImportData(string Browser) { //Gets the path of the Database string path = ResolveApplicationDataPath("DataBase.mdb"); //Create a new instance of OleDbConnection OleDbConnection connection = new OleDbConnection(); //Sets the string to open a Database connection.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=" + path; //Opens the Database connection connection.Open(); //Get all the data from the Database OleDbCommand query = new OleDbCommand("select * from StockData", connection); //Create a new instance of OleDbDataAdapter OleDbDataAdapter adapter = new OleDbDataAdapter(query); //Create a new instance of DataSet DataSet dataSet = new DataSet(); //Adds rows in the Dataset adapter.Fill(dataSet); //Create a DataTable from the Dataset DataTable dataTable = dataSet.Tables[0]; //Create a new instance of Presentation IPresentation presentation = Presentation.Create(); //Set the number of rows to be present in the DataTable int RowsPerSlide = 5; List <DataTable> dataTables = SplitDataTable(dataTable, RowsPerSlide); int count = 1; //Export the data into the table of the Presentation foreach (DataTable splittedDataTable in dataTables) { //if the count of the splitted DataTable is equal to 1, then the data willl be imported as Table into the presentation if (count == 1) { ExportToPresentationSlide(presentation, splittedDataTable); } //if the count of the splitted DataTable is greater than 1, then the data willl be imported as Chart into the presentation else { CreateChartFromDatatable(presentation, splittedDataTable); } count++; } //Dispose all the resources connection.Close(); connection.Dispose(); query.Dispose(); adapter.Dispose(); dataSet.Dispose(); return(new PresentationResult(presentation, "Imported.pptx", HttpContext.ApplicationInstance.Response)); }
public IActionResult CreateSlide(string image, string header, string content) { WebClient webClient = new WebClient(); webClient.DownloadFile(image, "image.jpg"); //Create a new instance of PowerPoint Presentation file IPresentation pptxDoc = Presentation.Create(); //Add a new slide to file and apply background color ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.TitleOnly); //Specify the fill type and fill color for the slide background slide.Background.Fill.FillType = FillType.Solid; slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229); //Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide IShape titleShape = slide.Shapes[0] as IShape; titleShape.TextBody.AddParagraph(header).HorizontalAlignment = HorizontalAlignmentType.Center; //Add description content to the slide by adding a new TextBox IShape descriptionShape = slide.AddTextBox(53.22, 141.73, 874.19, 77.70); descriptionShape.TextBody.Text = content; //Gets a picture as stream. FileStream pictureStream = new FileStream("image.jpg", FileMode.Open); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16); //Save the PowerPoint Presentation as stream FileStream outputStream = new FileStream("Sample.pptx", FileMode.Create); pptxDoc.Save(outputStream); //Release all resources from stream outputStream.Dispose(); //Close the PowerPoint presentation pptxDoc.Close(); var displaySlide = new Result { Title = header, Content = content, Link = image }; return(View(displaySlide)); }
/// <summary> /// Creates a table in the presentation. /// </summary> private void ManipulateSample() { //Stream to save the created PowerPoint presnetation MemoryStream stream = new MemoryStream(); //Creates a new instance of the presentation. using (IPresentation presentation = Presentation.Create()) { #region Slide1 //To add a slide to PowerPoint presentation ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); //To set the table title in a slide SetTableTitle(slide); //To get the table data from an XML file Dictionary <string, Dictionary <string, string> > products = LoadXMLData(); int columnCount = products.Keys.Count + 1; int rowCount = products[products.Keys.ToArray()[0]].Count + 1; //To add a new table in slide. ITable table = slide.Shapes.AddTable(rowCount, columnCount, 61.92, 95.76, 856.8, 378.72); //To set the style for the table. table.BuiltInStyle = BuiltInTableStyle.MediumStyle2Accent6; //To set category title SetCategoryTitle(table); //Iterates and sets the values to the table cells. for (int rowIndex = 0; rowIndex < table.Rows.Count; rowIndex++) { IRow row = table.Rows[rowIndex]; Dictionary <string, string> months = products[products.Keys.ToArray()[0]]; string[] monthName = months.Keys.ToArray(); for (int cellIndex = 0; cellIndex < row.Cells.Count - 1; cellIndex++) { months = products[products.Keys.ToArray()[cellIndex]]; AddHeaderRowAndColumn(row, cellIndex, products.Keys.ToArray(), rowIndex, monthName); AddCellContent(row, rowIndex, monthName, months, cellIndex); } } #endregion //Save the presentation instance to the memory stream. presentation.Save(stream); } stream.Position = 0; if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("TablesSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("TablesSample.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", stream); } }
protected void Button1_Click(object sender, EventArgs e) { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.Left = 0.65 * 72; titleShape.Top = 0.24 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.45 * 72; titleShape.TextBody.AddParagraph("Ole Object"); titleShape.TextBody.Paragraphs[0].Font.Bold = true; titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Left; IShape heading = slide.Shapes.AddTextBox(100, 100, 100, 100); heading.Left = 0.84 * 72; heading.Top = 1.65 * 72; heading.Width = 2.23 * 72; heading.Height = 0.51 * 72; heading.TextBody.AddParagraph("MS Word Object"); heading.TextBody.Paragraphs[0].Font.Italic = true; heading.TextBody.Paragraphs[0].Font.Bold = true; heading.TextBody.Paragraphs[0].Font.FontSize = 18; //Get the word file as stream using (Stream wordStream = File.Open(ResolveApplicationDataPath("OleTemplate.docx"), FileMode.Open)) { //Image to be displayed, This can be any image using (Stream imageStream = File.Open(ResolveApplicationImagePath("OlePicture.png"), FileMode.Open)) { IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Word.Document.12", wordStream); //Set size and position of the ole object oleObject.Left = 4.53 * 72; oleObject.Top = 0.79 * 72; oleObject.Width = 4.26 * 72; oleObject.Height = 5.92 * 72; //Set DisplayAsIcon as true, to open the embedded document in separate (default) application. oleObject.DisplayAsIcon = true; //Saves the presentation presentation.Save("InsertOLEObject.pptx", FormatType.Pptx, Response); wordStream.Close(); imageStream.Close(); } } }
protected void Button1_Click(object sender, EventArgs e) { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.Left = 0.92 * 72; titleShape.Top = 0.4 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.01 * 72; titleShape.TextBody.AddParagraph("Ole Object Demo"); titleShape.TextBody.Paragraphs[0].Font.Bold = true; titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Center; IShape heading = slide.Shapes.AddTextBox(100, 100, 100, 100); heading.Left = 3.2 * 72; heading.Top = 1.51 * 72; heading.Width = 1.86 * 72; heading.Height = 0.71 * 72; heading.TextBody.AddParagraph("MS Excel Object"); heading.TextBody.Paragraphs[0].Font.Italic = true; heading.TextBody.Paragraphs[0].Font.Bold = true; heading.TextBody.Paragraphs[0].Font.FontSize = 18; //Get the excel file as stream using (Stream excelStream = File.Open(ResolveApplicationDataPath("OleTemplate.xlsx"), FileMode.Open)) { //Image to be displayed, This can be any image using (Stream imageStream = File.Open(ResolveApplicationImagePath("OlePicture.png"), FileMode.Open)) { IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Excel.Sheet.12", excelStream); //Set size and position of the ole object oleObject.Left = 3.29 * 72; oleObject.Top = 2.01 * 72; oleObject.Width = 6.94 * 72; oleObject.Height = 5.13 * 72; //Saves the presentation presentation.Save("InsertOLESample.pptx", FormatType.Pptx, Response); excelStream.Close(); imageStream.Close(); } } }
private void CreateInitialPPt() { String Title, TextDesc; Title = Title_txtBx.Text; TextDesc = Txt_Blk.Text; string today = DateTime.Now.ToShortDateString(); //Creates a new ppt doc IPresentation ppt_doc = Presentation.Create(); //Adding a initial slide to the ppt ISlide slide = ppt_doc.Slides.Add(SlideLayoutType.PictureWithCaption); //Specify the fill type and fill color for the slide background slide.Background.Fill.FillType = FillType.Solid; slide.Background.Fill.SolidFill.Color = ColorObject.FromArgb(232, 241, 229); //Add title content to the slide by accessing the title placeholder of the TitleOnly layout-slide IShape titleShape = slide.Shapes[0] as IShape; titleShape.TextBody.AddParagraph(Title).HorizontalAlignment = HorizontalAlignmentType.Center; //Adding a TextBox to the slide IShape shape = slide.AddTextBox(80, 200, 500, 100); shape.TextBody.AddParagraph(TextDesc); String imgName = GetImageName(); imgName = staticFilePath + imgName; //Gets a picture as stream. Stream pictureStream = File.Open(imgName, FileMode.Open); //Adds the picture to a slide by specifying its size and position. slide.Shapes.AddPicture(pictureStream, 499.79, 238.59, 364.54, 192.16); //Save the ppt ppt_doc.Save(Title + ".pptx"); //Dispose the image stream pictureStream.Dispose(); //closing the ppt ppt_doc.Close(); }
public ActionResult CreatingChart(string Browser) { IPresentation presentation = Presentation.Create(); ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IParagraph paragraph = ((IShape)slide.Shapes[0]).TextBody.Paragraphs.Add(); //Apply center alignment to the paragraph paragraph.HorizontalAlignment = HorizontalAlignmentType.Center; //Add slide title ITextPart textPart = paragraph.AddTextPart("Northwind Management Report"); textPart.Font.Color = ColorObject.FromArgb(46, 116, 181); //Get chart data from xml file DataSet dataSet = new DataSet(); //Load XML file string dataPath = ResolveApplicationDataPath("Products.xml"); dataSet.ReadXml(dataPath); //Add a new chart to the presentation slide IPresentationChart chart = slide.Charts.AddChart(44.64, 133.2, 870.48, 380.16); //Set chart type chart.ChartType = OfficeChartType.Pie; //Set chart title chart.ChartTitle = "Best Selling Products"; //Set chart properties font name and size chart.ChartTitleArea.FontName = "Calibri (Body)"; chart.ChartTitleArea.Size = 14; for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++) { chart.ChartData.SetValue(i + 2, 1, dataSet.Tables[0].Rows[i].ItemArray[1]); chart.ChartData.SetValue(i + 2, 2, dataSet.Tables[0].Rows[i].ItemArray[2]); } //Create a new chart series with the name �Sales� AddSeriesForChart(chart); //Setting the font size of the legend. chart.Legend.TextArea.Size = 14; //Setting background color chart.ChartArea.Fill.ForeColor = System.Drawing.Color.FromArgb(242, 242, 242); chart.PlotArea.Fill.ForeColor = System.Drawing.Color.FromArgb(242, 242, 242); chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 11, 1]; // Saves the presentation return(new PresentationResult(presentation, "Chart.pptx", HttpContext.ApplicationInstance.Response)); }
public ActionResult InsertOLEObject(string Browser) { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); ISlide slide = presentation.Slides.Add(SlideLayoutType.TitleOnly); IShape titleShape = slide.Shapes[0] as IShape; titleShape.Left = 0.92 * 72; titleShape.Top = 0.4 * 72; titleShape.Width = 11.5 * 72; titleShape.Height = 1.01 * 72; titleShape.TextBody.AddParagraph("Ole Object Demo"); titleShape.TextBody.Paragraphs[0].Font.Bold = true; titleShape.TextBody.Paragraphs[0].HorizontalAlignment = HorizontalAlignmentType.Center; IShape heading = slide.Shapes.AddTextBox(100, 100, 100, 100); heading.Left = 3.2 * 72; heading.Top = 1.51 * 72; heading.Width = 1.86 * 72; heading.Height = 0.71 * 72; heading.TextBody.AddParagraph("MS Excel Object"); heading.TextBody.Paragraphs[0].Font.Italic = true; heading.TextBody.Paragraphs[0].Font.Bold = true; heading.TextBody.Paragraphs[0].Font.FontSize = 18; string excelPath = "OleTemplate.xlsx"; //Get the excel file as stream Stream excelStream = new FileStream(ResolveApplicationDataPath(excelPath), FileMode.Open); string imagePath = "OlePicture.png"; //Image to be displayed, This can be any image Stream imageStream = new FileStream(ResolveApplicationImagePath(imagePath), FileMode.Open); IOleObject oleObject = slide.Shapes.AddOleObject(imageStream, "Excel.Sheet.12", excelStream); //Set size and position of the ole object oleObject.Left = 3.29 * 72; oleObject.Top = 2.01 * 72; oleObject.Width = 6.94 * 72; oleObject.Height = 5.13 * 72; return(new PresentationResult(presentation, "InsertOLEObject.pptx", HttpContext.ApplicationInstance.Response)); }
public ActionResult PresentationFeatures(string button) { if (button == null) { return(View()); } if (button == "Generate") { //New Instance of PowerPoint is Created.[Equivalent to launching MS PowerPoint with no slides]. IPresentation presentation = Presentation.Create(); //Method call to create slides CreateSlide101(presentation); CreateSlide201(presentation); CreateSlide301(presentation); CreateSlide401(presentation); return(new PresentationResult(presentation, "Slides.pptx", HttpContext.ApplicationInstance.Response)); } return(View()); }