private void SetGraphicFrameVisualProperties(SlidePart slidePart, GraphicFrame gfarame) { base.VisualShapeProp = new PPTVisualPPTShapeProp(); if (gfarame.Transform != null) { base.VisualShapeProp.Extents = gfarame.Transform.Extents; base.VisualShapeProp.Offset = gfarame.Transform.Offset; } else { //Petco change get properties from layout for GraphicFrame object. DocumentFormat.OpenXml.Presentation.ShapeTree shapeTree = slidePart.SlideLayoutPart.SlideLayout.CommonSlideData.ShapeTree; DocumentFormat.OpenXml.Presentation.GraphicFrame layoutShape; if (shapeTree != null) { layoutShape = shapeTree.GetFirstChild <DocumentFormat.OpenXml.Presentation.GraphicFrame>(); if (layoutShape.Transform != null) { base.VisualShapeProp.Extents = layoutShape.Transform.Extents; base.VisualShapeProp.Offset = layoutShape.Transform.Offset; } } } }
private void SetGraphicFrameNonVisualProperties(SlidePart slidePart, GraphicFrame gfarame) { if (gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.HyperlinkOnClick != null) { foreach (HyperlinkRelationship link in slidePart.HyperlinkRelationships) { if (link.Id.Equals(gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.HyperlinkOnClick.Id)) { ClickLinkUrl = link.Uri.IsAbsoluteUri ? link.Uri.AbsoluteUri : link.Uri.OriginalString; } } } if (gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.HyperlinkOnHover != null) { foreach (HyperlinkRelationship link in slidePart.HyperlinkRelationships) { if (link.Id.Equals(gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.HyperlinkOnHover.Id)) { HoverLinkUrl = link.Uri.IsAbsoluteUri ? link.Uri.AbsoluteUri : link.Uri.OriginalString; } } } var nonVisualShapeProp = new PPTNonVisualShapeProp { Id = "s1s" + //HARD CODED: we split it into separate HTML files! gfarame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.Id, Name = gfarame.LocalName, Type = "PPTGraphicFrame" }; base.NonVisualShapeProp = nonVisualShapeProp; }
public ITableVisual AppendTableVisual(string name) { Drawing.Table table = new Drawing.Table() .AppendChildFluent(new Drawing.TableProperties()) .AppendChildFluent(new Drawing.TableGrid()); GraphicFrame graphicFrame = this.shapeTree.AppendChild(new GraphicFrame() { NonVisualGraphicFrameProperties = new NonVisualGraphicFrameProperties() { NonVisualDrawingProperties = new NonVisualDrawingProperties() { Name = name, Id = 6 // TODO: calculate }, NonVisualGraphicFrameDrawingProperties = new NonVisualGraphicFrameDrawingProperties(), ApplicationNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties() }, Graphic = new Drawing.Graphic() { GraphicData = new Drawing.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/table" } .AppendChildFluent(table) } }); return(new OpenXmlTableVisual(this.container, graphicFrame)); }
/// <summary> /// Removes a table (a:tbl) given its "artificial" id (tblId). /// </summary> /// <param name="tblId">The table id.</param> /// <remarks> /// <![CDATA[ /// p:graphicFrame /// a:graphic /// a:graphicData /// a:tbl (Table) /// ]]> /// </remarks> internal void RemoveTable(int tblId) { IEnumerable <GraphicFrame> graphicFrames = this.slidePart.Slide.Descendants <GraphicFrame>(); GraphicFrame graphicFrame = graphicFrames.ElementAt(tblId); graphicFrame.Remove(); }
private void AddTableCommonProperty(GraphicFrame graphicFrame1, uint ObjectID) { NonVisualGraphicFrameProperties nonVisualGraphicFrameProperties1 = new NonVisualGraphicFrameProperties(); NonVisualDrawingProperties nonVisualDrawingProperties2 = new NonVisualDrawingProperties() { Id = ObjectID, Name = $"Table{ObjectID}" }; A.NonVisualDrawingPropertiesExtensionList nonVisualDrawingPropertiesExtensionList1 = new A.NonVisualDrawingPropertiesExtensionList(); A.NonVisualDrawingPropertiesExtension nonVisualDrawingPropertiesExtension1 = new A.NonVisualDrawingPropertiesExtension() { Uri = "{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}" }; OpenXmlUnknownElement openXmlUnknownElement1 = OpenXmlUnknownElement.CreateOpenXmlUnknownElement("<a16:creationId xmlns:a16=\"http://schemas.microsoft.com/office/drawing/2014/main\" id=\"{7AB8EDC7-F9EF-4752-9A46-413B9437344B}\" />"); nonVisualDrawingPropertiesExtension1.Append(openXmlUnknownElement1); nonVisualDrawingPropertiesExtensionList1.Append(nonVisualDrawingPropertiesExtension1); nonVisualDrawingProperties2.Append(nonVisualDrawingPropertiesExtensionList1); NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties1 = new NonVisualGraphicFrameDrawingProperties(); A.GraphicFrameLocks graphicFrameLocks1 = new A.GraphicFrameLocks() { NoGrouping = true }; nonVisualGraphicFrameDrawingProperties1.Append(graphicFrameLocks1); ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties2 = new ApplicationNonVisualDrawingProperties(); ApplicationNonVisualDrawingPropertiesExtensionList applicationNonVisualDrawingPropertiesExtensionList1 = new ApplicationNonVisualDrawingPropertiesExtensionList(); ApplicationNonVisualDrawingPropertiesExtension applicationNonVisualDrawingPropertiesExtension1 = new ApplicationNonVisualDrawingPropertiesExtension() { Uri = "{D42A27DB-BD31-4B8C-83A1-F6EECF244321}" }; P14.ModificationId modificationId1 = new P14.ModificationId() { Val = (UInt32Value)833561296U }; modificationId1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main"); applicationNonVisualDrawingPropertiesExtension1.Append(modificationId1); applicationNonVisualDrawingPropertiesExtensionList1.Append(applicationNonVisualDrawingPropertiesExtension1); applicationNonVisualDrawingProperties2.Append(applicationNonVisualDrawingPropertiesExtensionList1); nonVisualGraphicFrameProperties1.Append(nonVisualDrawingProperties2); nonVisualGraphicFrameProperties1.Append(nonVisualGraphicFrameDrawingProperties1); nonVisualGraphicFrameProperties1.Append(applicationNonVisualDrawingProperties2); graphicFrame1.Append(nonVisualGraphicFrameProperties1); }
public OpenXmlTableVisual(IOpenXmlVisualContainer container, GraphicFrame graphicFrame) : base(container, graphicFrame) { this.table = this.graphicFrame .GetFirstChild <Drawing.Graphic>() .GetFirstChild <Drawing.GraphicData>() .GetFirstChild <Drawing.Table>(); }
public OpenXmlChartVisual(IOpenXmlVisualContainer container, GraphicFrame graphicFrame) : base(container, graphicFrame) { this.chart = this.graphicFrame .GetFirstChild <Drawing.Graphic>() .GetFirstChild <Drawing.GraphicData>() .GetFirstChild <Charts.Chart>(); }
public static ChartElement Create(string name, GraphicFrame element, SlideElement slide) { ChartElement chart = new ChartElement(); if (!chart.Parse(name, slide)) { return(null); } chart.ChartFrame = element; return(chart); }
public static TableElement Create(string name, GraphicFrame element, SlideElement slide) { TableElement table = new TableElement(); if (!table.Parse(name, slide)) { return(null); } table.TableFrame = element; return(table); }
public void AddContent(ShapeTree shapeTree1, uint ObjectID, PPTXTable Content, Dictionary <string, string> HyperLinkIDMap) { GraphicFrame graphicFrame1 = new GraphicFrame(); AddTableCommonProperty(graphicFrame1, ObjectID); Transform transform1 = SlideWriterHelper.CreateTransform(Content.Transform); A.Graphic graphic1 = new A.Graphic(); A.GraphicData graphicData1 = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/table" }; A.Table table1 = new A.Table(); A.TableProperties tableProperties1 = new A.TableProperties() { FirstRow = true, BandRow = true }; A.TableStyleId tableStyleId1 = new A.TableStyleId(); tableStyleId1.Text = "{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}"; tableProperties1.Append(tableStyleId1); table1.Append(tableProperties1); A.TableGrid tableGrid1 = new A.TableGrid(); foreach (var tableColumn in Content.Columns) { tableGrid1.Append(CreateColumn(tableColumn.Width)); } table1.Append(tableGrid1); foreach (var _tableRow in Content.Rows) { table1.Append(CreateRow(Content.Columns, _tableRow, HyperLinkIDMap)); } graphicData1.Append(table1); graphic1.Append(graphicData1); graphicFrame1.Append(transform1); graphicFrame1.Append(graphic1); shapeTree1.Append(graphicFrame1); }
/// <summary> /// Finds a table (a:tbl) given its "artificial" id (tblId). /// </summary> /// <param name="tblId">The table id.</param> /// <returns>The table or null if not found.</returns> /// <remarks>The "artificial" id (tblId) is created inside FindTables().</remarks> internal A.Table FindTable(int tblId) { A.Table tbl = null; IEnumerable <GraphicFrame> graphicFrames = this.slidePart.Slide.Descendants <GraphicFrame>(); GraphicFrame graphicFrame = graphicFrames.ElementAt(tblId); if (graphicFrame != null) { tbl = graphicFrame.Descendants <A.Table>().First(); } return(tbl); }
public IChartVisual AppendChartVisual(string name) { ChartPart chartPart = this.container.Part.AddNewPartDefaultId <ChartPart>(); chartPart.ChartSpace = new Charts.ChartSpace() { Date1904 = new Charts.Date1904() { Val = false } } .AppendChildFluent( new Charts.Chart() { PlotArea = new Charts.PlotArea(), DisplayBlanksAs = new Charts.DisplayBlanksAs() { Val = Charts.DisplayBlanksAsValues.Gap } } ); Charts.Chart chart = new Charts.Chart(); chart.SetAttribute(new OpenXmlAttribute("r", "id", "http://schemas.openxmlformats.org/officeDocument/2006/relationships", this.container.Part.GetIdOfPart(chartPart))); GraphicFrame graphicFrame = this.shapeTree.AppendChild(new GraphicFrame() { NonVisualGraphicFrameProperties = new NonVisualGraphicFrameProperties() { NonVisualDrawingProperties = new NonVisualDrawingProperties() { Name = name, Id = 6 // TODO: calculate }, NonVisualGraphicFrameDrawingProperties = new NonVisualGraphicFrameDrawingProperties(), ApplicationNonVisualDrawingProperties = new ApplicationNonVisualDrawingProperties() }, Graphic = new Drawing.Graphic() { GraphicData = new Drawing.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/chart" } .AppendChildFluent(chart) } }); return(new OpenXmlChartVisual(this.container, graphicFrame)); }
/// <summary> /// Append Table into Last Slide /// </summary> /// <param name="presentationDocument"></param> 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 GraphicFrame graphicFrame = tableSlidePart.Slide.CommonSlideData.ShapeTree.AppendChild(new GraphicFrame()); // Specify the required Frame properties of the graphicFrame ApplicationNonVisualDrawingPropertiesExtension applicationNonVisualDrawingPropertiesExtension = new ApplicationNonVisualDrawingPropertiesExtension() { Uri = "{D42A27DB-BD31-4B8C-83A1-F6EECF244321}" }; 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 NonVisualGraphicFrameProperties (new NonVisualDrawingProperties() { Id = 5, Name = "table 1" }, new NonVisualGraphicFrameDrawingProperties(new A.GraphicFrameLocks() { NoGrouping = true }), new ApplicationNonVisualDrawingProperties(new ApplicationNonVisualDrawingPropertiesExtensionList(applicationNonVisualDrawingPropertiesExtension))); graphicFrame.Transform = new Transform(new A.Offset() { X = 1650609L, Y = 4343400L }, new A.Extents() { Cx = 6096000L, Cy = 741680L }); // Specify the Griaphic of the graphic Frame graphicFrame.Graphic = new A.Graphic(new A.GraphicData(GenerateTable()) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/table" }); presentationPart.Presentation.Save(); }
private static bool TryCreateGraphicFrameVisual(IOpenXmlVisualContainer container, GraphicFrame graphicFrame, out IOpenXmlVisual visual) { string uri = graphicFrame.Graphic?.GraphicData?.Uri?.Value; switch (uri) { case "http://schemas.openxmlformats.org/drawingml/2006/chart": visual = new OpenXmlChartVisual(container, graphicFrame); return(true); case "http://schemas.openxmlformats.org/drawingml/2006/table": visual = new OpenXmlTableVisual(container, graphicFrame); return(true); default: visual = new OpenXmlGenericGraphicFrameVisual(container, graphicFrame); return(true); } }
public OpenXmlGenericGraphicFrameVisual(IOpenXmlVisualContainer container, GraphicFrame graphicFrame) : base(container, graphicFrame) { }
public PPTGraphicFrame(SlidePart slidePart, GraphicFrame gfarame) { SetGraphicFrameVisualProperties(slidePart, gfarame); SetGraphicFrameNonVisualProperties(slidePart, gfarame); }
public void CreateExcelDoc(string fileName) { List <Student> students = new List <Student>(); Initizalize(students); using (SpreadsheetDocument document = SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook)) { WorkbookPart workbookPart = document.AddWorkbookPart(); workbookPart.Workbook = new Workbook(); WorksheetPart worksheetPart = workbookPart.AddNewPart <WorksheetPart>(); worksheetPart.Worksheet = new Worksheet(); Sheets sheets = workbookPart.Workbook.AppendChild(new Sheets()); Sheet sheet = new Sheet() { Id = workbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Students" }; SheetData sheetData = worksheetPart.Worksheet.AppendChild(new SheetData()); // Add drawing part to WorksheetPart DrawingsPart drawingsPart = worksheetPart.AddNewPart <DrawingsPart>(); worksheetPart.Worksheet.Append(new Drawing() { Id = worksheetPart.GetIdOfPart(drawingsPart) }); worksheetPart.Worksheet.Save(); drawingsPart.WorksheetDrawing = new WorksheetDrawing(); sheets.Append(sheet); workbookPart.Workbook.Save(); // Add a new chart and set the chart language ChartPart chartPart = drawingsPart.AddNewPart <ChartPart>(); chartPart.ChartSpace = new ChartSpace(); chartPart.ChartSpace.AppendChild(new EditingLanguage() { Val = "en-US" }); Chart chart = chartPart.ChartSpace.AppendChild(new Chart()); chart.AppendChild(new AutoTitleDeleted() { Val = true }); // We don't want to show the chart title // Create a new Clustered Column Chart PlotArea plotArea = chart.AppendChild(new PlotArea()); Layout layout = plotArea.AppendChild(new Layout()); BarChart barChart = plotArea.AppendChild(new BarChart( new BarDirection() { Val = new EnumValue <BarDirectionValues>(BarDirectionValues.Column) }, new BarGrouping() { Val = new EnumValue <BarGroupingValues>(BarGroupingValues.Clustered) }, new VaryColors() { Val = false } )); // Constructing header Row row = new Row(); int rowIndex = 1; row.AppendChild(ConstructCell(string.Empty, CellValues.String)); foreach (var month in Months.Short) { row.AppendChild(ConstructCell(month, CellValues.String)); } // Insert the header row to the Sheet Data sheetData.AppendChild(row); rowIndex++; // Create chart series for (int i = 0; i < students.Count; i++) { BarChartSeries barChartSeries = barChart.AppendChild(new BarChartSeries( new Index() { Val = (uint)i }, new Order() { Val = (uint)i }, new SeriesText(new NumericValue() { Text = students[i].Name }) )); // Adding category axis to the chart CategoryAxisData categoryAxisData = barChartSeries.AppendChild(new CategoryAxisData()); // Category // Constructing the chart category string formulaCat = "Students!$B$1:$G$1"; StringReference stringReference = categoryAxisData.AppendChild(new StringReference() { Formula = new DocumentFormat.OpenXml.Drawing.Charts.Formula() { Text = formulaCat } }); StringCache stringCache = stringReference.AppendChild(new StringCache()); stringCache.Append(new PointCount() { Val = (uint)Months.Short.Length }); for (int j = 0; j < Months.Short.Length; j++) { stringCache.AppendChild(new NumericPoint() { Index = (uint)j }).Append(new NumericValue(Months.Short[j])); } } var chartSeries = barChart.Elements <BarChartSeries>().GetEnumerator(); for (int i = 0; i < students.Count; i++) { row = new Row(); row.AppendChild(ConstructCell(students[i].Name, CellValues.String)); chartSeries.MoveNext(); string formulaVal = string.Format("Students!$B${0}:$G${0}", rowIndex); DocumentFormat.OpenXml.Drawing.Charts.Values values = chartSeries.Current.AppendChild(new DocumentFormat.OpenXml.Drawing.Charts.Values()); NumberReference numberReference = values.AppendChild(new NumberReference() { Formula = new DocumentFormat.OpenXml.Drawing.Charts.Formula() { Text = formulaVal } }); NumberingCache numberingCache = numberReference.AppendChild(new NumberingCache()); numberingCache.Append(new PointCount() { Val = (uint)Months.Short.Length }); for (uint j = 0; j < students[i].Values.Length; j++) { var value = students[i].Values[j]; row.AppendChild(ConstructCell(value.ToString(), CellValues.Number)); numberingCache.AppendChild(new NumericPoint() { Index = j }).Append(new NumericValue(value.ToString())); } sheetData.AppendChild(row); rowIndex++; } barChart.AppendChild(new DataLabels( new ShowLegendKey() { Val = false }, new ShowValue() { Val = false }, new ShowCategoryName() { Val = false }, new ShowSeriesName() { Val = false }, new ShowPercent() { Val = false }, new ShowBubbleSize() { Val = false } )); barChart.Append(new AxisId() { Val = 48650112u }); barChart.Append(new AxisId() { Val = 48672768u }); // Adding Category Axis plotArea.AppendChild( new CategoryAxis( new AxisId() { Val = 48650112u }, new Scaling(new Orientation() { Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>(DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax) }), new Delete() { Val = false }, new AxisPosition() { Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Bottom) }, new TickLabelPosition() { Val = new EnumValue <TickLabelPositionValues>(TickLabelPositionValues.NextTo) }, new CrossingAxis() { Val = 48672768u }, new Crosses() { Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero) }, new AutoLabeled() { Val = true }, new LabelAlignment() { Val = new EnumValue <LabelAlignmentValues>(LabelAlignmentValues.Center) } )); // Adding Value Axis plotArea.AppendChild( new ValueAxis( new AxisId() { Val = 48672768u }, new Scaling(new Orientation() { Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>(DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax) }), new Delete() { Val = false }, new AxisPosition() { Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Left) }, new MajorGridlines(), new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat() { FormatCode = "General", SourceLinked = true }, new TickLabelPosition() { Val = new EnumValue <TickLabelPositionValues>(TickLabelPositionValues.NextTo) }, new CrossingAxis() { Val = 48650112u }, new Crosses() { Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero) }, new CrossBetween() { Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between) } )); chart.Append( new PlotVisibleOnly() { Val = true }, new DisplayBlanksAs() { Val = new EnumValue <DisplayBlanksAsValues>(DisplayBlanksAsValues.Gap) }, new ShowDataLabelsOverMaximum() { Val = false } ); chartPart.ChartSpace.Save(); // Positioning the chart on the spreadsheet TwoCellAnchor twoCellAnchor = drawingsPart.WorksheetDrawing.AppendChild(new TwoCellAnchor()); twoCellAnchor.Append(new DocumentFormat.OpenXml.Drawing.Spreadsheet.FromMarker( new ColumnId("0"), new ColumnOffset("0"), new RowId((rowIndex + 2).ToString()), new RowOffset("0") )); twoCellAnchor.Append(new DocumentFormat.OpenXml.Drawing.Spreadsheet.ToMarker( new ColumnId("8"), new ColumnOffset("0"), new RowId((rowIndex + 12).ToString()), new RowOffset("0") )); // Append GraphicFrame to TwoCellAnchor GraphicFrame graphicFrame = twoCellAnchor.AppendChild(new GraphicFrame()); graphicFrame.Macro = string.Empty; graphicFrame.Append(new NonVisualGraphicFrameProperties( new NonVisualDrawingProperties() { Id = 2u, Name = "Sample Chart" }, new NonVisualGraphicFrameDrawingProperties() )); graphicFrame.Append(new Transform( new DocumentFormat.OpenXml.Drawing.Offset() { X = 0L, Y = 0L }, new DocumentFormat.OpenXml.Drawing.Extents() { Cx = 0L, Cy = 0L } )); graphicFrame.Append(new DocumentFormat.OpenXml.Drawing.Graphic( new DocumentFormat.OpenXml.Drawing.GraphicData( new ChartReference() { Id = drawingsPart.GetIdOfPart(chartPart) } ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/chart" } )); twoCellAnchor.Append(new ClientData()); drawingsPart.WorksheetDrawing.Save(); worksheetPart.Worksheet.Save(); } }
public OpenXmlGraphicFrameVisual(IOpenXmlVisualContainer container, GraphicFrame graphicFrame) { this.container = container; this.graphicFrame = graphicFrame; }