Как определить идентификаторы, используемые в презентации PowerPoint, с помощью OpenXML SDK версии 3.0? ⇐ C#
Как определить идентификаторы, используемые в презентации PowerPoint, с помощью OpenXML SDK версии 3.0?
INTRO
When inserting new elements into an existing presentation, some of them require a unique identifier (positive integer).
To avoid using the same identifier twice, we need to find the identifiers that are already in use.
The code below shows how to retrieve some of the identifiers, but I don't know how to retrieve all of them.
QUESTION
How do we detect all unique identifiers used in a PowerPoint presentation using the OpenXML SDK version 3.0?
using G = DocumentFormat.OpenXml.Packaging; using D = DocumentFormat.OpenXml.Drawing; using P = DocumentFormat.OpenXml.Presentation; using P14 = DocumentFormat.OpenXml.Office2010.PowerPoint; using P16 = DocumentFormat.OpenXml.Office2016.Drawing; private readonly HashSet UsedIdentifiers = new HashSet(); private void RememberUniqueIdentifiers(G.PresentationDocument doc, string filename) { var presentationPart = doc.PresentationPart ?? throw new FileFormatException($"Error: The document contains no presentation parts: {filename}"); var presentation = presentationPart.Presentation; var slideIds = presentation.SlideIdList ?? throw new FileFormatException($"Error: The presentation contains no slide identifiers: {filename}"); foreach (var child in slideIds.ChildElements) { if (child is not P.SlideId slideId) continue; if (slideId.RelationshipId == null) continue; if (presentationPart.GetPartById(slideId.RelationshipId!) is not G.SlidePart slidePart) continue; var slide = slidePart.Slide; if (slide == null) continue; var modificationIds = slide.Descendants(); foreach (var modificationId in modificationIds) { var id = modificationId.Val; if (id != null) UsedIdentifiers.Add(id); } var nonVisualDrawingProperties = slide.Descendants(); foreach (var nonVisualDrawingProperty in nonVisualDrawingProperties) { var id = nonVisualDrawingProperty.Id; if (id != null) UsedIdentifiers.Add(id); } var colIdIdentifiers = slide.Descendants(); foreach (var colIdIdentifier in colIdIdentifiers) { var id = colIdIdentifier.Val; if (id != null) UsedIdentifiers.Add(id); } var rowIdIdentifiers = slide.Descendants(); foreach (var rowIdIdentifier in rowIdIdentifiers) { var id = rowIdIdentifier.Val; if (id != null) UsedIdentifiers.Add(id); } } } The code was modified to keep it short and readable (at the cost of efficiency).
Источник: https://stackoverflow.com/questions/780 ... the-openxm
INTRO
When inserting new elements into an existing presentation, some of them require a unique identifier (positive integer).
To avoid using the same identifier twice, we need to find the identifiers that are already in use.
The code below shows how to retrieve some of the identifiers, but I don't know how to retrieve all of them.
QUESTION
How do we detect all unique identifiers used in a PowerPoint presentation using the OpenXML SDK version 3.0?
using G = DocumentFormat.OpenXml.Packaging; using D = DocumentFormat.OpenXml.Drawing; using P = DocumentFormat.OpenXml.Presentation; using P14 = DocumentFormat.OpenXml.Office2010.PowerPoint; using P16 = DocumentFormat.OpenXml.Office2016.Drawing; private readonly HashSet UsedIdentifiers = new HashSet(); private void RememberUniqueIdentifiers(G.PresentationDocument doc, string filename) { var presentationPart = doc.PresentationPart ?? throw new FileFormatException($"Error: The document contains no presentation parts: {filename}"); var presentation = presentationPart.Presentation; var slideIds = presentation.SlideIdList ?? throw new FileFormatException($"Error: The presentation contains no slide identifiers: {filename}"); foreach (var child in slideIds.ChildElements) { if (child is not P.SlideId slideId) continue; if (slideId.RelationshipId == null) continue; if (presentationPart.GetPartById(slideId.RelationshipId!) is not G.SlidePart slidePart) continue; var slide = slidePart.Slide; if (slide == null) continue; var modificationIds = slide.Descendants(); foreach (var modificationId in modificationIds) { var id = modificationId.Val; if (id != null) UsedIdentifiers.Add(id); } var nonVisualDrawingProperties = slide.Descendants(); foreach (var nonVisualDrawingProperty in nonVisualDrawingProperties) { var id = nonVisualDrawingProperty.Id; if (id != null) UsedIdentifiers.Add(id); } var colIdIdentifiers = slide.Descendants(); foreach (var colIdIdentifier in colIdIdentifiers) { var id = colIdIdentifier.Val; if (id != null) UsedIdentifiers.Add(id); } var rowIdIdentifiers = slide.Descendants(); foreach (var rowIdIdentifier in rowIdIdentifiers) { var id = rowIdIdentifier.Val; if (id != null) UsedIdentifiers.Add(id); } } } The code was modified to keep it short and readable (at the cost of efficiency).
Источник: https://stackoverflow.com/questions/780 ... the-openxm
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение