出口MS ChartImage的PPT在asp.net [英] Export MS ChartImage to PPT in asp.net

查看:100
本文介绍了出口MS ChartImage的PPT在asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图图图像​​导出到PPT即在一个幻灯片每个图像,下面是我的code

i am trying to Export Chart images to PPT i.e each image in one slide, below is my code

 String strTemplate, strPic;
            strTemplate = "C:\\Program Files (x86)\\Microsoft Office\\Templates\\Presentation Designs\\Maple.GIF";

            //strPic = @"C:\Users\rongala.ganesh\Pictures\arrow_left_green_large.png";

            bool bAssistantOn;

            Microsoft.Office.Interop.PowerPoint.Application objApp;
            Microsoft.Office.Interop.PowerPoint.Presentations objPresSet;
            Microsoft.Office.Interop.PowerPoint._Presentation objPres;
            Microsoft.Office.Interop.PowerPoint.Slides objSlides;
            Microsoft.Office.Interop.PowerPoint._Slide objSlide;
            Microsoft.Office.Interop.PowerPoint.TextRange objTextRng;
            Microsoft.Office.Interop.PowerPoint.Shapes objShapes;
            Microsoft.Office.Interop.PowerPoint.Shape objShape;
            Microsoft.Office.Interop.PowerPoint.SlideShowWindows objSSWs;
            Microsoft.Office.Interop.PowerPoint.SlideShowTransition objSST;
            Microsoft.Office.Interop.PowerPoint.SlideShowSettings objSSS;
            Microsoft.Office.Interop.PowerPoint.SlideRange objSldRng;
            //Create a new presentation based on a template.
            objApp = new Microsoft.Office.Interop.PowerPoint.Application();
            objApp.Visible = MsoTriState.msoTrue;
            objPresSet = objApp.Presentations;
            objPres = objPresSet.Open(strTemplate,
                 MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
            objSlides = objPres.Slides;
            //Build Slide #1:
            //Add text to the slide, change the font and insert/position a
            //picture on the first slide.
            objSlide = objSlides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
            objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
            // objTextRng.Text = "FAME Presentation";
            objTextRng.Font.Name = "Comic Sans MS";
            objTextRng.Font.Size = 25;
            foreach (var ar in arr)
            {
                // ScriptManager.RegisterClientScriptBlock(this.Page,typeof(string),"alert"
                objSlide = objSlides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
                objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
                // objTextRng.Text = "FAME Presentation";
                objTextRng.Font.Name = "Comic Sans MS";
                objTextRng.Font.Size = 25;
                string[] str = (string[])ar;
                strPic = str[0];
                objSlide.Shapes.AddPicture(strPic, MsoTriState.msoFalse, MsoTriState.msoTrue,
                      150, 150, 500, 350);
                objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
                objTextRng.Text = str[1];
                objTextRng.Font.Name = "Comic Sans MS";
                objTextRng.Font.Size = 48;

                //Build Slide #2:
                //Add text to the slide title, format the text. Also add a chart to the
                //slide and change the chart type to a 3D pie chart.

                //Build Slide #3:
                //Change the background color of this slide only. Add a text effect to the slide
                //and apply various color schemes and shadows to the text effect.
            }



        }
        catch (Exception ex)
        {

            throw ex;
        }

当我运行这一点,每一件事情是工作在本地主机很好,但是当我举办这个appilcaion IIS7它抛出异常PowerPoint无法打开的文件。
所以我的想法是最好添加响应头,于是我也跟着下面的code

when i Run this, every thing is working fine in localHost, but when i host this appilcaion IIS7 it Throwing exception PowerPoint could not open file. so what i thought is better to add Response Header, so i followed the below code

// dt是数据表名称这containt,图片的路径保存当我点击SaveImage

// dt is the DataTable Name which containt, path of Images saved when i click on SaveImage

 GridView1.AllowPaging = false;

            GridView1.DataSource = dt;
            GridView1.DataBind();////////write this code only if paging is enabled.

            Response.Clear();

            Response.AddHeader("content-disposition", "attachment;filename=FileName.ppt");///////for text file write FileName.txt

            Response.Charset = "";
            // If you want the option to open the Excel file without saving than

            // comment out the line below
            // Response.Cache.SetCacheability(HttpCacheability.NoCache);

            Response.ContentType = "application/vnd.ppt";//for text file write vnd.txt



            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite =

            new HtmlTextWriter(stringWrite);
            GridView1.RenderControl(htmlWrite);

            Response.Write(stringWrite.ToString());

            Response.End();

在这里,我可以添加图像PPT,但他们在同一个幻灯片和图像相互重叠。

here i can add Images to PPT, but they are in same slide,and the images are overlapping each other.

任何一个可以帮助我,有急事请。

any one help me it's Urgent please.

推荐答案

服务器(如ASP.NET)不是由MS支持使用互操作 - 看到的 http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Using Interop on the server (like ASP.NET) is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

由于Windows Vista中引入MS几个与安全相关的措施,prevent Windows服务从做桌面式的东西......这意味着你将不得不绕过几个保安措施,以得到它的工作(不推荐!)。

Since Windows Vista MS introduced several security-related measures which prevent a Windows Service from doing "desktop-like" things... which means you would have to circumvent several security measures to get it to work (NOT recommended!).

要处理的PPT在服务器方案中有一些选项(免费的和商业)那里:

To deal with PPT in a server-scenario there are some options (free and commercial) out there:

有一个自由选择(尽管较新的PPTX格式只!)例如的 2的OpenXML从MS 的。

A free option (though for the newer pptx format only!) is for example OpenXML 2 from MS.

一个商业的选择是 Aspose.Slides 它可以处理旧的(PPT )和新(PPTX)格式。

A commercial option is Aspose.Slides which can handle old (PPT) and new (PPTX) format.

这篇关于出口MS ChartImage的PPT在asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆