Unable to extract table data from word document #6255

Closed
opened 2026-02-21 18:14:45 -05:00 by yindo · 2 comments
Owner

Originally created by @naked34501 on GitHub (Oct 23, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

10.0

Cloud or Self Hosted

Cloud

Steps to reproduce

The word document I uploaded contains table data, but the document extractor cannot extract the table data. The entire table data is lost, and the table data in the word document cannot be extracted.

✔️ Expected Behavior

The word document I uploaded contains table data, but the document extractor cannot extract the table data. The entire table data is lost, and the table data in the word document cannot be extracted.

Actual Behavior

The word document I uploaded contains table data, but the document extractor cannot extract the table data. The entire table data is lost, and the table data in the word document cannot be extracted.

Originally created by @naked34501 on GitHub (Oct 23, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 10.0 ### Cloud or Self Hosted Cloud ### Steps to reproduce The word document I uploaded contains table data, but the document extractor cannot extract the table data. The entire table data is lost, and the table data in the word document cannot be extracted. ### ✔️ Expected Behavior The word document I uploaded contains table data, but the document extractor cannot extract the table data. The entire table data is lost, and the table data in the word document cannot be extracted. ### ❌ Actual Behavior The word document I uploaded contains table data, but the document extractor cannot extract the table data. The entire table data is lost, and the table data in the word document cannot be extracted.
yindo added the 🐞 bug label 2026-02-21 18:14:45 -05:00
yindo closed this issue 2026-02-21 18:14:45 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 23, 2024):

Hello, @naked34501! I'm here to help you with any bugs, questions, or contributions you have for the Dify project. Let me know how I can assist you!

To address the issue of table data not being extracted from a Word document using Dify version 10.0, ensure that the WordExtractor class is correctly parsing tables into markdown format. The _table_to_markdown method is responsible for converting tables into markdown, which is then included in the extracted content. Verify that the parse_docx method is correctly iterating over the document's elements and calling _table_to_markdown for each table.

Here's a relevant snippet from the code that handles table extraction:

def _table_to_markdown(self, table, image_map):
    markdown = []
    total_cols = max(len(row.cells) for row in table.rows)

    header_row = table.rows[0]
    headers = self._parse_row(header_row, image_map, total_cols)
    markdown.append("| " + " | ".join(headers) + " |")
    markdown.append("| " + " | ".join(["---"] * total_cols) + " |")

    for row in table.rows[1:]:
        row_cells = self._parse_row(row, image_map, total_cols)
        markdown.append("| " + " | ".join(row_cells) + " |")
    return "\n".join(markdown)

Ensure that the parse_docx method is correctly identifying table elements and invoking _table_to_markdown:

for element in doc.element.body:
    if hasattr(element, "tag"):
        if isinstance(element.tag, str) and element.tag.endswith("tbl"):  # table
            table = tables.pop(0)
            content.append(self._table_to_markdown(table, image_map))

If the tables are still not being extracted, check for any errors in the _parse_row or _parse_cell methods that might prevent proper parsing of table rows and cells [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 23, 2024): <!-- Greeting --> Hello, @naked34501! I'm here to help you with any bugs, questions, or contributions you have for the Dify project. Let me know how I can assist you! <!-- Answer --> To address the issue of table data not being extracted from a Word document using Dify version 10.0, ensure that the `WordExtractor` class is correctly parsing tables into markdown format. The `_table_to_markdown` method is responsible for converting tables into markdown, which is then included in the extracted content. Verify that the `parse_docx` method is correctly iterating over the document's elements and calling `_table_to_markdown` for each table. Here's a relevant snippet from the code that handles table extraction: ```python def _table_to_markdown(self, table, image_map): markdown = [] total_cols = max(len(row.cells) for row in table.rows) header_row = table.rows[0] headers = self._parse_row(header_row, image_map, total_cols) markdown.append("| " + " | ".join(headers) + " |") markdown.append("| " + " | ".join(["---"] * total_cols) + " |") for row in table.rows[1:]: row_cells = self._parse_row(row, image_map, total_cols) markdown.append("| " + " | ".join(row_cells) + " |") return "\n".join(markdown) ``` Ensure that the `parse_docx` method is correctly identifying table elements and invoking `_table_to_markdown`: ```python for element in doc.element.body: if hasattr(element, "tag"): if isinstance(element.tag, str) and element.tag.endswith("tbl"): # table table = tables.pop(0) content.append(self._table_to_markdown(table, image_map)) ``` If the tables are still not being extracted, check for any errors in the `_parse_row` or `_parse_cell` methods that might prevent proper parsing of table rows and cells <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/rag/extractor/word_extractor.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Oct 23, 2024):

Duplicated

@crazywoola commented on GitHub (Oct 23, 2024): Duplicated
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6255