简体   繁体   English

如何在 ASP.NET MVC C# 项目的新选项卡中打开 PowerPoint 演示文稿

[英]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.

相关问题 如何在新选项卡或窗口中打开PDF文件,而不是使用C#和ASP.NET MVC下载它? - How to open PDF file in a new tab or window instead of downloading it using C# and ASP.NET MVC? asp.net:如何使用c#在新窗口(不是标签页或当前页面)中打开新的asp.net页 - asp.net: How to open a new asp.net page in new window (not tab or current page) using c# 如何通过单击asp.net c#中的链接按钮来打开带有会话的新标签? - how to open a new tab with session by clicking link button in asp.net c#? 如何使用asp.net C#在Chrome的新标签页中打开打开的PDF - How to itextsharp PDF open in new tab in chrome using asp.net c# 如何在ASP.NET C#中的新选项卡(NOT WINDOW)中打开页面? - How to open page in new Tab (NOT WINDOW) in ASP.NET C#? 如何在ASP.NET C#中使用GridView行命令在浏览器的新选项卡中打开PDF文件 - How To Open PDF Files In New Tab In Browser Using GridView Row Command In ASP.NET C# 如何在c#asp.net MVC中提示打开文件 - How to prompt to open a file in c# asp.net mvc 如何在ASP.NET MVC C#项目中插入脚本 - How to insert scripts in an asp.net mvc c# project ASP.NET MVC - 在新标签上有条件地打开PDF /图像 - ASP.NET MVC - Conditionally open PDF/Image on new Tab 在asp.net Webform中显示PowerPoint演示文稿? - Display powerpoint presentation in asp.net webform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM