普贤教程 › 包参考
xlsx 包
最小 .xlsx 写器 + 读器 · 0.2.0
| 项 | 值 |
|---|---|
| 包名 | xlsx |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | xlsx.px |
| 分类 | 数据格式与编解码 |
| 文件数 / 行数 | 2 / 514 |
安装与引入
bash
pxpkg init # 首次 pxpkg add xlsx@0.2.0 pxpkg install
px
import xlsx所属分类教程:数据格式与编解码
公开接口
| 函数 | 参数 |
|---|---|
xsx_new | |
xsx_style | doc, name, opts |
xsx_add | doc, name, rows |
xsx_write | doc, path |
xsx_read_sheet | path, idx |
xsx_read | path |
其余 25 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
xsx_col_letter | idx |
xsx_parts | doc |
o_col_letters | ref |
o_col_idx | letter |
o_el_child | el, name |
o_el_text | el |
o_has_file | dir, name |
o_parse_shared | xml |
o_has_dot | v |
o_cell_val_parse | c, shared |
o_cell_val | c, shared |
o_parse_sheet | xml, shared |
xp_esc | s |
xp_is_num | c |
xsx_col_letter_ns | idx |
xp_font_xml | opts |
xp_fill_xml | opts |
xp_styles_plan | styles |
xp_cell_fields | cell |
xp_cell | cell, col, row, styles_idx |
xp_worksheet | rows, styles_idx |
xp_content_types | sheets |
xp_root_rels | |
xp_workbook | sheets |
xp_workbook_rels | sheets |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/xlsx —— 最小 .xlsx 写器 + 读器 · 0.2.0 ------------------------------------------------------------ 纯函数库(构建 parts 无 IO;写出时调 zip_pack),双模式验证 (zip 族 M201 已修复:m204 解释轨 zip_pack/zip_unpack 可用)。 对齐 Python openpyxl / Rust rust_xlsxwriter 心智: xsx_new() → dict 新建文档(无工作表) xsx_style(doc, name, opts) → dict 注册命名样式(返回新 doc) opts = {"bold": true, "italic": true, "underline": true, "color": "FF0000", "fill": "FFFF00", "size": 14, "align": "left|center|right", "valign": "top|center|bottom"} xsx_add(doc, name, rows) → dict 追加工作表(返回新 doc) cell = str(inlineStr)| int/float(数字)| bool | null(空单元格) | {"v": 值, "style": "样式名"} (带样式) | {"f": "SUM(A1:A2)", "v": 175, "style": "bold"}(公式单元格) xsx_write(doc, path) → Ok | Err 写出 .xlsx(zip_pack) xsx_read(path) / xsx_read_sheet(path, idx) → Ok(rows) 公式单元格读回 → {"f": 公式, "v": 缓存值} 结构:Content_Types + rels + workbook + 每个 worksheet + 动态 styles (fonts/fills/cellXfs 按命名样式生成,单元格 s="xf 索引")。 ============================================================