private void OnButtonClicked(object sender, EventArgs e) { Assembly assembly = Assembly.GetExecutingAssembly(); //A new document is created. WordDocument document = new WordDocument(); //Add new section to the Word document IWSection section = document.AddSection(); //Set page margins of the section section.PageSetup.Margins.All = 72; //Add new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Apply heading style to the title paragraph paragraph.ApplyStyle(BuiltinStyle.Heading1); //Apply center alignment to the paragraph paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; //Append text to the paragraph paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); //Add new paragraph paragraph = section.AddParagraph(); //Get chart data from xml file List <ProductDetail> Products = LoadXMLData(); //Create and Append chart to the paragraph WChart pieChart = document.LastParagraph.AppendChart(446, 270); //Set chart data pieChart.ChartType = OfficeChartType.Pie; pieChart.ChartTitle = "Best Selling Products"; pieChart.ChartTitleArea.FontName = "Calibri (Body)"; pieChart.ChartTitleArea.Size = 14; for (int i = 0; i < Products.Count; i++) { ProductDetail product = Products[i]; pieChart.ChartData.SetValue(i + 2, 1, product.ProductName); pieChart.ChartData.SetValue(i + 2, 2, product.Sum); } //Create a new chart series with the name “Sales” IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales"); pieSeries.Values = pieChart.ChartData[2, 2, 11, 2]; //Setting data label pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Setting background color pieChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1]; MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2013); document.Close(); if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("PieChart.docx", "application/msword", stream, m_context); } }
/// <summary> /// Adds the series for the chart. /// </summary> /// <param name="chart">Represents the chart instance from the presentation.</param> private void AddSeriesForChart(IPresentationChart chart) { //Add a series for the chart. IOfficeChartSerie series = chart.Series.Add("Sales"); series.Values = chart.ChartData[2, 2, 11, 2]; //Setting data label series.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; series.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; series.DataPoints.DefaultDataPoint.DataLabels.Size = 14; }
private void Button_Click_1(object sender, RoutedEventArgs e) { Assembly execAssem = typeof(Common.MainPage).GetTypeInfo().Assembly; //A new document is created. WordDocument document = new WordDocument(); //Add new section to the Word document IWSection section = document.AddSection(); //Set page margins of the section section.PageSetup.Margins.All = 72; //Add new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Apply heading style to the title paragraph paragraph.ApplyStyle(BuiltinStyle.Heading1); //Apply center alignment to the paragraph paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Append text to the paragraph paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.DocIO.DLS.Color.FromArgb(46, 116, 181); //Add new paragraph paragraph = section.AddParagraph(); //Get chart data from xml file List <ProductDetail> Products = LoadXMLData(); //Create and Append chart to the paragraph WChart pieChart = document.LastParagraph.AppendChart(446, 270); //Set chart data pieChart.ChartType = OfficeChartType.Pie; pieChart.ChartTitle = "Best Selling Products"; pieChart.ChartTitleArea.FontName = "Calibri (Body)"; pieChart.ChartTitleArea.Size = 14; for (int i = 0; i < Products.Count; i++) { ProductDetail product = Products[i]; pieChart.ChartData.SetValue(i + 2, 1, product.ProductName); pieChart.ChartData.SetValue(i + 2, 2, product.Sum); } //Create a new chart series with the name “Sales” IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales"); pieSeries.Values = pieChart.ChartData[2, 2, 11, 2]; //Setting data label pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Setting background color pieChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1]; #region Saving Document MemoryStream ms = new MemoryStream(); SaveDocx(document); #endregion }
private void AddDataToCommonCharts(DataTable dataTable, ViewData viewData, IPresentationChart chart, string paName, int nRows) { chart.ChartType = GetChartType(viewData.ChartType); foreach (string item in viewData.SerieList ?? Enumerable.Empty <string>()) { IOfficeChartSerie serie = chart.Series.Add(item); int columnIndex = dataTable.Columns.IndexOf(item) + 1; serie.Values = chart.ChartData[2, columnIndex, nRows, columnIndex]; } var paCn = dataTable.Columns.IndexOf(paName) + 1; chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, paCn, nRows, paCn]; chart.Refresh(); }
/// <summary> /// Exports the tables and charts to the PowerPoint Slide /// </summary> /// <param name="presentation">The PowerPoint presnetation to export the charts and tables</param> /// <param name="dataTable">The table which has the data</param> private static void CreateChartFromDatatable(IPresentation pptxDoc, DataTable dataTable) { //Get the first slide in the PowerPoint presentation ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Create a chart and add to the slide IPresentationChart chart = slide.Charts.AddChart(100, 10, 700, 500); int rowIndex = 1; int colIndex = 1; //Add data to the table in presentation from the DataTable foreach (DataRow row in dataTable.Rows) { foreach (object val in row.ItemArray) { string value = val.ToString(); chart.ChartData.SetValue(rowIndex, colIndex, value); colIndex++; } colIndex = 1; rowIndex++; } //Creates a new chart series with the name IOfficeChartSerie openPrice = chart.Series.Add("Open Price"); //Sets the data range of chart series – start row, start column, end row, end column openPrice.Values = chart.ChartData[2, 2, 5, 2]; //Creates a new chart series with the name IOfficeChartSerie highPrice = chart.Series.Add("High Price"); //Sets the data range of chart series – start row, start column, end row, end column highPrice.Values = chart.ChartData[2, 3, 5, 3]; //Creates a new chart series with the name IOfficeChartSerie lowPrice = chart.Series.Add("Low Price"); //Sets the data range of chart series – start row, start column, end row, end column lowPrice.Values = chart.ChartData[2, 4, 5, 4]; //Sets the data range of the category axis chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 5, 1]; //Specifies the chart type chart.ChartType = OfficeChartType.Column_Clustered; //Set the title for the chart chart.ChartTitle = "Sales Report"; }
private void CreateLineAndBar(DataTable dataTable, ViewData viewData, IPresentationChart chart, int nRows) { //Serie1 IOfficeChartSerie serie1 = chart.Series.Add(viewData.SerieList[0]); int columnIndex = dataTable.Columns.IndexOf(viewData.SerieList[0]); serie1.Values = chart.ChartData[2, columnIndex, nRows, columnIndex]; serie1.SerieType = OfficeChartType.Column_Clustered; //Serie2 IOfficeChartSerie serie2 = chart.Series.Add(viewData.SerieList[1]); int columnIndex2 = dataTable.Columns.IndexOf(viewData.SerieList[1]); serie2.Values = chart.ChartData[2, columnIndex2, nRows, columnIndex2]; serie2.SerieType = OfficeChartType.Line; }
private void SlideWithComments2(IPresentation presentation) { xValue = 650; yValue = 90; ISlide slide2 = presentation.Slides.Add(SlideLayoutType.Blank); IPresentationChart chart = slide2.Shapes.AddChart(230, 80, 500, 400); //Specifies the chart title chart.ChartTitle = "Sales Analysis"; //Sets chart data - Row1 chart.ChartData.SetValue(1, 2, "Jan"); chart.ChartData.SetValue(1, 3, "Feb"); chart.ChartData.SetValue(1, 4, "March"); //Sets chart data - Row2 chart.ChartData.SetValue(2, 1, 2010); chart.ChartData.SetValue(2, 2, 60); chart.ChartData.SetValue(2, 3, 70); chart.ChartData.SetValue(2, 4, 80); //Sets chart data - Row3 chart.ChartData.SetValue(3, 1, 2011); chart.ChartData.SetValue(3, 2, 80); chart.ChartData.SetValue(3, 3, 70); chart.ChartData.SetValue(3, 4, 60); //Sets chart data - Row4 chart.ChartData.SetValue(4, 1, 2012); chart.ChartData.SetValue(4, 2, 60); chart.ChartData.SetValue(4, 3, 70); chart.ChartData.SetValue(4, 4, 80); //Creates a new chart series with the name IOfficeChartSerie serieJan = chart.Series.Add("Jan"); //Sets the data range of chart serie – start row, start column, end row, end column serieJan.Values = chart.ChartData[2, 2, 4, 2]; //Creates a new chart series with the name IOfficeChartSerie serieFeb = chart.Series.Add("Feb"); //Sets the data range of chart serie – start row, start column, end row, end column serieFeb.Values = chart.ChartData[2, 3, 4, 3]; //Creates a new chart series with the name IOfficeChartSerie serieMarch = chart.Series.Add("March"); //Sets the data range of chart series – start row, start column, end row, end column serieMarch.Values = chart.ChartData[2, 4, 4, 4]; //Sets the data range of the category axis chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 4, 1]; //Specifies the chart type chart.ChartType = OfficeChartType.Column_Clustered_3D; slide2.Comments.Add(xValue, yValue, "Author2", "A2", "Do all 3D-chart types support in Presentation library?", DateTime.Now); }
public ActionResult PieChart(string Group1) { if (Group1 == null) { return(View()); } string basePath = _hostingEnvironment.WebRootPath; string datapath = basePath + @"/DocIO/PieChart.docx"; //A new document is created. FileStream fileStream = new FileStream(datapath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); WordDocument document = new WordDocument(fileStream, FormatType.Docx); //Create MailMergeDataTable MailMergeDataTable mailMergeDataTable = GetMailMergeDataTableProductDetails(); //Merge the product table in the Word document document.MailMerge.ExecuteGroup(mailMergeDataTable); //Find the Placeholder of Pie chart to insert TextSelection selection = document.Find("<Pie Chart>", false, false); WParagraph paragraph = selection.GetAsOneRange().OwnerParagraph; paragraph.ChildEntities.Clear(); //Create and Append chart to the paragraph WChart pieChart = paragraph.AppendChart(446, 270); //Set chart data pieChart.ChartType = OfficeChartType.Pie; pieChart.ChartTitle = "Best Selling Products"; pieChart.ChartTitleArea.FontName = "Calibri (Body)"; pieChart.ChartTitleArea.Size = 14; GetChartData(pieChart, 0); //Create a new chart series with the name “Sales” IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales"); pieSeries.Values = pieChart.ChartData[2, 2, 11, 2]; //Setting data label pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Setting background color pieChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1]; string filename = ""; string contenttype = ""; MemoryStream ms = new MemoryStream(); #region Document SaveOption if (Group1 == "WordDocx") { filename = "Sample.docx"; contenttype = "application/msword"; document.Save(ms, FormatType.Docx); } else if (Group1 == "WordML") { filename = "Sample.xml"; contenttype = "application/msword"; document.Save(ms, FormatType.WordML); } else { filename = "Sample.pdf"; contenttype = "application/pdf"; DocIORenderer renderer = new DocIORenderer(); renderer.ConvertToPDF(document).Save(ms); } #endregion Document SaveOption document.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
private void OnButtonClicked(object sender, EventArgs e) { string resourcePath = ""; #if COMMONSB resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.Images.pptx"; #else resourcePath = "SampleBrowser.Presentation.Samples.Templates.Images.pptx"; #endif Assembly assembly = typeof(Comments).GetTypeInfo().Assembly; Stream fileStream = assembly.GetManifestResourceStream(resourcePath); IPresentation presentation = Syncfusion.Presentation.Presentation.Open(fileStream); #region Slide 1 ISlide slide1 = presentation.Slides[0]; IShape shape1 = (IShape)slide1.Shapes[0]; shape1.Left = 1.27 * 72; shape1.Top = 0.85 * 72; shape1.Width = 10.86 * 72; shape1.Height = 3.74 * 72; ITextBody textFrame = shape1.TextBody; IParagraphs paragraphs = textFrame.Paragraphs; paragraphs.Add(); IParagraph paragraph = paragraphs[0]; paragraph.HorizontalAlignment = HorizontalAlignmentType.Left; ITextParts textParts = paragraph.TextParts; textParts.Add(); ITextPart textPart = textParts[0]; textPart.Text = "Essential Presentation "; textPart.Font.CapsType = TextCapsType.All; textPart.Font.FontName = "Calibri Light (Headings)"; textPart.Font.FontSize = 80; textPart.Font.Color = ColorObject.Black; IComment comment = slide1.Comments.Add(0.35, 0.04, "Author1", "A1", "Essential Presentation is available from 13.1 versions of Essential Studio", DateTime.Now); #endregion #region Slide2 ISlide slide2 = presentation.Slides.Add(SlideLayoutType.Blank); IPresentationChart chart = slide2.Shapes.AddChart(230, 80, 500, 400); //Specifies the chart title chart.ChartTitle = "Sales Analysis"; //Sets chart data - Row1 chart.ChartData.SetValue(1, 2, "Jan"); chart.ChartData.SetValue(1, 3, "Feb"); chart.ChartData.SetValue(1, 4, "March"); //Sets chart data - Row2 chart.ChartData.SetValue(2, 1, 2010); chart.ChartData.SetValue(2, 2, 60); chart.ChartData.SetValue(2, 3, 70); chart.ChartData.SetValue(2, 4, 80); //Sets chart data - Row3 chart.ChartData.SetValue(3, 1, 2011); chart.ChartData.SetValue(3, 2, 80); chart.ChartData.SetValue(3, 3, 70); chart.ChartData.SetValue(3, 4, 60); //Sets chart data - Row4 chart.ChartData.SetValue(4, 1, 2012); chart.ChartData.SetValue(4, 2, 60); chart.ChartData.SetValue(4, 3, 70); chart.ChartData.SetValue(4, 4, 80); //Creates a new chart series with the name IOfficeChartSerie serieJan = chart.Series.Add("Jan"); //Sets the data range of chart serie – start row, start column, end row, end column serieJan.Values = chart.ChartData[2, 2, 4, 2]; //Creates a new chart series with the name IOfficeChartSerie serieFeb = chart.Series.Add("Feb"); //Sets the data range of chart serie – start row, start column, end row, end column serieFeb.Values = chart.ChartData[2, 3, 4, 3]; //Creates a new chart series with the name IOfficeChartSerie serieMarch = chart.Series.Add("March"); //Sets the data range of chart series – start row, start column, end row, end column serieMarch.Values = chart.ChartData[2, 4, 4, 4]; //Sets the data range of the category axis chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 4, 1]; //Specifies the chart type chart.ChartType = OfficeChartType.Column_Clustered_3D; slide2.Comments.Add(0.35, 0.04, "Author2", "A2", "All 3D-chart types are supported in Presentation library.", DateTime.Now); #endregion #region Slide3 ISlide slide3 = presentation.Slides.Add(SlideLayoutType.ContentWithCaption); slide3.Background.Fill.FillType = FillType.Solid; slide3.Background.Fill.SolidFill.Color = ColorObject.White; //Adds shape in slide IShape shape2 = (IShape)slide3.Shapes[0]; shape2.Left = 0.47 * 72; shape2.Top = 1.15 * 72; shape2.Width = 3.5 * 72; shape2.Height = 4.91 * 72; ITextBody textFrame1 = shape2.TextBody; //Instance to hold paragraphs in textframe IParagraphs paragraphs1 = textFrame1.Paragraphs; IParagraph paragraph1 = paragraphs1.Add(); paragraph1.HorizontalAlignment = HorizontalAlignmentType.Left; ITextPart textpart1 = paragraph1.AddTextPart(); textpart1.Text = "Lorem ipsum dolor sit amet, lacus amet amet ultricies. Quisque mi venenatis morbi libero, orci dis, mi ut et class porta, massa ligula magna enim, aliquam orci vestibulum tempus."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph2 = paragraphs1.Add(); paragraph2.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph2.AddTextPart(); textpart1.Text = "Turpis facilisis vitae consequat, cum a a, turpis dui consequat massa in dolor per, felis non amet."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph3 = paragraphs1.Add(); paragraph3.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph3.AddTextPart(); textpart1.Text = "Auctor eleifend in omnis elit vestibulum, donec non elementum tellus est mauris, id aliquam, at lacus, arcu pretium proin lacus dolor et. Eu tortor, vel ultrices amet dignissim mauris vehicula."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); IParagraph paragraph4 = paragraphs1.Add(); paragraph4.HorizontalAlignment = HorizontalAlignmentType.Left; textpart1 = paragraph4.AddTextPart(); textpart1.Text = "Lorem tortor neque, purus taciti quis id. Elementum integer orci accumsan minim phasellus vel."; textpart1.Font.Color = ColorObject.White; textpart1.Font.FontName = "Calibri (Body)"; textpart1.Font.FontSize = 15; paragraphs1.Add(); slide3.Shapes.RemoveAt(1); slide3.Shapes.RemoveAt(1); //Adds picture in the shape resourcePath = ""; #if COMMONSB resourcePath = "SampleBrowser.Samples.Presentation.Samples.Templates.tablet.jpg"; #else resourcePath = "SampleBrowser.Presentation.Samples.Templates.tablet.jpg"; #endif fileStream = assembly.GetManifestResourceStream(resourcePath); IPicture picture1 = slide3.Shapes.AddPicture(fileStream, 5.18 * 72, 1.15 * 72, 7.3 * 72, 5.31 * 72); fileStream.Dispose(); slide3.Comments.Add(0.14, 0.04, "Author3", "A3", "Can we use a different font family for this text?", DateTime.Now); #endregion MemoryStream memoryStream = new MemoryStream(); presentation.Save(memoryStream); presentation.Close(); memoryStream.Position = 0; if (Device.RuntimePlatform == Device.UWP) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("CommentsSamples.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", memoryStream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("CommentsSamples.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", memoryStream); } }
private void button1_Click(object sender, System.EventArgs e) { try { //Getting Data files path. string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\common\Data\DocIO\"; //A new document is created. WordDocument document = new WordDocument(dataPath + "PieChart.docx"); //Get chart data from xml file DataSet ds = new DataSet(); ds.ReadXml(dataPath + "Products.xml"); //Merge the product table in the Word document document.MailMerge.ExecuteGroup(ds.Tables["Product"]); //Find the Placeholder of Pie chart to insert TextSelection selection = document.Find("<Pie Chart>", false, false); WParagraph paragraph = selection.GetAsOneRange().OwnerParagraph; paragraph.ChildEntities.Clear(); //Create and Append chart to the paragraph WChart pieChart = paragraph.AppendChart(446, 270); //Set chart data pieChart.ChartType = OfficeChartType.Pie; pieChart.ChartTitle = "Best Selling Products"; pieChart.ChartTitleArea.FontName = "Calibri (Body)"; pieChart.ChartTitleArea.Size = 14; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { pieChart.ChartData.SetValue(i + 2, 1, ds.Tables[0].Rows[i].ItemArray[1]); pieChart.ChartData.SetValue(i + 2, 2, ds.Tables[0].Rows[i].ItemArray[2]); } //Create a new chart series with the name “Sales” IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales"); pieSeries.Values = pieChart.ChartData[2, 2, 11, 2]; //Setting data label pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Setting background color pieChart.ChartArea.Fill.ForeColor = Color.FromArgb(242, 242, 242); pieChart.PlotArea.Fill.ForeColor = Color.FromArgb(242, 242, 242); pieChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1]; //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
private void SlideWithNotes1(IPresentation presentation) { ISlide slide1 = presentation.Slides[0]; IShape shape1 = (IShape)slide1.Shapes[0]; shape1.Left = 1.27 * 72; shape1.Top = 0.56 * 72; shape1.Width = 9.55 * 72; shape1.Height = 5.4 * 72; ITextBody textFrame = shape1.TextBody; IParagraphs paragraphs = textFrame.Paragraphs; paragraphs.Add(); IParagraph paragraph = paragraphs[0]; paragraph.HorizontalAlignment = HorizontalAlignmentType.Left; ITextParts textParts = paragraph.TextParts; textParts.Add(); ITextPart textPart = textParts[0]; textPart.Text = "Essential Presentation "; textPart.Font.CapsType = TextCapsType.All; textPart.Font.FontName = "Calibri Light (Headings)"; textPart.Font.FontSize = 80; textPart.Font.Color = ColorObject.Black; //Adding Notes INotesSlide notesSlide = slide1.AddNotesSlide(); ITextPart notesTextPart = notesSlide.NotesTextBody.Paragraphs[0].TextParts.Add(); notesTextPart.Text = "The slide represents the title content of the presentation"; IPresentationChart chart = notesSlide.Shapes.AddChart(1.24 * 72, 5.71 * 72, 5 * 72, 3.33 * 72); //Specifies the chart title chart.ChartTitle = "Sales Analysis"; //Sets chart data - Row1 chart.ChartData.SetValue(1, 2, "Jan"); chart.ChartData.SetValue(1, 3, "Feb"); chart.ChartData.SetValue(1, 4, "March"); //Sets chart data - Row2 chart.ChartData.SetValue(2, 1, 2010); chart.ChartData.SetValue(2, 2, 60); chart.ChartData.SetValue(2, 3, 70); chart.ChartData.SetValue(2, 4, 80); //Sets chart data - Row3 chart.ChartData.SetValue(3, 1, 2011); chart.ChartData.SetValue(3, 2, 80); chart.ChartData.SetValue(3, 3, 70); chart.ChartData.SetValue(3, 4, 60); //Sets chart data - Row4 chart.ChartData.SetValue(4, 1, 2012); chart.ChartData.SetValue(4, 2, 60); chart.ChartData.SetValue(4, 3, 70); chart.ChartData.SetValue(4, 4, 80); //Creates a new chart series with the name IOfficeChartSerie serieJan = chart.Series.Add("Jan"); //Sets the data range of chart serie – start row, start column, end row, end column serieJan.Values = chart.ChartData[2, 2, 4, 2]; //Creates a new chart series with the name IOfficeChartSerie serieFeb = chart.Series.Add("Feb"); //Sets the data range of chart serie – start row, start column, end row, end column serieFeb.Values = chart.ChartData[2, 3, 4, 3]; //Creates a new chart series with the name IOfficeChartSerie serieMarch = chart.Series.Add("March"); //Sets the data range of chart series – start row, start column, end row, end column serieMarch.Values = chart.ChartData[2, 4, 4, 4]; //Sets the data range of the category axis chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 4, 1]; //Specifies the chart type chart.ChartType = OfficeChartType.Column_Clustered; chart.ChartTitle = "Chart inside Notes section"; }
public ActionResult PieChart(string Group1) { if (Group1 == null) { return(View()); } //A new document is created. WordDocument document = new WordDocument(ResolveApplicationDataPath("PieChart.docx", "App_Data\\DocIO")); //Get chart data from xml file DataSet ds = new DataSet(); ds.ReadXml(ResolveApplicationDataPath("Products.xml", "App_Data\\DocIO")); //Merge the product table in the Word document document.MailMerge.ExecuteGroup(ds.Tables["Product"]); //Find the Placeholder of Pie chart to insert TextSelection selection = document.Find("<Pie Chart>", false, false); WParagraph paragraph = selection.GetAsOneRange().OwnerParagraph; paragraph.ChildEntities.Clear(); //Create and Append chart to the paragraph WChart pieChart = paragraph.AppendChart(446, 270); //Set chart data pieChart.ChartType = OfficeChartType.Pie; pieChart.ChartTitle = "Best Selling Products"; pieChart.ChartTitleArea.FontName = "Calibri (Body)"; pieChart.ChartTitleArea.Size = 14; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { pieChart.ChartData.SetValue(i + 2, 1, ds.Tables[0].Rows[i].ItemArray[1]); pieChart.ChartData.SetValue(i + 2, 2, ds.Tables[0].Rows[i].ItemArray[2]); } //Create a new chart series with the name “Sales” IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales"); pieSeries.Values = pieChart.ChartData[2, 2, 11, 2]; //Setting data label pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsPercentage = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Setting background color pieChart.ChartArea.Fill.ForeColor = System.Drawing.Color.FromArgb(242, 242, 242); pieChart.PlotArea.Fill.ForeColor = System.Drawing.Color.FromArgb(242, 242, 242); pieChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1]; #region Document save option //Save as .docx format if (Group1 == "WordDocx") { return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(document.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } return(View()); #endregion Document save option }
private void SlideWithComments(IPresentation presentation) { #region Slide 1 ISlide slide1 = presentation.Slides[0]; IShape shape1 = (IShape)slide1.Shapes[0]; shape1.Left = 1.27 * 72; shape1.Top = 0.85 * 72; shape1.Width = 10.86 * 72; shape1.Height = 3.74 * 72; ITextBody textFrame = shape1.TextBody; IParagraphs paragraphs = textFrame.Paragraphs; paragraphs.Add(); IParagraph paragraph = paragraphs[0]; paragraph.HorizontalAlignment = HorizontalAlignmentType.Left; ITextParts textParts = paragraph.TextParts; textParts.Add(); ITextPart textPart = textParts[0]; textPart.Text = "Essential Presentation "; textPart.Font.CapsType = TextCapsType.All; textPart.Font.FontName = "Calibri Light (Headings)"; textPart.Font.FontSize = 80; textPart.Font.Color = ColorObject.Black; IComment comment = slide1.Comments.Add(0.5, 0.04, "Author1", "A1", "Essential Presentation is available from 13.1 versions of Essential Studio", DateTime.Now); //Author2 add reply to a parent comment slide1.Comments.Add("Author2", "A2", "Does it support rendering of slides as images or PDF?", DateTime.Now, comment); //Author1 add reply to a parent comment slide1.Comments.Add("Author1", "A1", "Yes, you may render slides as images and PDF.", DateTime.Now, comment); #endregion #region Slide2 ISlide slide2 = presentation.Slides.Add(SlideLayoutType.Blank); IPresentationChart chart = slide2.Shapes.AddChart(230, 80, 500, 400); //Specifies the chart title chart.ChartTitle = "Sales Analysis"; //Sets chart data - Row1 chart.ChartData.SetValue(1, 2, "Jan"); chart.ChartData.SetValue(1, 3, "Feb"); chart.ChartData.SetValue(1, 4, "March"); //Sets chart data - Row2 chart.ChartData.SetValue(2, 1, 2010); chart.ChartData.SetValue(2, 2, 60); chart.ChartData.SetValue(2, 3, 70); chart.ChartData.SetValue(2, 4, 80); //Sets chart data - Row3 chart.ChartData.SetValue(3, 1, 2011); chart.ChartData.SetValue(3, 2, 80); chart.ChartData.SetValue(3, 3, 70); chart.ChartData.SetValue(3, 4, 60); //Sets chart data - Row4 chart.ChartData.SetValue(4, 1, 2012); chart.ChartData.SetValue(4, 2, 60); chart.ChartData.SetValue(4, 3, 70); chart.ChartData.SetValue(4, 4, 80); //Creates a new chart series with the name IOfficeChartSerie serieJan = chart.Series.Add("Jan"); //Sets the data range of chart serie – start row, start column, end row, end column serieJan.Values = chart.ChartData[2, 2, 4, 2]; //Creates a new chart series with the name IOfficeChartSerie serieFeb = chart.Series.Add("Feb"); //Sets the data range of chart serie – start row, start column, end row, end column serieFeb.Values = chart.ChartData[2, 3, 4, 3]; //Creates a new chart series with the name IOfficeChartSerie serieMarch = chart.Series.Add("March"); //Sets the data range of chart series – start row, start column, end row, end column serieMarch.Values = chart.ChartData[2, 4, 4, 4]; //Sets the data range of the category axis chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 4, 1]; //Specifies the chart type chart.ChartType = OfficeChartType.Column_Clustered_3D; slide2.Comments.Add(0.35, 0.04, "Author2", "A2", "Do all 3D-chart types support in Presentation library?", DateTime.Now); #endregion }
/// <summary> /// Exports the Data as chart to the PowerPoint Slide /// </summary> /// <returns>Returns the generated presentation</returns> private IPresentation CreateChartFromGrid() { //Create a new instance of Presentation IPresentation presentation = Presentation.Open(ResolveApplicationDataPath("DataTemplate.pptx")); foreach (ISlide slide in presentation.Slides) { //Iterate each shape in the slide for (int i = 0; i < slide.Shapes.Count; i++) { //Retrieves the shape IShape shape = slide.Shapes[i] as IShape; //Removes the shape from the shape collection. slide.Shapes.Remove(shape); } } int slideIndex = 0; //Clone the slide ISlide clonedSlide = presentation.Slides[0].Clone(); //Iterate each data of the Grid foreach (PresentationData presentationData in PresentationData.presentationData) { if (slideIndex > 0) { presentation.Slides.Add(clonedSlide); } //Gets the slide of the presentation ISlide slide = slide = presentation.Slides[slideIndex]; //Adds chart to the slide with position and size IPresentationChart chart = slide.Charts.AddChart(100, 10, 700, 500); //Set the first row of the chart values chart.ChartData.SetValue(1, 2, "Jan"); chart.ChartData.SetValue(1, 3, "Feb"); chart.ChartData.SetValue(1, 4, "Mar"); chart.ChartData.SetValue(1, 5, "Apr"); chart.ChartData.SetValue(1, 6, "May"); //Initalize the row index int rowIndex = 2; int?[] array = new int?[] { presentationData.Year, presentationData.Jan, presentationData.Feb, presentationData.Mar, presentationData.Apr, presentationData.May }; for (int i = 0; i < array.Length; i++) { //Initialize the column index int columnIndex = i + 1; //Set the value for chart chart.ChartData.SetValue(rowIndex, columnIndex, array[i].Value); if (columnIndex == array.Length) { //Creates a new chart series with the name IOfficeChartSerie series = chart.Series.Add(array[0].Value.ToString()); //Sets the data range of chart series – start row, start column, end row, end column series.Values = chart.ChartData[2, 2, 2, 6]; //Sets the data range of the category axis chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[1, 2, 1, 6]; //Sets the type of the chart chart.ChartType = OfficeChartType.Pie; //Sets a value indicates wherher to fill style is visible or not chart.ChartArea.Fill.Visible = false; IOfficeChartFrameFormat chartPlotArea = chart.PlotArea; //Sets a value indicates wherher to fill style is visible or not chartPlotArea.Fill.Visible = false; //Specifies the chart title chart.ChartTitle = "Sales details of the year " + array[0].Value.ToString(); //Sets the legend position chart.Legend.Position = OfficeLegendPosition.Right; } } rowIndex++; slideIndex++; } return(presentation); }
/// <summary> /// Creates slides with chart. /// </summary> private static void CreateChart(IPresentation presentation) { //Adds a blank slide to the presentation. ISlide slide1 = presentation.Slides.Add(SlideLayoutType.Blank); //Adds a chart to the slide with position and size. IPresentationChart chart = slide1.Shapes.AddChart(1.93 * 72, 0.31 * 72, 9.48 * 72, 6.89 * 72); //Sets the data for chart– RowIndex, columnIndex and data. chart.ChartData.SetValue(1, 1, "Crescent City, CA"); chart.ChartData.SetValue(3, 2, "Precipitation,in."); chart.ChartData.SetValue(3, 3, "Temperature,deg.F"); chart.ChartData.SetValue(4, 1, "Jan"); chart.ChartData.SetValue(5, 1, "Feb"); chart.ChartData.SetValue(6, 1, "March"); chart.ChartData.SetValue(7, 1, "Apr"); chart.ChartData.SetValue(8, 1, "May"); chart.ChartData.SetValue(9, 1, "June"); chart.ChartData.SetValue(10, 1, "July"); chart.ChartData.SetValue(11, 1, "Aug"); chart.ChartData.SetValue(12, 1, "Sept"); chart.ChartData.SetValue(13, 1, "Oct"); chart.ChartData.SetValue(14, 1, "Nov"); chart.ChartData.SetValue(15, 1, "Dec"); chart.ChartData.SetValue(4, 2, 10.9); chart.ChartData.SetValue(5, 2, 8.9); chart.ChartData.SetValue(6, 2, 8.6); chart.ChartData.SetValue(7, 2, 4.8); chart.ChartData.SetValue(8, 2, 3.2); chart.ChartData.SetValue(9, 2, 1.4); chart.ChartData.SetValue(10, 2, 0.6); chart.ChartData.SetValue(11, 2, 0.7); chart.ChartData.SetValue(12, 2, 1.7); chart.ChartData.SetValue(13, 2, 5.4); chart.ChartData.SetValue(14, 2, 9.0); chart.ChartData.SetValue(15, 2, 10.4); chart.ChartData.SetValue(4, 3, 47.5); chart.ChartData.SetValue(5, 3, 48.7); chart.ChartData.SetValue(6, 3, 48.9); chart.ChartData.SetValue(7, 3, 50.2); chart.ChartData.SetValue(8, 3, 53.1); chart.ChartData.SetValue(9, 3, 56.3); chart.ChartData.SetValue(10, 3, 58.1); chart.ChartData.SetValue(11, 3, 59.0); chart.ChartData.SetValue(12, 3, 58.5); chart.ChartData.SetValue(13, 3, 55.4); chart.ChartData.SetValue(14, 3, 51.1); chart.ChartData.SetValue(15, 3, 47.8); //Sets the data range of chart series – start row, start column, end row, end column. chart.DataRange = chart.ChartData[3, 1, 15, 3]; //Sets the chart title and axis title. chart.ChartTitle = "Crescent City, CA"; chart.PrimaryValueAxis.Title = "Precipitation,in."; chart.PrimaryValueAxis.TitleArea.TextRotationAngle = 90; chart.PrimaryValueAxis.MaximumValue = 14.0; chart.PrimaryValueAxis.NumberFormat = "0.0"; #region Format Series //Formats the first serie. IOfficeChartSerie serieOne = chart.Series[0]; serieOne.Name = "Precipitation,in."; serieOne.SerieFormat.Fill.FillType = OfficeFillType.Gradient; serieOne.SerieFormat.Fill.TwoColorGradient(OfficeGradientStyle.Vertical, OfficeGradientVariants.ShadingVariants_2); serieOne.SerieFormat.Fill.GradientColorType = OfficeGradientColor.TwoColor; serieOne.SerieFormat.Fill.ForeColor = Color.Plum; //Shows value as data labels. serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; serieOne.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Formats the second serie. IOfficeChartSerie serieTwo = chart.Series[1]; serieTwo.SerieType = OfficeChartType.Line_Markers; serieTwo.Name = "Temperature,deg.F"; //Formats marker. serieTwo.SerieFormat.MarkerStyle = OfficeChartMarkerType.Diamond; serieTwo.SerieFormat.MarkerSize = 8; serieTwo.SerieFormat.MarkerBackgroundColor = Color.DarkGreen; serieTwo.SerieFormat.MarkerForegroundColor = Color.DarkGreen; serieTwo.SerieFormat.LineProperties.LineColor = Color.DarkGreen; //Uses Secondary Axis. serieTwo.UsePrimaryAxis = false; #endregion #region Set the Secondary Axis for Second Serie. //Displays secondary axis for the series. chart.SecondaryCategoryAxis.IsMaxCross = true; chart.SecondaryValueAxis.IsMaxCross = true; //Sets the title. chart.SecondaryValueAxis.Title = "Temperature,deg.F"; chart.SecondaryValueAxis.TitleArea.TextRotationAngle = 90; //Hides the secondary category axis. chart.SecondaryCategoryAxis.Border.LineColor = Color.Transparent; chart.SecondaryCategoryAxis.MajorTickMark = OfficeTickMark.TickMark_None; chart.SecondaryCategoryAxis.TickLabelPosition = OfficeTickLabelPosition.TickLabelPosition_None; #endregion #region Legend setting chart.Legend.Position = OfficeLegendPosition.Bottom; chart.Legend.IsVerticalLegend = false; #endregion }
private void CreatePieChart() { //Creating a new Word document using (WordDocument document = new WordDocument()) { #region Create Pie chart //Add new section to the Word document IWSection section = document.AddSection(); //Set page margins of the section section.PageSetup.Margins.All = 72; //Add new paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Apply heading style to the title paragraph paragraph.ApplyStyle(BuiltinStyle.Heading1); //Apply center alignment to the paragraph paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center; //Append text to the paragraph paragraph.AppendText("Northwind Management Report").CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); //Add new paragraph paragraph = section.AddParagraph(); //Get chart data from xml file List <ProductDetail> Products = LoadXMLData(); //Create and Append chart to the paragraph WChart pieChart = document.LastParagraph.AppendChart(446, 270); //Set chart data pieChart.ChartType = OfficeChartType.Pie; pieChart.ChartTitle = "Best Selling Products"; pieChart.ChartTitleArea.FontName = "Calibri (Body)"; pieChart.ChartTitleArea.Size = 14; for (int i = 0; i < Products.Count; i++) { ProductDetail product = Products[i]; pieChart.ChartData.SetValue(i + 2, 1, product.ProductName); pieChart.ChartData.SetValue(i + 2, 2, product.Sum); } //Create a new chart series with the name “Sales” IOfficeChartSerie pieSeries = pieChart.Series.Add("Sales"); pieSeries.Values = pieChart.ChartData[2, 2, 11, 2]; //Setting data label pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Position = OfficeDataLabelPosition.Outside; //Setting background color pieChart.ChartArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.PlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.FromArgb(242, 242, 242); pieChart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; pieChart.PrimaryCategoryAxis.CategoryLabels = pieChart.ChartData[2, 1, 11, 1]; #endregion #region Saving a document //Saves the word document to stream. MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Save file in the disk based on specfic OS if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>() .Save("PieChart.docx", "application/msword", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("PieChart.docx", "application/msword", stream); } #endregion } }