나는 실버 라이트 어플리케이션에서 Datagrid을 가지고 있고 데이터를 파워 포인트로 내보내고 싶습니다.파워 포인트에서 OpenXML을 사용하여 테이블 만들기
이미지 (화면 캡처)를 파워 포인트로 내보내려면 링크 만 조사하고 발견했습니다. 내 시나리오에서는 20 열이있는 스크롤 막대가 있고 위의 해결 방법으로 표시되지 않기 때문에 화면 캡처도 작동하지 않습니다.
이 시나리오의 모든 문제를 해결하십시오.
P .: 타사 컨트롤을 사용하지 않으려합니다.
편집 :
지금의 OpenXML을 사용하는 것을 시도했다, 그러나 나는 다음과 같은 오류를 얻고있다 : 내 코드는 다음과 같습니다
:
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/ 어떤 도움을?
아이디어 : 당신이 office.interop 서버에 설치 한 경우에는 취득하기위한 웹 메소드를 만들 수 있습니다/데이터를 수락하고 PP 파일을 만듭니다. MS 오피스가 제 3 자라고 생각하십니까? – Steve
아니요, 제 의도는 MS Office만을 사용하는 것입니다. 고마워. 나는 그것을 시도해 줄 것이다 !!! – adityaswami89