Как определить идентификаторы, используемые в презентации PowerPoint, с помощью OpenXML SDK версии 3.0?C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Как определить идентификаторы, используемые в презентации PowerPoint, с помощью OpenXML SDK версии 3.0?

Сообщение Anonymous »


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
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»