2014-10-06 3 views
1

나는 실버 라이트 어플리케이션에서 Datagrid을 가지고 있고 데이터를 파워 포인트로 내보내고 싶습니다.파워 포인트에서 OpenXML을 사용하여 테이블 만들기

이미지 (화면 캡처)를 파워 포인트로 내보내려면 링크 만 조사하고 발견했습니다. 내 시나리오에서는 20 열이있는 스크롤 막대가 있고 위의 해결 방법으로 표시되지 않기 때문에 화면 캡처도 작동하지 않습니다.

이 시나리오의 모든 문제를 해결하십시오.

P .: 타사 컨트롤을 사용하지 않으려합니다.

편집 :

지금의 OpenXML을 사용하는 것을 시도했다, 그러나 나는 다음과 같은 오류를 얻고있다 : 내 코드는 다음과 같습니다 enter image description here

:

  using A = DocumentFormat.OpenXml.Drawing; 
     using P14 = DocumentFormat.OpenXml.Office2010.PowerPoint; 
     using System; 
     using System.Collections.Generic; 
     using System.Linq; 
     using System.Text; 
     using DocumentFormat.OpenXml; 

     using DocumentFormat.OpenXml.Packaging; 
     using DocumentFormat.OpenXml.Presentation; 
     using P = DocumentFormat.OpenXml.Presentation; 
     using D = DocumentFormat.OpenXml.Drawing; 
     using DocumentFormat.OpenXml.Drawing; 

     public static void CreateTableInLastSlide(PresentationDocument presentationDocument) 
    { 
     // Get the presentation Part of the presentation document 
     PresentationPart presentationPart = presentationDocument.PresentationPart; 

     // Get the Slide Id collection of the presentation document 
     var slideIdList = presentationPart.Presentation.SlideIdList; 

     if (slideIdList == null) 
     { 
      throw new NullReferenceException("The number of slide is empty, please select a ppt with a slide at least again"); 
     } 

     // Get all Slide Part of the presentation document 
     var list = slideIdList.ChildElements 
        .Cast<SlideId>() 
        .Select(x => presentationPart.GetPartById(x.RelationshipId)) 
        .Cast<SlidePart>(); 

     // Get the last Slide Part of the presentation document 
     var tableSlidePart = (SlidePart)list.Last(); 

     // Declare and instantiate the graphic Frame of the new slide 

     P.GraphicFrame graphicFrame = tableSlidePart.Slide.CommonSlideData.ShapeTree.AppendChild(new P.GraphicFrame()); 

     ApplicationNonVisualDrawingPropertiesExtension applicationNonVisualDrawingPropertiesExtension = new ApplicationNonVisualDrawingPropertiesExtension(); 
     P14.ModificationId modificationId1 = new P14.ModificationId() { Val = 3229994563U }; 
     modificationId1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main"); 
     applicationNonVisualDrawingPropertiesExtension.Append(modificationId1); 
     graphicFrame.NonVisualGraphicFrameProperties = new DocumentFormat.OpenXml.Presentation.NonVisualGraphicFrameProperties 
     (new A.NonVisualDrawingProperties() { Id = 5, Name = "table 1" }, 
     new A.NonVisualGraphicFrameDrawingProperties(new A.GraphicFrameLocks() { NoGrouping = true }), 
     new ApplicationNonVisualDrawingProperties(new ApplicationNonVisualDrawingPropertiesExtensionList(applicationNonVisualDrawingPropertiesExtension))); 

     graphicFrame.Transform = new Transform(new Offset() { X = 10, Y = 10 }); 
     graphicFrame.Graphic = new A.Graphic(new A.GraphicData(GenerateTable()) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/table" }); 
     presentationPart.Presentation.Save(); 

    } 


    private static A.Table GenerateTable() 
    { 
     string[,] tableSources = new string[,] { { "name", "age" }, { "Tom", "25" } }; 

     // Declare and instantiate table 
     A.Table table = new A.Table(); 

     // Specify the required table properties for the table 
     A.TableProperties tableProperties = new A.TableProperties() { FirstRow = true, BandRow = true }; 
     A.TableStyleId tableStyleId = new A.TableStyleId(); 
     tableStyleId.Text = "{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}"; 

     tableProperties.Append(tableStyleId); 

     // Declare and instantiate tablegrid and colums 
     A.TableGrid tableGrid1 = new A.TableGrid(); 
     A.GridColumn gridColumn1 = new A.GridColumn() { Width = 3048000L }; 
     A.GridColumn gridColumn2 = new A.GridColumn() { Width = 3048000L }; 

     tableGrid1.Append(gridColumn1); 
     tableGrid1.Append(gridColumn2); 
     table.Append(tableProperties); 
     table.Append(tableGrid1); 
     for (int row = 0; row < tableSources.GetLength(0); row++) 
     { 
      // Instantiate the table row 
      A.TableRow tableRow = new A.TableRow() { Height = 370840L }; 
      for (int column = 0; column < tableSources.GetLength(1); column++) 
      { 
       tableRow.Append(CreateTextCell(tableSources.GetValue(row, column).ToString())); 
      } 

      table.Append(tableRow); 
     } 

     return table; 
    } 

내가 사용하고 올바른 그래픽과 변환 ?? 나에 따라 문제를 일으키는 라인은 다음과 같습니다 내가 자신의 라인을 주석

P.GraphicFrame graphicFrame = tableSlidePart.Slide.CommonSlideData.ShapeTree.AppendChild(new P.GraphicFrame()); 

것 같은 오류를 얻을 해달라고,하지만 나도 테이블을받을 수 있나요 : O/ 어떤 도움을?

+0

아이디어 : 당신이 office.interop 서버에 설치 한 경우에는 취득하기위한 웹 메소드를 만들 수 있습니다/데이터를 수락하고 PP 파일을 만듭니다. MS 오피스가 제 3 자라고 생각하십니까? – Steve

+0

아니요, 제 의도는 MS Office만을 사용하는 것입니다. 고마워. 나는 그것을 시도해 줄 것이다 !!! – adityaswami89

답변

0

마지막으로 Open XML 생산성 도구 (here)를 사용하여 문제를 해결할 수있었습니다. 강조 표시된 선은 오류였습니다. 나는 아래의 코드를 추가하는 데 필요한 :

List<OpenXmlElement> elements = new List<OpenXmlElement>(); 
     elements.Add(new P.NonVisualGraphicFrameProperties 
      (new P.NonVisualDrawingProperties() { Id = 1, Name = "xyz" }, new P.NonVisualGraphicFrameDrawingProperties(),new ApplicationNonVisualDrawingProperties())); 



     P.GraphicFrame graphicFrame = tableSlidePart.Slide.CommonSlideData.ShapeTree.AppendChild(new P.GraphicFrame(elements)); 

따라서 나는 오류 :없이 출력을 얻을 수 있었다

+0

안녕하세요, Aditya, PPTX 보고서의 표 형식으로 데이터 집합의 데이터를 추가해야합니다. 4 개의 다른 데이터 테이블을 채울 필요가있는 4 개의 자리 표시자가있는 템플릿이 있습니다. 현재이 템플릿을 사용하여 새로운 슬라이드를 만들고 텍스트의 자리 표시자를 대체하지만 테이블을 찾을 수는 없습니다. 테이블을 생성 할 수 있지만 자리 표시 자의 위치는 생성 할 수 없습니다. 너 내게 알려주시겠습니까? 감사 – Sak

관련 문제