У меня есть 10-страничный документ. Каждая страница имеет верхний и нижний колонтитулы. Заголовок может иметь две строки текста или один, каждый из которых имеет другой стиль. То, что нужно сделать, - это пропустить документ. Прочитайте верхний и нижний колонтитул каждой страницы, поместите это в DataTable
, чтобы я мог позже создать TOC. Любая идея, я пробовал, но она не работает правильно, она не читает нижний колонтитул страницы и пропускает страницы (это выглядит не по порядку, и я хотел бы получить значения в порядке страницы, так как кажется, что пропустил первую страницу до последней итерация).OpenXML asp.net loop через заголовок
Справка будет принята с благодарностью. JT
Using wordDoc As WordprocessingDocument = WordprocessingDocument.Open(combineDocName, True)
For Each Head As HeaderPart In wordDoc.MainDocumentPart.HeaderParts
For Each currentParagraph As DocumentFormat.OpenXml.Wordprocessing.Paragraph In Head.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.Paragraph)()
Dim p As ParagraphProperties = currentParagraph.Elements(Of ParagraphProperties)().First()
If p.Count > 0 Then
If (p.ParagraphStyleId IsNot Nothing) Then
If p.ParagraphStyleId.Val.ToString() = "HeaderBar" Then
For Each currentText As Text In Head.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.Text)()
If (String.IsNullOrEmpty(keepHeaderM)) Then
HeaderBarTxt = currentText.Text.Trim()
ElseIf keepHeaderM <> currentText.Text.Trim() Then
HeaderBarTxt = currentText.Text.Trim()
End If
Next
ElseIf p.ParagraphStyleId.Val.ToString() = "NavigationBar" Then
For Each currentText As Text In Head.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.Text)()
iCount = currentText.Text.Split(":").Length - 1
If (String.IsNullOrEmpty(keepHeaderM)) Then
HeaderTxt = currentText.Text.Trim()
ElseIf keepHeaderM <> currentText.Text.Trim() Then
HeaderTxt = currentText.Text.Trim()
End If
Next
End If
End If
End If
Next
Next
For Each foot As FooterPart In wordDoc.MainDocumentPart.FooterParts
For Each currentParagraph2 As DocumentFormat.OpenXml.Wordprocessing.Paragraph In foot.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.Paragraph)()
If currentParagraph2.Count > 0 Then
For Each currentText2 As Text In foot.RootElement.Descendants(Of DocumentFormat.OpenXml.Wordprocessing.Text)()
Dim strTemp As String = currentText2.Text
If strTemp.IndexOf("-") <> -1 Then
FooterTxt = currentText2.Text.Trim()
End If
Next
End If
Next
Next
end using
Что именно не работает? Каков формат документа? – Patrik
То, что я нахожу, когда вы его зацикливаете, не делает этого, чтобы мне было нужно, как быстро прокручивать страницы ... Я пробовал следующее, но я все еще получаю первую третью страницу и первую страницу для некоторых причина. Как это сделать в порядке? – user2883963