Address CSV export and field alignment review
This commit is contained in:
41
HOWTO.md
41
HOWTO.md
@@ -73,7 +73,9 @@ database: report.sqlite
|
||||
|
||||
## 5. 查看字段化内容
|
||||
|
||||
在 macOS/Linux 终端中:
|
||||
普通用户优先导出 CSV 后用 WPS/Excel 打开,见下一节。
|
||||
|
||||
如果机器上安装了 `sqlite3`,也可以直接查看数据库:
|
||||
|
||||
```bash
|
||||
sqlite3 report.sqlite
|
||||
@@ -107,7 +109,7 @@ SELECT key, value FROM fields ORDER BY id;
|
||||
这是最常用的导出方式:
|
||||
|
||||
```bash
|
||||
sqlite3 -header -csv report.sqlite "SELECT key, value FROM fields ORDER BY id;" > report-fields.csv
|
||||
./bin/wordtable2sqlite export-fields -db report.sqlite -out report-fields.csv
|
||||
```
|
||||
|
||||
生成的 `report-fields.csv` 可以直接用 WPS/Excel 打开。
|
||||
@@ -123,11 +125,12 @@ UTF-8
|
||||
如果要检查 Word 表格的原始行列结构,导出 `cells`:
|
||||
|
||||
```bash
|
||||
sqlite3 -header -csv report.sqlite "SELECT table_index, row_index, cell_index, col_index, col_span, text FROM cells ORDER BY table_index, row_index, cell_index;" > report-cells.csv
|
||||
./bin/wordtable2sqlite export-cells -db report.sqlite -out report-cells.csv
|
||||
```
|
||||
|
||||
字段含义:
|
||||
|
||||
- `filename`:Word 文件名。
|
||||
- `table_index`:第几张表,从 0 开始。
|
||||
- `row_index`:第几行,从 0 开始。
|
||||
- `cell_index`:该行第几个单元格。
|
||||
@@ -137,6 +140,8 @@ sqlite3 -header -csv report.sqlite "SELECT table_index, row_index, cell_index, c
|
||||
|
||||
## 8. 常用查询
|
||||
|
||||
下面这些查询需要本机有 `sqlite3` 或其他 SQLite 查看工具。
|
||||
|
||||
查所有字段名:
|
||||
|
||||
```sql
|
||||
@@ -180,22 +185,42 @@ ORDER BY table_index, row_index, cell_index;
|
||||
2. 查看 `cells` 判断 Word 原始表格结构。
|
||||
3. 查看 `fields` 判断字段抽取是否符合预期。
|
||||
|
||||
## 10. 本次样例命令
|
||||
## 10. 表格复杂度限制
|
||||
|
||||
本次样例数据库:
|
||||
当前字段化抽取主要面向常见报备表:
|
||||
|
||||
- 一行标题。
|
||||
- 一行表头。
|
||||
- 一行或多行数据。
|
||||
|
||||
工具会保留所有原始单元格到 `cells`,并按逻辑列处理横向合并的表头。如果 Word 表格包含复杂多行表头、纵向合并单元格、嵌套表格,建议同时导出 `report-cells.csv` 检查原始行列结构。
|
||||
|
||||
## 11. 样例命令模板
|
||||
|
||||
导入:
|
||||
|
||||
```bash
|
||||
/Users/zhaoyilun/Documents/Codex/2026-06-24/wo-x/outputs/sample-baiyin.sqlite
|
||||
./bin/wordtable2sqlite -reset -db report.sqlite input.docx
|
||||
```
|
||||
|
||||
导出字段化 CSV:
|
||||
|
||||
```bash
|
||||
sqlite3 -header -csv /Users/zhaoyilun/Documents/Codex/2026-06-24/wo-x/outputs/sample-baiyin.sqlite "SELECT key, value FROM fields ORDER BY id;" > /Users/zhaoyilun/Documents/Codex/2026-06-24/wo-x/outputs/sample-baiyin-fields.csv
|
||||
./bin/wordtable2sqlite export-fields -db report.sqlite -out report-fields.csv
|
||||
```
|
||||
|
||||
导出原始单元格 CSV:
|
||||
|
||||
```bash
|
||||
sqlite3 -header -csv /Users/zhaoyilun/Documents/Codex/2026-06-24/wo-x/outputs/sample-baiyin.sqlite "SELECT table_index, row_index, cell_index, col_index, col_span, text FROM cells ORDER BY table_index, row_index, cell_index;" > /Users/zhaoyilun/Documents/Codex/2026-06-24/wo-x/outputs/sample-baiyin-cells.csv
|
||||
./bin/wordtable2sqlite export-cells -db report.sqlite -out report-cells.csv
|
||||
```
|
||||
|
||||
## 12. 开发者验证
|
||||
|
||||
如果需要从源码编译或修改代码,使用:
|
||||
|
||||
```bash
|
||||
go test ./...
|
||||
go vet ./...
|
||||
go build -o bin/wordtable2sqlite .
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user