2026-06-24 16:21:57 +08:00
2026-06-24 16:21:57 +08:00
2026-06-24 16:21:57 +08:00
2026-06-24 16:21:57 +08:00
2026-06-24 16:21:57 +08:00
2026-06-24 16:21:57 +08:00
2026-06-24 16:21:57 +08:00

wordtable2sqlite

.docx 里的 Word 表格内容导入 SQLite 的最小 Go 工具。

详细操作说明见:HOWTO.md

特点

  • 不依赖 Word、WPS、Python 或 LibreOffice。
  • 直接解析 .docx 内部的 word/document.xml
  • SQLite 使用纯 Go 驱动 modernc.org/sqlite,方便编译成单文件可执行程序。
  • 保底保存所有表格单元格到 cells
  • 对常见报备表这种“标题行 + 表头行 + 数据行”的结构,自动生成 fields,便于按字段检索。

编译

go build -o bin/wordtable2sqlite .

给非技术用户使用时,分发 bin/wordtable2sqlite 这个可执行文件即可。

使用

./bin/wordtable2sqlite -reset -db data/report.sqlite input.docx

批量导入多个文件:

./bin/wordtable2sqlite -db data/report.sqlite *.docx

参数:

  • -db:输出 SQLite 文件路径,默认 word_tables.sqlite
  • -reset:导入前删除旧数据库
  • -quiet:不输出每个文件的摘要

数据表

  • documents:每个导入的 Word 文件。
  • tablesWord 文档中的表格。
  • cells:每个表格单元格,包含表格序号、行号、列号、跨列数和文本。
  • fields:自动推断出的字段,常用于报备表检索。

常用查询:

SELECT key, value
FROM fields
ORDER BY id;
SELECT table_index, row_index, cell_index, text
FROM cells
ORDER BY table_index, row_index, cell_index;
Description
Import DOCX Word table contents into SQLite
Readme 46 KiB
Languages
Go 100%