小编Ekz*_*Man的帖子

从DOCX中提取表格

使用OpenXML(C#)解析*.docx文档时遇到一个问题.

所以,这是我的步骤:
1.加载*.docx文档
2.接收段落列表
3.在每个段落中查找文本,图像和表格元素
4.为每个文本和图像元素创建html标签
5.将输出保存为*. html文件

我已经找到了如何在文档中找到图像文件并将其解压缩.现在还有一步 - 找到文本中的表位置(段落).

如果有人知道如何使用OpenXML在*.docx文档中找到表格请帮忙.谢谢.

附加:好的,可能是我不清楚解释我的意思.如果我们获得段落的内容,您可以找到chield对象作为文本块,图片等.所以,如果段落包含Run包含Picture那就意味着在这个地方放置Word文档放置图像.

我的功能样本:

public static string ParseDocxDocument(string pathToFile)
    {
        StringBuilder result = new StringBuilder();
        WordprocessingDocument wordProcessingDoc = WordprocessingDocument.Open(pathToFile, true);
        List<ImagePart> imgPart = wordProcessingDoc.MainDocumentPart.ImageParts.ToList();
        IEnumerable<Paragraph> paragraphElement = wordProcessingDoc.MainDocumentPart.Document.Descendants<Paragraph>();
        int imgCounter = 0;


        foreach (Paragraph par in paragraphElement)
        {

                //Add new paragraph tag
                result.Append("<div style=\"width:100%; text-align:");

                //Append anchor style
                if (par.ParagraphProperties != null && par.ParagraphProperties.Justification != null)
                    switch (par.ParagraphProperties.Justification.Val.Value)
                    {
                        case JustificationValues.Left:
                            result.Append("left;");
                            break;
                        case JustificationValues.Center:
                            result.Append("center;");
                            break;
                        case JustificationValues.Both:
                            result.Append("justify;"); …
Run Code Online (Sandbox Code Playgroud)

c# docx openxml

5
推荐指数
1
解决办法
6062
查看次数

标签 统计

c# ×1

docx ×1

openxml ×1