[英]How to open PowerPoint Presentation in New Tab in ASP.NET MVC C# project
I am working on an ASP.NET MVC application which have a some power point which I want to display it on new tab.我正在开发一个 ASP.NET MVC 应用程序,它有一个电源点,我想在新选项卡上显示它。
I had used openxml to read files but I don't know how to open it.我曾使用 openxml 读取文件,但我不知道如何打开它。
My code for reading the files:我读取文件的代码:
public ActionResult Index()
{
StringBuilder sb = new StringBuilder();
string file = Server.MapPath("~/PPTFiles/Test.pptx");
int numberOfSlides = CountSlides(file);
string slideText;
for (int i = 0; i < numberOfSlides; i++)
{
// Get slide text.
GetSlideIdAndText(out slideText, file, i);
sb.Append(slideText);
}
return View();
}
public static int CountSlides(string presentationFile)
{
using (PresentationDocument presentationDocument = PresentationDocument.Open(presentationFile, false))
{
return CountSlides(presentationDocument);
}
}
public static int CountSlides(PresentationDocument presentationDocument)
{
if (presentationDocument == null)
{
throw new ArgumentNullException("presentationDocument");
}
int slidesCount = 0;
PresentationPart presentationPart = presentationDocument.PresentationPart;
if (presentationPart != null)
{
slidesCount = presentationPart.SlideParts.Count();
}
return slidesCount;
}
public static void GetSlideIdAndText(out string slideText, string docName, int index)
{
using (PresentationDocument ppt = PresentationDocument.Open(docName, false))
{
PresentationPart part = ppt.PresentationPart;
OpenXmlElementList slideIds = part.Presentation.SlideIdList.ChildElements;
string relId = (slideIds[index] as SlideId).RelationshipId;
SlidePart slide = (SlidePart)part.GetPartById(relId);
StringBuilder paragraphText = new StringBuilder();
IEnumerable<A.Text> texts = slide.Slide.Descendants<A.Text>();
foreach (A.Text text in texts)
{
paragraphText.Append(text.Text);
}
slideText = paragraphText.ToString();
}
}
Can you please help me with this?你能帮我解决这个问题吗?
You can't open pptx file in a browser.您无法在浏览器中打开 pptx 文件。 You should put your.pptx file in a directory on server.
您应该将您的 .pptx 文件放在服务器上的目录中。 And link it to a button.
并将其链接到一个按钮。 When User Clicks on button.
当用户单击按钮时。 It Will open.
它会打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.