Полный код
using System;
using SautinSoft.Document;
using System.IO;
using System.Linq;
using System.Text;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
// Get your free 100-day key here:
// https://sautinsoft.com/start-for-free/
IterationElement();
}
/// <summary>
/// Calculate sections, paragraphs, inlines, runs and fields in DOCX document.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/iteration-in-element-collection-net-csharp-vb.php
/// </remarks>
static void IterationElement()
{
DocumentCore dc = DocumentCore.Load(@"..\..\..\Parsing.docx", LoadOptions.DocxDefault);
int numberOfSections = dc.Sections.Count;
int numberOfParagraphs = dc.GetChildElements(true, ElementType.Paragraph).Count();
int numberOfRunsAndFields = dc.GetChildElements(true, ElementType.Run, ElementType.Field).Count();
int numberOfInlines = dc.GetChildElements(true).OfType<Inline>().Count();
int elements = dc.Sections[0].GetChildElements(true).Count();
StringBuilder sb = new StringBuilder();
sb.AppendLine("File has:");
sb.AppendLine(numberOfSections + " section");
sb.AppendLine(numberOfParagraphs + " paragraphs");
sb.AppendLine(numberOfRunsAndFields + " runs and fields");
sb.AppendLine(numberOfInlines + " inlines");
sb.AppendLine("First section contains " + elements + " elements");
Console.WriteLine(sb.ToString());
Console.ReadKey();
}
}
}
Imports System
Imports SautinSoft.Document
Imports System.IO
Imports System.Linq
Imports System.Text
Module Sample
Sub Main()
IterationElement()
End Sub
''' Get your free 100-day key here:
''' https://sautinsoft.com/start-for-free/
''' <summary>
''' Calculate sections, paragraphs, inlines, runs and fields in DOCX document.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/iteration-in-element-collection-net-csharp-vb.php
''' </remarks>
Sub IterationElement()
Dim dc As DocumentCore = DocumentCore.Load("..\..\..\Parsing.docx", LoadOptions.DocxDefault)
Dim numberOfSections As Integer = dc.Sections.Count
Dim numberOfParagraphs As Integer = dc.GetChildElements(True, ElementType.Paragraph).Count()
Dim numberOfRunsAndFields As Integer = dc.GetChildElements(True, ElementType.Run, ElementType.Field).Count()
Dim numberOfInlines As Integer = dc.GetChildElements(True).OfType(Of Inline)().Count()
Dim elements As Integer = dc.Sections(0).GetChildElements(True).Count()
Dim sb As New StringBuilder()
sb.AppendLine("File has:")
sb.AppendLine(numberOfSections & " section")
sb.AppendLine(numberOfParagraphs & " paragraphs")
sb.AppendLine(numberOfRunsAndFields & " runs and fields")
sb.AppendLine(numberOfInlines & " inlines")
sb.AppendLine("First section contains " & elements & " elements")
Console.WriteLine(sb.ToString())
Console.ReadKey()
End Sub
End Module
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: