Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net的powerpoint中显示次y轴和线系列_C#_Asp.net_Powerpoint - Fatal编程技术网

C# 如何在asp.net的powerpoint中显示次y轴和线系列

C# 如何在asp.net的powerpoint中显示次y轴和线系列,c#,asp.net,powerpoint,C#,Asp.net,Powerpoint,我对使用asp.net将图表和网格导出到ppt感到惊讶。在下面的代码中,我可以显示图表,但不能显示网格。我的图表由两个条形系列和两个线条系列组成,我无法显示,线条系列应与辅助y轴(右侧)绑定。在这里我提供我的代码,所以任何修改或任何示例代码都非常感谢。这是使用Microsoft.Office.Interop.PowerPoint开发的 在代码下面的aspx.cs页面中 try { bool bAssistantOn; Micr

我对使用asp.net将图表和网格导出到ppt感到惊讶。在下面的代码中,我可以显示图表,但不能显示网格。我的图表由两个条形系列和两个线条系列组成,我无法显示,线条系列应与辅助y轴(右侧)绑定。在这里我提供我的代码,所以任何修改或任何示例代码都非常感谢。这是使用Microsoft.Office.Interop.PowerPoint开发的

在代码下面的aspx.cs页面中

   try
        {
            bool bAssistantOn;
            Microsoft.Office.Interop.PowerPoint.Application objApp;
            Presentations objPresSet;
            _Presentation objPres;
            Slides objSlides;
            _Slide objSlide;
            TextRange objTextRng;
            Microsoft.Office.Interop.PowerPoint.Shapes objShapes;
            Microsoft.Office.Interop.PowerPoint.Shape objShape;
            SlideShowWindows objSSWs;
            SlideShowTransition objSST;
            SlideShowSettings objSSS;
            Microsoft.Office.Interop.PowerPoint.SlideRange objSldRng;
            Microsoft.Office.Interop.Graph.Chart objChart;
            Microsoft.Office.Interop.Graph.DataSheet dataSheet;

            //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(@"D:\Template.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
            //.potx file is the template file of powerpoint.
            //Take a template file remove all it's slides and save it.
            //Then give it's physical path instead of it.
            objSlides = objPres.Slides;

            //Build Slide #1
            //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.
            objSlide = objSlides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
            objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
            objTextRng.Text = "My Chart";
            objTextRng.Font.Name = "Comic Sans MS";
            objTextRng.Font.Size = 48;

            objChart = (Microsoft.Office.Interop.Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320, "MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse).OLEFormat.Object;
            dataSheet = objChart.Application.DataSheet;

            // objChart.Legend.LegendEntries();
            //objChart.Axes(Microsoft.Office.Interop.Graph.XlAxisType.xlValue, Microsoft.Office.Interop.Graph.XlAxisGroup.xlSecondary);

            for (int i = 1; i < ds.Tables[0].Rows.Count + 1; i++)
            {
                if (i == 1)
                {
                    for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                        dataSheet.Cells[i, j + 1] = ds.Tables[0].Rows[j]["ProductGroup"];// x-axis values
                }
                else if (i == 2)
                {
                    //objChart.ChartType = Microsoft.Office.Interop.Graph.XlChartType.xlBarOfPie;

                    dataSheet.Cells[i, 1] = "ActualsQTD"; // Legend 1
                    for (int j = 1; j <= ds.Tables[0].Rows.Count; j++)
                    {
                        dataSheet.Cells[i, j + 1] = Convert.ToInt32(ds.Tables[0].Rows[j - 1]["ActualsQTD"])/1000;
                    }
                }
                else if (i == 3)
                {
                    //objChart.ChartType = Microsoft.Office.Interop.Graph.XlChartType.xlBarOfPie;

                    dataSheet.Cells[i, 1] = "ForecastQTD"; // Legend 2
                    for (int j = 1; j <= ds.Tables[0].Rows.Count; j++)
                    {
                        dataSheet.Cells[i, j + 1] = Convert.ToInt32(ds.Tables[0].Rows[j - 1]["ForecastQTD"])/1000;
                    }
                }
                else if (i == 4)
                {
                    //objChart.ChartType = Microsoft.Office.Interop.Graph.XlChartType.xlLine;

                    dataSheet.Cells[i, 1] = "QTDRatio"; // Legend 3
                    for (int j = 1; j <= ds.Tables[0].Rows.Count; j++)
                    {
                        dataSheet.Cells[i, j + 1] = ds.Tables[0].Rows[j-1]["QTDRatio"];
                    }
                }
                else if (i == 5)
                {
                    //objChart.ChartType = Microsoft.Office.Interop.Graph.XlChartType.xlLine;

                    dataSheet.Cells[i, 1] = "Target Attain"; // Legend 4
                    for (int j = 1; j <= ds.Tables[0].Rows.Count; j++)
                    {
                        dataSheet.Cells[i, j + 1] = ds.Tables[0].Rows[j-1]["Target Attain"];
                    }
                }

                objChart.Application.Update();
            }
            //objChart.ChartType = Microsoft.Office.Interop.Graph.XlChartType.xlLine; //changing the graph type : by default pie chart
            objChart.SeriesCollection(2);
            objChart.Legend.Position = Microsoft.Office.Interop.Graph.XlLegendPosition.xlLegendPositionBottom;
            objChart.HasTitle = true;
            objChart.ChartTitle.Text = "Chart";

            ///Build Slide #2:
            ///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.
            objSlide = objSlides.Add(2, PpSlideLayout.ppLayoutBlank);
            objSlide.FollowMasterBackground = MsoTriState.msoFalse;
            objShapes = objSlide.Shapes;
            objShape = objShapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect27, "The End", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200);

            //Modify the slide show transition settings for all slides in
            //the presentation.
            int[] SlideIdx = new int[2];
            for (int i = 0; i < 2; i++) SlideIdx[i] = i + 1;
            objSldRng = objSlides.Range(SlideIdx);
            objSST = objSldRng.SlideShowTransition;
            objSST.AdvanceOnTime = MsoTriState.msoTrue;
            objSST.AdvanceTime = 3;
            objSST.EntryEffect = PpEntryEffect.ppEffectBoxOut;

            //Prevent Office Assistant from displaying alert messages:
            ////bAssistantOn = objApp.Assistant.On;
            ////objApp.Assistant.On = false;

            //Run the Slide show
            //objSSS = objPres.SlideShowSettings;
            //objSSS.StartingSlide = 1;
            //objSSS.EndingSlide = 2;![enter image description here][1]
            //objSSS.Run();

            //Wait for the slide show to end.
            ////objSSWs = objApp.SlideShowWindows;
            ////while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);

            //Reenable Office Assisant, if it was on:
            ////if (bAssistantOn)
            ////{
            ////    objApp.Assistant.On = true;
            ////    objApp.Assistant.Visible = false;
            ////}

            //Close the presentation without saving changes and quit PowerPoint.
            objPres.SaveAs(@"D:\Sample", PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);
            //"D:\Sample" is the location where the ppt will be saved.
            objPres.Close();
            objApp.Quit();
        }
        catch (Exception ex)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            sb.Append("<script type = 'text/javascript'>");

            sb.Append("window.onload=function(){");

            sb.Append("alert('");

            sb.Append(ex.Message);

            sb.Append("')};");

            sb.Append("</script>");

            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString());

       }
试试看
{
布尔·巴斯坦顿;
Microsoft.Office.Interop.PowerPoint.Application objApp;
陈述对象;
_陈述对象;
玻片;小玻片;
_滑片;
textrangeobjtexting;
Microsoft.Office.Interop.PowerPoint.Shapes对象形状;
Microsoft.Office.Interop.PowerPoint.Shape objShape;
幻灯片窗口objSSWs;
幻灯片显示过渡对象;
幻灯片设置objSSS;
Microsoft.Office.Interop.PowerPoint.SlideRange objSldRng;
Microsoft.Office.Interop.Graph.Chart objChart;
Microsoft.Office.Interop.Graph.DataSheet数据表;
//基于模板创建新的演示文稿。
objApp=新的Microsoft.Office.Interop.PowerPoint.Application();
objApp.Visible=MsoTriState.msoTrue;
objpress=objApp.Presentations;
objPres=objpress.Open(@“D:\Template.pptx”、MsoTriState.msoFalse、MsoTriState.msoTrue、MsoTriState.msoTrue);
//.potx文件是powerpoint的模板文件。
//获取模板文件,删除所有幻灯片并保存。
//然后给出它的物理路径,而不是它。
objSlides=objPres.幻灯片;
//构建幻灯片#1
//将文本添加到幻灯片标题,设置文本格式。同时将图表添加到幻灯片标题
//滑动并将图表类型更改为三维饼图。
objSlide=objSlides.Add(1,Microsoft.Office.Interop.PowerPoint.PpSlideLayout.pplayouttonly);
objTextRng=objSlide.Shapes[1].TextFrame.TextRange;
Text=“我的图表”;
objTextRng.Font.Name=“Comic Sans MS”;
objTextRng.Font.Size=48;
objChart=(Microsoft.Office.Interop.Graph.Chart)objSlide.Shapes.AddOLEObject(150150480320,“MSGraph.Chart.8”,“MsoTriState.msoFalse”,“0”,“MsoTriState.msoFalse”).OLEFormat.Object;
数据表=objChart.Application.dataSheet;
//objChart.Legend.LegendEntries();
//objChart.Axes(Microsoft.Office.Interop.Graph.XlAxisType.xlValue,Microsoft.Office.Interop.Graph.XlAxisGroup.xlSecondary);
对于(int i=1;i