aspnet-ej1-demos/Presentation/Comments.aspx.cs

179 строки
6.0 KiB
C#

#region Copyright Syncfusion Inc. 2001 - 2022
// Copyright Syncfusion Inc. 2001 - 2022. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using Syncfusion.Presentation;
using Syncfusion.OfficeChart;
namespace WebSampleBrowser.PPTX
{
public partial class Comments : System.Web.UI.Page
{
# region Page Load
/// <summary>
/// Handles page load
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
}
# endregion
# region Events
/// <summary>
/// Creates Presentation
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnCreateDocuments_Click(object sender, EventArgs e)
{
Stream file1 = new FileStream(ResolveApplicationDataPath("Images.pptx"), FileMode.Open, FileAccess.Read, FileShare.Read);
IPresentation presentation = Presentation.Open(file1);
SlideWithComments(presentation);
presentation.Save("Sample.pptx", FormatType.Pptx, Response);
file1.Close();
}
#endregion
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(410, 60, "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(650, 90, "Author2", "A2", "Do all 3D-chart types support in Presentation library?", DateTime.Now);
#endregion
}
protected string ResolveApplicationDataPath(string fileName)
{
string dataPath = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\App_Data\\Presentation").FullName;
return string.Format("{0}\\{1}", dataPath, fileName);
}
protected string ResolveApplicationImagePath(string fileName)
{
string dataPath = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\Content\\Presentation").FullName;
return string.Format("{0}\\{1}", dataPath, fileName);
}
}
}