From cb5d7d0768c18c92df42e2a3e848e86c949ac65b Mon Sep 17 00:00:00 2001 From: macro Date: Sun, 26 Apr 2026 01:01:51 +0800 Subject: [PATCH] =?UTF-8?q?docs(README):=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E6=B7=BB=E5=8A=A0=E6=8D=A2=E8=A1=8C=E7=AC=A6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加换行符支持特性说明 - 新增换行符使用示例和常见问题解答 - 扩展技术细节中的换行符智能处理说明 - 更新注意事项中关于换行处理的内容 - 添加多行文本处理的使用示例 --- dexcel/README.md | 83 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/dexcel/README.md b/dexcel/README.md index 1784234..fb4845d 100644 --- a/dexcel/README.md +++ b/dexcel/README.md @@ -22,6 +22,7 @@ - 📤 **表格输出**: query 以美观的表格格式显示数据 - 📅 **日期智能**: 自动识别和格式化日期时间单元格 - 🧹 **备份清理**: 操作成功后自动删除 .bak 备份文件 +- ↩️ **换行支持**: 智能处理各种换行符格式,自动开启换行并调整行高 ## 📦 安装 @@ -134,6 +135,18 @@ dexcel data.xlsx insert "数据" --sheet "Sheet2" **注意**:insert 命令要求文件必须已存在,如果文件不存在会报错。 +**换行符支持**: +```bash +# 使用字面量 \n(单引号) +dexcel data.xlsx insert '第一行\n第二行\n第三行|其他列' + +# 使用 PowerShell 转义(双引号 + `r`n) +dexcel data.xlsx insert "Line1`r`nLine2,Col2" --split "," + +# 自动开启换行并调整行高 +# 无需手动设置,程序会自动检测换行符并调整 +``` + ### 4. 更新数据 (update) ```bash @@ -157,6 +170,15 @@ dexcel data.xlsx update "新值" --row 1 --sheet "Sheet2" - `--sheet `: Sheet 名称(可选) - `--split `: 分隔符(默认 |) +**换行符支持**: +```bash +# 更新单元格为多行文本 +dexcel data.xlsx update '新内容\n带换行' --row 5 + +# 自动开启换行并调整行高 +dexcel data.xlsx update "Line1`nLine2" --row 3 --split "," +``` + ### 5. 删除数据 (delete) ```bash @@ -318,6 +340,24 @@ dexcel data.xlsx style --rows 1 2 3 --cols 1 2 --row-height 25 --col-width 15 -- dexcel data.xlsx style --rows 1 --row-height 20 --sheet "Sheet2" ``` +### 示例 7: 处理多行文本 + +```bash +# 插入带换行的内容(单引号中使用 \n) +dexcel data.xlsx insert '地址:北京市\n朝阳区\n建国路100号|备注' + +# 使用 PowerShell 转义符(双引号中使用 `r`n) +dexcel data.xlsx insert "Line1`r`nLine2`r`nLine3,Col2" --split "," + +# 更新为多行文本 +dexcel data.xlsx update '说明:第一项\n说明:第二项' --row 2 + +# 程序会自动: +# 1. 识别并转换所有换行格式(\r\n, \n, `r`n) +# 2. 开启单元格的自动换行功能 +# 3. 根据行数自动调整行高(每行约15磅) +``` + ## 📊 输出格式 ### query 输出(表格格式) @@ -405,6 +445,12 @@ dexcel data.xlsx style --rows 1 --row-height 20 --sheet "Sheet2" - 所有数据都作为字符串写入 - 日期时间自动识别并转换为 Excel 序列号 - 样式完全保留 +- **换行符智能处理**: + - 真正的 `\r\n` (ASCII 13+10) → 转换为 `\n` + - 字面量 `\r\n` (4个字符) → 转换为 `\n` + - 字面量 `\n` (2个字符) → 转换为 `\n` + - 自动开启单元格自动换行 + - 自动调整行高(每行约15磅) ## ⚠️ 注意事项 @@ -419,6 +465,7 @@ dexcel data.xlsx style --rows 1 --row-height 20 --sheet "Sheet2" 9. **备份清理**: 操作成功后自动删除 .bak 备份文件 10. **不可撤销**: delete 操作不可撤销,请谨慎操作! 11. **样式设置**: style 命令可设置行高、列宽、自动换行等样式 +12. **换行处理**: insert/update 自动处理换行符,开启自动换行并调整行高 ### 限制 @@ -491,6 +538,42 @@ if ((dexcel data.xlsx count) -gt 100) { dexcel data.xlsx delete 5 --count 3 -y ``` +### Q8: 如何处理多行文本? + +**方法 1: 使用单引号 + 字面量 \n** +```bash +dexcel data.xlsx insert '第一行\n第二行\n第三行' +``` + +**方法 2: 使用 PowerShell 双引号 + `` `r`n ``** +```powershell +dexcel data.xlsx insert "Line1`r`nLine2`r`nLine3" +``` + +**方法 3: 使用 Bash/Shell** +```bash +dexcel data.xlsx insert $'Line1\nLine2\nLine3' +``` + +程序会自动: +- ✅ 识别并转换所有换行格式 +- ✅ 开启单元格自动换行 +- ✅ 根据行数自动调整行高(每行约15磅) +- ✅ 保留原有样式不变 + +### Q9: 行高会自动调整吗? + +是的!当检测到单元格包含换行符时,程序会: +1. 计算行数(换行符数量 + 1) +2. 估算所需行高(每行约15磅) +3. 只在当前行高小于估算值时才调整 +4. 不会覆盖用户手动设置的行高 + +如果需要精确控制行高,可以使用 style 命令: +```bash +dexcel data.xlsx style --rows 5 --row-height 50 +``` + ## 🎯 应用场景 ### 1. 数据预览