FreeWork


NameFreeWork JSON
Version 1.0.10 PyPI version JSON
download
home_pageNone
Summary简单又实用的office操作函数!(Simple and practical office operation functions!)
upload_time2025-08-14 03:50:12
maintainerNone
docs_urlNone
authorJhonie King(王骏诚)
requires_pythonNone
licenseMIT License
keywords python office excle word file's operation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ★ 关于FreeWork的相关介绍 (Introduction for FreeWork)★

*本文档为中英双语文档,其中括号内的为中文部分的英语译文,其二者内容相同。(This document is a bilingual document in Chinese and English, with the English translation of the Chinese part enclosed in parentheses, both of which have the same content.)*

函数目录 (List of Functions)
=============================

· 文件名和父路径获取函数 / File Name and Parent Folder Functions
------------------------------------------------------------------

- **fileName(FilePath)**
  获取给定路径所指向文件的文件名。
  (Get the file name from a given file path.)

- **fileFatherPath(FilePath)**
  获取给定路径所指向文件的父文件夹路径。
  (Get the parent folder path from a given file path.)

· 文件复制与剪切函数 / File Copy and Move Functions
---------------------------------------------------

- **copyFile(FileOriginalPath, FileNewPath)**
  复制文件,支持相对或绝对路径,自动创建目标文件夹。
  (Copy files with support of relative or absolute paths; create target folder automatically.)

- **moveFile(FileOriginalPath, FileNewPath)**
  剪切(移动)文件,支持相对或绝对路径,自动创建目标文件夹。
  (Move files with support for relative or absolute paths; auto-create target folder.)

· Excel读写函数 / Excel Read and Write Functions
--------------------------------------------------

- **excleRead(ExclePath, SheetIndex, Rowlow, Rowmax, Collow, Colmax)**
  读取指定Excel工作簿、指定工作表中指定行列范围数据(起始均从1)。返回二维列表或者一维列表,单元格数据保持原型。
  (Read specified Excel sheet and range data starting from 1-based indices; returns list of lists or list.)

- **excleWrite(ExclePath, SheetIndex, Row, Col, Value, SaveAsNewFile)**
  向指定Excel单元格写入数据,可选择覆盖原文件或另存为新文件。行列均从1开始。
  (Write data at specified Excel cell, support save as new file or overwrite.)

· Word表格操作函数 / Word Table Functions
-------------------------------------------

- **wordTableRead(WordPath, TableIndex)**
  读取Word文档中指定索引表格的所有单元格数据(表格索引从1开始)。返回二维列表。
  (Read all cell data from a Word table by index, returns list of lists.)

- **wordTableWrite(WordPath, TableIndex, Row, Col, Text, SaveAsNewFile)**
  向Word表格指定单元格写入文本,支持插入格式化的上下标(需英文括号标记),支持是否保存为新文件。
  (Write text to Word table cell; supports superscript/subscript markers ^() _(); save as new file or not.)

- **wordTableInsertFig(WordPath, TableIndex, Row, Col, ImagePath, ImageHeight_cm, ImageWidth_cm, SaveAsNewFile)**
  向Word指定表格单元格追加图片(不删除原文字),支持指定图片高度和宽度(厘米为单位),可保存新文件或覆盖。
  (Append image to Word table cell without deleting text; size optional; save options.)

- **wordTableParaAlignment(WordPath, TableIndex, Row, Col, Alignment_left_right_center_None, SaveAsNewFile)**
  设置Word表格单元格内段落的对齐方式,只支持 left/right/center/None。可另存新文件或覆盖。
  (Set paragraph alignment inside Word table cell; options left, right, center, none.)

- **wordTableWriteExtend(WordPath, TableIndex, Row, Col, Text, StyleName=None, Alignment=None)**
  兼容扩展写入,自动按需新增行复制上一行格式,支持段落样式与对齐设置。
  (Extended write: auto-add rows with copied format; support paragraph styles and alignment.)

- **wordDeleteTable(WordPath, TableIndex)**
  删除指定索引的表格,并覆盖保存Word文件。
  (Delete specified table by index and overwrite Word file.)

- **wordDeleteTableRow(WordPath, TableIndex, RowIndex)**
  删除Word文档中指定表格的指定行,并覆盖保存文档。
  (Delete specified row from table in Word file and overwrite.)

· Word段落操作函数 / Word Paragraph Functions
-----------------------------------------------

- **wordAdd(wordPath, wordSavePath, new_text, FontName=None, FontSize=None, IsBold=None, IsItalic=None)**
  在文档末尾追加文本(同段落),支持设置字体、字号、加粗、斜体。
  (Append text at document end inline; support font name, size, bold, italic.)

- **wordParagraphAdd(wordPath, wordSavePath, new_text, FontName=None, FontSize=None, IsBold=None, IsItalic=None, Indent=None, Alignment="l")**
  在文档末尾新建段落插入文本,支持字体、字号、加粗、斜体、首行缩进及段落对齐。
  (Add new paragraph at document end with text; supports font, size, bold, italic, indent, alignment.)

- **wordParaFormat(wordPath)**
  获取文档最后一段的段落格式对象。
  (Get paragraph format object of the last paragraph in document.)

- **insert_paragraph_after(paragraph, text=None, style=None)**
  在指定段落后插入新段落,支持传入文本和样式名,返回新段落对象。
  (Insert new paragraph after specified paragraph, optional text and style.)

- **wordInsertText(WordPath, Text, ParaIndex, NewParagraph=True, StyleName=None)**
  在指定.docx文件指定段落(索引从0起)后插入文本,新建段落或追加文本可选,支持样式,文档空时自动创建第一段。
  (Insert text after specified paragraph index in Word; new paragraph or append; supports style; auto-create if empty.)

- **wordReplaceParagraphText(WordPath, Text, ParaIndex, StyleName=None)**
  替换Word文档指定段落所有文本,支持样式,越界自动调整,文档无段自动新建。
  (Replace all text of specified paragraph with style; index bounds checked; auto-create if empty.)

- **wordFindParagraphIndexesByMark(WordPath, MarkString)**
  返回包含指定字符串的所有段落索引列表(0开始)。
  (List paragraph indexes containing specified substring.)

- **wordFindParagraphTextsByMark(WordPath, MarkString)**
  返回所有包含指定子串的段落完整文本列表。
  (List paragraph texts containing substring.)

- **wordDeleteParagraph(WordPath, ParaIndex)**
  删除指定索引的段落,并覆盖保存Word文件。
  (Delete specified paragraph by index and overwrite Word file.)

· Word查找表格索引函数 / Word Table Index Finders
----------------------------------------------------

- **wordFindTableIndexByMark(WordPath, MarkRow, MarkString)**
  查找Word文档中所有在指定行(1起)包含指定标记字符串的表格索引列表。
  (Find all table indexes where specified row contains given string.)

- **wordFindCellsByMark(WordPath, MarkString)**
  查找Word文档中所有包含指定标记字符串的单元格,返回格式为 [表格索引, 行号, 列号](均从1开始)的列表。
  (Find all cells containing specified string, return list of [tableIndex, rowIndex, colIndex].)

· Shapefile转Excel函数 / Shapefile to Excel
---------------------------------------------

- **ShpToXlsx(ShpPath, XlsxPath)**
  利用fiona和pandas将Esri Shapefile中的属性表导出为Excel文件。
  (Export attribute table from Esri Shapefile to Excel file via fiona and pandas.)

· Word插入LaTeX公式函数 / Word Insert LaTeX Formula
-----------------------------------------------------

- **wordInsertLatexFormula(WordPath, ParaIndex, LatexCode, NewParagraph=True)**
  利用Spire.Doc在指定段落插入LaTeX数学公式,新建段落或追加可选。自动创建空段。
  (Insert LaTeX math formula at specified paragraph of Word using Spire.Doc library.)

· 新增函数 / New Functions
---------------------------

- **TextType (Enum)**

  定义文本类型的枚举,区分普通文本和公式。
  (Enumeration to distinguish text and formula types.)

- **parse_text_and_formula(text)**

  解析输入字符串,自动识别并拆分成普通文本和多种LaTeX数学公式(支持`$$...$$`、`$...$`、`\(...\)`和`\[...\]`标记),返回列表格式为 `[类型, 内容]`。

  (Parse input text to separate plain text and LaTeX formula parts, supporting common delimiters; returns list of [type, content].)

  :param text: 原始字符串 (Original string)
  :return: list,元素格式为 [[TextType.Text or TextType.Formula, 内容], ...] (List of parsed segments with type and content)

---

安装 (Installation)
===================

.. code:: bash

    pip install FreeWork

使用示例 (Usage Examples)
==========================

.. code:: python

    from FreeWork import office as ow
    from FreeWork import TextType
    from docx.shared import Pt
    from docx.enum.text import WD_ALIGN_PARAGRAPH

    # 复制文件
    ow.copyFile("source.png", "dest/new_source.png")

    # 移动文件
    ow.moveFile("source.txt", "dest/new_source.txt")

    # 读取Excel数据
    data = ow.excleRead("example.xlsx", SheetIndex=1, Rowlow=2, Rowmax=5, Collow=3, Colmax=7)

    # Excel写数据
    ow.excleWrite("example.xlsx", SheetIndex=1, Row=3, Col=4, Value="测试值", SaveAsNewFile=True)

    # 读取Word表格
    table_data = ow.wordTableRead("doc.docx", TableIndex=1)

    # 写Word表格带上下标文本
    ow.wordTableWrite("doc.docx", TableIndex=1, Row=2, Col=3, Text="面积 S_(1)=123 hm^(2)", SaveAsNewFile=False)

    # 向Word表格添加图片
    ow.wordTableInsertFig("doc.docx", TableIndex=1, Row=1, Col=2, ImagePath="img.png", ImageHeight_cm=5, ImageWidth_cm=None, SaveAsNewFile=True)

    # Word表格单元格对齐
    ow.wordTableParaAlignment("doc.docx", TableIndex=1, Row=1, Col=2, Alignment_left_right_center_None="center", SaveAsNewFile=False)

    # 新段落插入文字
    ow.wordInsertText("doc.docx", "新内容", ParaIndex=2, NewParagraph=True, StyleName="Normal")

    # 替换段落文本
    ow.wordReplaceParagraphText("doc.docx", Text="替换内容", ParaIndex=5, StyleName="Normal")

    # 查找包含标记的表格索引
    indexes = ow.wordFindTableIndexByMark("doc.docx", MarkRow=1, MarkString="关键字")

    # 查找包含标记的段落索引
    para_indexes = ow.wordFindParagraphIndexesByMark("doc.docx", "关键字")

    # 查找包含标记的段落文本
    texts = ow.wordFindParagraphTextsByMark("doc.docx", "关键字")

    # 查找包含标记的单元格坐标列表
    cell_positions = ow.wordFindCellsByMark("doc.docx", "关键字")

    # Shapefile转Excel
    ow.ShpToXlsx("example.shp", "output.xlsx")

    # Word文档末尾追加文字(同段)
    ow.wordAdd("doc.docx", "doc_modified.docx", "追加文字", FontName="宋体", FontSize=Pt(12), IsBold=True, IsItalic=False)

    # Word文档末尾添加新段落
    ow.wordParagraphAdd("doc.docx", "doc_modified.docx", "新段落文字", FontName="Calibri", FontSize=Pt(11), IsBold=False, IsItalic=False, Indent=None, Alignment="j")

    # 向指定单元格扩展写入,自动新增行
    ow.wordTableWriteExtend(
        WordPath="doc.docx",
        TableIndex=1,
        Row=10,
        Col=1,
        Text="延伸写入",
        StyleName="Normal",
        Alignment=WD_ALIGN_PARAGRAPH.CENTER
    )

    # 删除指定段落
    ow.wordDeleteParagraph("doc.docx", ParaIndex=3)

    # 删除指定表格
    ow.wordDeleteTable("doc.docx", TableIndex=2)

    # 删除指定表格行
    ow.wordDeleteTableRow("doc.docx", TableIndex=1, RowIndex=4)

    # 插入LaTeX公式
    latex_code = r"\frac{a}{b} = \sqrt{c}"
    ow.wordInsertLatexFormula("doc.docx", ParaIndex=5, LatexCode=latex_code, NewParagraph=True)

    # 使用parse_text_and_formula函数解析文本和公式
    text = "这是文本 $y=x^2+x+1$,还有公式 $$\\frac{a}{b}=c$$。"
    parsed = ow.parse_text_and_formula(text)
    for ttype, content in parsed:
        if ttype == TextType.Text:
            print("[文本]", content)
        else:
            print("[公式]", content)

---

备注与注意事项
==============

- 所有的Word操作会将段落的字体等恢复到样式默认大小,因此修改模版时请直接修改“样式”,不要直接改字体大小
- 所有文件路径均支持相对和绝对路径,路径必须包含文件名及扩展名。
- 行列及索引均从1开始(段落索引除外,特定函数中段落索引为0开始)。
- Word表格中合并单元格影响行列索引的语义,请根据实际合并情况调整参数。
- 上标和下标文本的标记语法需严格使用英文括号:“^()” 表示上标,“_()” 表示下标。
- 对段落字体大小设置参数,需传入 `docx.shared.Pt` 或 `docx.shared.Length` 类型对象,示例中的数值为示意,使用时请注意转换。
- 插入LaTeX公式需要 `spire.doc` 库,安装及使用请参考官方文档。

联系我们
========

如遇任何问题或者功能建议,请通过下列方式联系作者:

- 称呼:王先生 (Name: Jhonie)
- E-mail: queenelsaofarendelle2022@gmail.com / 2570518164@qq.com
- QQ:2570518164

---

感谢使用 FreeWork 办公自动化工具包!欢迎反馈与交流。



            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "FreeWork",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, Office, Excle, Word, File's operation",
    "author": "Jhonie King(\u738b\u9a8f\u8bda)",
    "author_email": "queenelsaofarendelle2022@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/49/99/4e20c5c8c004ab3d794fc1918d9e3982b070c7cda745f1ed6b9133a99aea/FreeWork-1.0.10.zip",
    "platform": null,
    "description": "\u2605 \u5173\u4e8eFreeWork\u7684\u76f8\u5173\u4ecb\u7ecd (Introduction for FreeWork)\u2605\r\n\r\n*\u672c\u6587\u6863\u4e3a\u4e2d\u82f1\u53cc\u8bed\u6587\u6863\uff0c\u5176\u4e2d\u62ec\u53f7\u5185\u7684\u4e3a\u4e2d\u6587\u90e8\u5206\u7684\u82f1\u8bed\u8bd1\u6587\uff0c\u5176\u4e8c\u8005\u5185\u5bb9\u76f8\u540c\u3002(This document is a bilingual document in Chinese and English, with the English translation of the Chinese part enclosed in parentheses, both of which have the same content.)*\r\n\r\n\u51fd\u6570\u76ee\u5f55 (List of Functions)\r\n=============================\r\n\r\n\u00b7 \u6587\u4ef6\u540d\u548c\u7236\u8def\u5f84\u83b7\u53d6\u51fd\u6570 / File Name and Parent Folder Functions\r\n------------------------------------------------------------------\r\n\r\n- **fileName(FilePath)**\r\n  \u83b7\u53d6\u7ed9\u5b9a\u8def\u5f84\u6240\u6307\u5411\u6587\u4ef6\u7684\u6587\u4ef6\u540d\u3002\r\n  (Get the file name from a given file path.)\r\n\r\n- **fileFatherPath(FilePath)**\r\n  \u83b7\u53d6\u7ed9\u5b9a\u8def\u5f84\u6240\u6307\u5411\u6587\u4ef6\u7684\u7236\u6587\u4ef6\u5939\u8def\u5f84\u3002\r\n  (Get the parent folder path from a given file path.)\r\n\r\n\u00b7 \u6587\u4ef6\u590d\u5236\u4e0e\u526a\u5207\u51fd\u6570 / File Copy and Move Functions\r\n---------------------------------------------------\r\n\r\n- **copyFile(FileOriginalPath, FileNewPath)**\r\n  \u590d\u5236\u6587\u4ef6\uff0c\u652f\u6301\u76f8\u5bf9\u6216\u7edd\u5bf9\u8def\u5f84\uff0c\u81ea\u52a8\u521b\u5efa\u76ee\u6807\u6587\u4ef6\u5939\u3002\r\n  (Copy files with support of relative or absolute paths; create target folder automatically.)\r\n\r\n- **moveFile(FileOriginalPath, FileNewPath)**\r\n  \u526a\u5207\uff08\u79fb\u52a8\uff09\u6587\u4ef6\uff0c\u652f\u6301\u76f8\u5bf9\u6216\u7edd\u5bf9\u8def\u5f84\uff0c\u81ea\u52a8\u521b\u5efa\u76ee\u6807\u6587\u4ef6\u5939\u3002\r\n  (Move files with support for relative or absolute paths; auto-create target folder.)\r\n\r\n\u00b7 Excel\u8bfb\u5199\u51fd\u6570 / Excel Read and Write Functions\r\n--------------------------------------------------\r\n\r\n- **excleRead(ExclePath, SheetIndex, Rowlow, Rowmax, Collow, Colmax)**\r\n  \u8bfb\u53d6\u6307\u5b9aExcel\u5de5\u4f5c\u7c3f\u3001\u6307\u5b9a\u5de5\u4f5c\u8868\u4e2d\u6307\u5b9a\u884c\u5217\u8303\u56f4\u6570\u636e\uff08\u8d77\u59cb\u5747\u4ece1\uff09\u3002\u8fd4\u56de\u4e8c\u7ef4\u5217\u8868\u6216\u8005\u4e00\u7ef4\u5217\u8868\uff0c\u5355\u5143\u683c\u6570\u636e\u4fdd\u6301\u539f\u578b\u3002\r\n  (Read specified Excel sheet and range data starting from 1-based indices; returns list of lists or list.)\r\n\r\n- **excleWrite(ExclePath, SheetIndex, Row, Col, Value, SaveAsNewFile)**\r\n  \u5411\u6307\u5b9aExcel\u5355\u5143\u683c\u5199\u5165\u6570\u636e\uff0c\u53ef\u9009\u62e9\u8986\u76d6\u539f\u6587\u4ef6\u6216\u53e6\u5b58\u4e3a\u65b0\u6587\u4ef6\u3002\u884c\u5217\u5747\u4ece1\u5f00\u59cb\u3002\r\n  (Write data at specified Excel cell, support save as new file or overwrite.)\r\n\r\n\u00b7 Word\u8868\u683c\u64cd\u4f5c\u51fd\u6570 / Word Table Functions\r\n-------------------------------------------\r\n\r\n- **wordTableRead(WordPath, TableIndex)**\r\n  \u8bfb\u53d6Word\u6587\u6863\u4e2d\u6307\u5b9a\u7d22\u5f15\u8868\u683c\u7684\u6240\u6709\u5355\u5143\u683c\u6570\u636e\uff08\u8868\u683c\u7d22\u5f15\u4ece1\u5f00\u59cb\uff09\u3002\u8fd4\u56de\u4e8c\u7ef4\u5217\u8868\u3002\r\n  (Read all cell data from a Word table by index, returns list of lists.)\r\n\r\n- **wordTableWrite(WordPath, TableIndex, Row, Col, Text, SaveAsNewFile)**\r\n  \u5411Word\u8868\u683c\u6307\u5b9a\u5355\u5143\u683c\u5199\u5165\u6587\u672c\uff0c\u652f\u6301\u63d2\u5165\u683c\u5f0f\u5316\u7684\u4e0a\u4e0b\u6807\uff08\u9700\u82f1\u6587\u62ec\u53f7\u6807\u8bb0\uff09\uff0c\u652f\u6301\u662f\u5426\u4fdd\u5b58\u4e3a\u65b0\u6587\u4ef6\u3002\r\n  (Write text to Word table cell; supports superscript/subscript markers ^() _(); save as new file or not.)\r\n\r\n- **wordTableInsertFig(WordPath, TableIndex, Row, Col, ImagePath, ImageHeight_cm, ImageWidth_cm, SaveAsNewFile)**\r\n  \u5411Word\u6307\u5b9a\u8868\u683c\u5355\u5143\u683c\u8ffd\u52a0\u56fe\u7247\uff08\u4e0d\u5220\u9664\u539f\u6587\u5b57\uff09\uff0c\u652f\u6301\u6307\u5b9a\u56fe\u7247\u9ad8\u5ea6\u548c\u5bbd\u5ea6\uff08\u5398\u7c73\u4e3a\u5355\u4f4d\uff09\uff0c\u53ef\u4fdd\u5b58\u65b0\u6587\u4ef6\u6216\u8986\u76d6\u3002\r\n  (Append image to Word table cell without deleting text; size optional; save options.)\r\n\r\n- **wordTableParaAlignment(WordPath, TableIndex, Row, Col, Alignment_left_right_center_None, SaveAsNewFile)**\r\n  \u8bbe\u7f6eWord\u8868\u683c\u5355\u5143\u683c\u5185\u6bb5\u843d\u7684\u5bf9\u9f50\u65b9\u5f0f\uff0c\u53ea\u652f\u6301 left/right/center/None\u3002\u53ef\u53e6\u5b58\u65b0\u6587\u4ef6\u6216\u8986\u76d6\u3002\r\n  (Set paragraph alignment inside Word table cell; options left, right, center, none.)\r\n\r\n- **wordTableWriteExtend(WordPath, TableIndex, Row, Col, Text, StyleName=None, Alignment=None)**\r\n  \u517c\u5bb9\u6269\u5c55\u5199\u5165\uff0c\u81ea\u52a8\u6309\u9700\u65b0\u589e\u884c\u590d\u5236\u4e0a\u4e00\u884c\u683c\u5f0f\uff0c\u652f\u6301\u6bb5\u843d\u6837\u5f0f\u4e0e\u5bf9\u9f50\u8bbe\u7f6e\u3002\r\n  (Extended write: auto-add rows with copied format; support paragraph styles and alignment.)\r\n\r\n- **wordDeleteTable(WordPath, TableIndex)**\r\n  \u5220\u9664\u6307\u5b9a\u7d22\u5f15\u7684\u8868\u683c\uff0c\u5e76\u8986\u76d6\u4fdd\u5b58Word\u6587\u4ef6\u3002\r\n  (Delete specified table by index and overwrite Word file.)\r\n\r\n- **wordDeleteTableRow(WordPath, TableIndex, RowIndex)**\r\n  \u5220\u9664Word\u6587\u6863\u4e2d\u6307\u5b9a\u8868\u683c\u7684\u6307\u5b9a\u884c\uff0c\u5e76\u8986\u76d6\u4fdd\u5b58\u6587\u6863\u3002\r\n  (Delete specified row from table in Word file and overwrite.)\r\n\r\n\u00b7 Word\u6bb5\u843d\u64cd\u4f5c\u51fd\u6570 / Word Paragraph Functions\r\n-----------------------------------------------\r\n\r\n- **wordAdd(wordPath, wordSavePath, new_text, FontName=None, FontSize=None, IsBold=None, IsItalic=None)**\r\n  \u5728\u6587\u6863\u672b\u5c3e\u8ffd\u52a0\u6587\u672c\uff08\u540c\u6bb5\u843d\uff09\uff0c\u652f\u6301\u8bbe\u7f6e\u5b57\u4f53\u3001\u5b57\u53f7\u3001\u52a0\u7c97\u3001\u659c\u4f53\u3002\r\n  (Append text at document end inline; support font name, size, bold, italic.)\r\n\r\n- **wordParagraphAdd(wordPath, wordSavePath, new_text, FontName=None, FontSize=None, IsBold=None, IsItalic=None, Indent=None, Alignment=\"l\")**\r\n  \u5728\u6587\u6863\u672b\u5c3e\u65b0\u5efa\u6bb5\u843d\u63d2\u5165\u6587\u672c\uff0c\u652f\u6301\u5b57\u4f53\u3001\u5b57\u53f7\u3001\u52a0\u7c97\u3001\u659c\u4f53\u3001\u9996\u884c\u7f29\u8fdb\u53ca\u6bb5\u843d\u5bf9\u9f50\u3002\r\n  (Add new paragraph at document end with text; supports font, size, bold, italic, indent, alignment.)\r\n\r\n- **wordParaFormat(wordPath)**\r\n  \u83b7\u53d6\u6587\u6863\u6700\u540e\u4e00\u6bb5\u7684\u6bb5\u843d\u683c\u5f0f\u5bf9\u8c61\u3002\r\n  (Get paragraph format object of the last paragraph in document.)\r\n\r\n- **insert_paragraph_after(paragraph, text=None, style=None)**\r\n  \u5728\u6307\u5b9a\u6bb5\u843d\u540e\u63d2\u5165\u65b0\u6bb5\u843d\uff0c\u652f\u6301\u4f20\u5165\u6587\u672c\u548c\u6837\u5f0f\u540d\uff0c\u8fd4\u56de\u65b0\u6bb5\u843d\u5bf9\u8c61\u3002\r\n  (Insert new paragraph after specified paragraph, optional text and style.)\r\n\r\n- **wordInsertText(WordPath, Text, ParaIndex, NewParagraph=True, StyleName=None)**\r\n  \u5728\u6307\u5b9a.docx\u6587\u4ef6\u6307\u5b9a\u6bb5\u843d\uff08\u7d22\u5f15\u4ece0\u8d77\uff09\u540e\u63d2\u5165\u6587\u672c\uff0c\u65b0\u5efa\u6bb5\u843d\u6216\u8ffd\u52a0\u6587\u672c\u53ef\u9009\uff0c\u652f\u6301\u6837\u5f0f\uff0c\u6587\u6863\u7a7a\u65f6\u81ea\u52a8\u521b\u5efa\u7b2c\u4e00\u6bb5\u3002\r\n  (Insert text after specified paragraph index in Word; new paragraph or append; supports style; auto-create if empty.)\r\n\r\n- **wordReplaceParagraphText(WordPath, Text, ParaIndex, StyleName=None)**\r\n  \u66ff\u6362Word\u6587\u6863\u6307\u5b9a\u6bb5\u843d\u6240\u6709\u6587\u672c\uff0c\u652f\u6301\u6837\u5f0f\uff0c\u8d8a\u754c\u81ea\u52a8\u8c03\u6574\uff0c\u6587\u6863\u65e0\u6bb5\u81ea\u52a8\u65b0\u5efa\u3002\r\n  (Replace all text of specified paragraph with style; index bounds checked; auto-create if empty.)\r\n\r\n- **wordFindParagraphIndexesByMark(WordPath, MarkString)**\r\n  \u8fd4\u56de\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6240\u6709\u6bb5\u843d\u7d22\u5f15\u5217\u8868\uff080\u5f00\u59cb\uff09\u3002\r\n  (List paragraph indexes containing specified substring.)\r\n\r\n- **wordFindParagraphTextsByMark(WordPath, MarkString)**\r\n  \u8fd4\u56de\u6240\u6709\u5305\u542b\u6307\u5b9a\u5b50\u4e32\u7684\u6bb5\u843d\u5b8c\u6574\u6587\u672c\u5217\u8868\u3002\r\n  (List paragraph texts containing substring.)\r\n\r\n- **wordDeleteParagraph(WordPath, ParaIndex)**\r\n  \u5220\u9664\u6307\u5b9a\u7d22\u5f15\u7684\u6bb5\u843d\uff0c\u5e76\u8986\u76d6\u4fdd\u5b58Word\u6587\u4ef6\u3002\r\n  (Delete specified paragraph by index and overwrite Word file.)\r\n\r\n\u00b7 Word\u67e5\u627e\u8868\u683c\u7d22\u5f15\u51fd\u6570 / Word Table Index Finders\r\n----------------------------------------------------\r\n\r\n- **wordFindTableIndexByMark(WordPath, MarkRow, MarkString)**\r\n  \u67e5\u627eWord\u6587\u6863\u4e2d\u6240\u6709\u5728\u6307\u5b9a\u884c\uff081\u8d77\uff09\u5305\u542b\u6307\u5b9a\u6807\u8bb0\u5b57\u7b26\u4e32\u7684\u8868\u683c\u7d22\u5f15\u5217\u8868\u3002\r\n  (Find all table indexes where specified row contains given string.)\r\n\r\n- **wordFindCellsByMark(WordPath, MarkString)**\r\n  \u67e5\u627eWord\u6587\u6863\u4e2d\u6240\u6709\u5305\u542b\u6307\u5b9a\u6807\u8bb0\u5b57\u7b26\u4e32\u7684\u5355\u5143\u683c\uff0c\u8fd4\u56de\u683c\u5f0f\u4e3a [\u8868\u683c\u7d22\u5f15, \u884c\u53f7, \u5217\u53f7]\uff08\u5747\u4ece1\u5f00\u59cb\uff09\u7684\u5217\u8868\u3002\r\n  (Find all cells containing specified string, return list of [tableIndex, rowIndex, colIndex].)\r\n\r\n\u00b7 Shapefile\u8f6cExcel\u51fd\u6570 / Shapefile to Excel\r\n---------------------------------------------\r\n\r\n- **ShpToXlsx(ShpPath, XlsxPath)**\r\n  \u5229\u7528fiona\u548cpandas\u5c06Esri Shapefile\u4e2d\u7684\u5c5e\u6027\u8868\u5bfc\u51fa\u4e3aExcel\u6587\u4ef6\u3002\r\n  (Export attribute table from Esri Shapefile to Excel file via fiona and pandas.)\r\n\r\n\u00b7 Word\u63d2\u5165LaTeX\u516c\u5f0f\u51fd\u6570 / Word Insert LaTeX Formula\r\n-----------------------------------------------------\r\n\r\n- **wordInsertLatexFormula(WordPath, ParaIndex, LatexCode, NewParagraph=True)**\r\n  \u5229\u7528Spire.Doc\u5728\u6307\u5b9a\u6bb5\u843d\u63d2\u5165LaTeX\u6570\u5b66\u516c\u5f0f\uff0c\u65b0\u5efa\u6bb5\u843d\u6216\u8ffd\u52a0\u53ef\u9009\u3002\u81ea\u52a8\u521b\u5efa\u7a7a\u6bb5\u3002\r\n  (Insert LaTeX math formula at specified paragraph of Word using Spire.Doc library.)\r\n\r\n\u00b7 \u65b0\u589e\u51fd\u6570 / New Functions\r\n---------------------------\r\n\r\n- **TextType (Enum)**\r\n\r\n  \u5b9a\u4e49\u6587\u672c\u7c7b\u578b\u7684\u679a\u4e3e\uff0c\u533a\u5206\u666e\u901a\u6587\u672c\u548c\u516c\u5f0f\u3002\r\n  (Enumeration to distinguish text and formula types.)\r\n\r\n- **parse_text_and_formula(text)**\r\n\r\n  \u89e3\u6790\u8f93\u5165\u5b57\u7b26\u4e32\uff0c\u81ea\u52a8\u8bc6\u522b\u5e76\u62c6\u5206\u6210\u666e\u901a\u6587\u672c\u548c\u591a\u79cdLaTeX\u6570\u5b66\u516c\u5f0f\uff08\u652f\u6301`$$...$$`\u3001`$...$`\u3001`\\(...\\)`\u548c`\\[...\\]`\u6807\u8bb0\uff09\uff0c\u8fd4\u56de\u5217\u8868\u683c\u5f0f\u4e3a `[\u7c7b\u578b, \u5185\u5bb9]`\u3002\r\n\r\n  (Parse input text to separate plain text and LaTeX formula parts, supporting common delimiters; returns list of [type, content].)\r\n\r\n  :param text: \u539f\u59cb\u5b57\u7b26\u4e32 (Original string)\r\n  :return: list\uff0c\u5143\u7d20\u683c\u5f0f\u4e3a [[TextType.Text or TextType.Formula, \u5185\u5bb9], ...] (List of parsed segments with type and content)\r\n\r\n---\r\n\r\n\u5b89\u88c5 (Installation)\r\n===================\r\n\r\n.. code:: bash\r\n\r\n    pip install FreeWork\r\n\r\n\u4f7f\u7528\u793a\u4f8b (Usage Examples)\r\n==========================\r\n\r\n.. code:: python\r\n\r\n    from FreeWork import office as ow\r\n    from FreeWork import TextType\r\n    from docx.shared import Pt\r\n    from docx.enum.text import WD_ALIGN_PARAGRAPH\r\n\r\n    # \u590d\u5236\u6587\u4ef6\r\n    ow.copyFile(\"source.png\", \"dest/new_source.png\")\r\n\r\n    # \u79fb\u52a8\u6587\u4ef6\r\n    ow.moveFile(\"source.txt\", \"dest/new_source.txt\")\r\n\r\n    # \u8bfb\u53d6Excel\u6570\u636e\r\n    data = ow.excleRead(\"example.xlsx\", SheetIndex=1, Rowlow=2, Rowmax=5, Collow=3, Colmax=7)\r\n\r\n    # Excel\u5199\u6570\u636e\r\n    ow.excleWrite(\"example.xlsx\", SheetIndex=1, Row=3, Col=4, Value=\"\u6d4b\u8bd5\u503c\", SaveAsNewFile=True)\r\n\r\n    # \u8bfb\u53d6Word\u8868\u683c\r\n    table_data = ow.wordTableRead(\"doc.docx\", TableIndex=1)\r\n\r\n    # \u5199Word\u8868\u683c\u5e26\u4e0a\u4e0b\u6807\u6587\u672c\r\n    ow.wordTableWrite(\"doc.docx\", TableIndex=1, Row=2, Col=3, Text=\"\u9762\u79ef S_(1)=123 hm^(2)\", SaveAsNewFile=False)\r\n\r\n    # \u5411Word\u8868\u683c\u6dfb\u52a0\u56fe\u7247\r\n    ow.wordTableInsertFig(\"doc.docx\", TableIndex=1, Row=1, Col=2, ImagePath=\"img.png\", ImageHeight_cm=5, ImageWidth_cm=None, SaveAsNewFile=True)\r\n\r\n    # Word\u8868\u683c\u5355\u5143\u683c\u5bf9\u9f50\r\n    ow.wordTableParaAlignment(\"doc.docx\", TableIndex=1, Row=1, Col=2, Alignment_left_right_center_None=\"center\", SaveAsNewFile=False)\r\n\r\n    # \u65b0\u6bb5\u843d\u63d2\u5165\u6587\u5b57\r\n    ow.wordInsertText(\"doc.docx\", \"\u65b0\u5185\u5bb9\", ParaIndex=2, NewParagraph=True, StyleName=\"Normal\")\r\n\r\n    # \u66ff\u6362\u6bb5\u843d\u6587\u672c\r\n    ow.wordReplaceParagraphText(\"doc.docx\", Text=\"\u66ff\u6362\u5185\u5bb9\", ParaIndex=5, StyleName=\"Normal\")\r\n\r\n    # \u67e5\u627e\u5305\u542b\u6807\u8bb0\u7684\u8868\u683c\u7d22\u5f15\r\n    indexes = ow.wordFindTableIndexByMark(\"doc.docx\", MarkRow=1, MarkString=\"\u5173\u952e\u5b57\")\r\n\r\n    # \u67e5\u627e\u5305\u542b\u6807\u8bb0\u7684\u6bb5\u843d\u7d22\u5f15\r\n    para_indexes = ow.wordFindParagraphIndexesByMark(\"doc.docx\", \"\u5173\u952e\u5b57\")\r\n\r\n    # \u67e5\u627e\u5305\u542b\u6807\u8bb0\u7684\u6bb5\u843d\u6587\u672c\r\n    texts = ow.wordFindParagraphTextsByMark(\"doc.docx\", \"\u5173\u952e\u5b57\")\r\n\r\n    # \u67e5\u627e\u5305\u542b\u6807\u8bb0\u7684\u5355\u5143\u683c\u5750\u6807\u5217\u8868\r\n    cell_positions = ow.wordFindCellsByMark(\"doc.docx\", \"\u5173\u952e\u5b57\")\r\n\r\n    # Shapefile\u8f6cExcel\r\n    ow.ShpToXlsx(\"example.shp\", \"output.xlsx\")\r\n\r\n    # Word\u6587\u6863\u672b\u5c3e\u8ffd\u52a0\u6587\u5b57\uff08\u540c\u6bb5\uff09\r\n    ow.wordAdd(\"doc.docx\", \"doc_modified.docx\", \"\u8ffd\u52a0\u6587\u5b57\", FontName=\"\u5b8b\u4f53\", FontSize=Pt(12), IsBold=True, IsItalic=False)\r\n\r\n    # Word\u6587\u6863\u672b\u5c3e\u6dfb\u52a0\u65b0\u6bb5\u843d\r\n    ow.wordParagraphAdd(\"doc.docx\", \"doc_modified.docx\", \"\u65b0\u6bb5\u843d\u6587\u5b57\", FontName=\"Calibri\", FontSize=Pt(11), IsBold=False, IsItalic=False, Indent=None, Alignment=\"j\")\r\n\r\n    # \u5411\u6307\u5b9a\u5355\u5143\u683c\u6269\u5c55\u5199\u5165\uff0c\u81ea\u52a8\u65b0\u589e\u884c\r\n    ow.wordTableWriteExtend(\r\n        WordPath=\"doc.docx\",\r\n        TableIndex=1,\r\n        Row=10,\r\n        Col=1,\r\n        Text=\"\u5ef6\u4f38\u5199\u5165\",\r\n        StyleName=\"Normal\",\r\n        Alignment=WD_ALIGN_PARAGRAPH.CENTER\r\n    )\r\n\r\n    # \u5220\u9664\u6307\u5b9a\u6bb5\u843d\r\n    ow.wordDeleteParagraph(\"doc.docx\", ParaIndex=3)\r\n\r\n    # \u5220\u9664\u6307\u5b9a\u8868\u683c\r\n    ow.wordDeleteTable(\"doc.docx\", TableIndex=2)\r\n\r\n    # \u5220\u9664\u6307\u5b9a\u8868\u683c\u884c\r\n    ow.wordDeleteTableRow(\"doc.docx\", TableIndex=1, RowIndex=4)\r\n\r\n    # \u63d2\u5165LaTeX\u516c\u5f0f\r\n    latex_code = r\"\\frac{a}{b} = \\sqrt{c}\"\r\n    ow.wordInsertLatexFormula(\"doc.docx\", ParaIndex=5, LatexCode=latex_code, NewParagraph=True)\r\n\r\n    # \u4f7f\u7528parse_text_and_formula\u51fd\u6570\u89e3\u6790\u6587\u672c\u548c\u516c\u5f0f\r\n    text = \"\u8fd9\u662f\u6587\u672c $y=x^2+x+1$\uff0c\u8fd8\u6709\u516c\u5f0f $$\\\\frac{a}{b}=c$$\u3002\"\r\n    parsed = ow.parse_text_and_formula(text)\r\n    for ttype, content in parsed:\r\n        if ttype == TextType.Text:\r\n            print(\"[\u6587\u672c]\", content)\r\n        else:\r\n            print(\"[\u516c\u5f0f]\", content)\r\n\r\n---\r\n\r\n\u5907\u6ce8\u4e0e\u6ce8\u610f\u4e8b\u9879\r\n==============\r\n\r\n- \u6240\u6709\u7684Word\u64cd\u4f5c\u4f1a\u5c06\u6bb5\u843d\u7684\u5b57\u4f53\u7b49\u6062\u590d\u5230\u6837\u5f0f\u9ed8\u8ba4\u5927\u5c0f\uff0c\u56e0\u6b64\u4fee\u6539\u6a21\u7248\u65f6\u8bf7\u76f4\u63a5\u4fee\u6539\u201c\u6837\u5f0f\u201d\uff0c\u4e0d\u8981\u76f4\u63a5\u6539\u5b57\u4f53\u5927\u5c0f\r\n- \u6240\u6709\u6587\u4ef6\u8def\u5f84\u5747\u652f\u6301\u76f8\u5bf9\u548c\u7edd\u5bf9\u8def\u5f84\uff0c\u8def\u5f84\u5fc5\u987b\u5305\u542b\u6587\u4ef6\u540d\u53ca\u6269\u5c55\u540d\u3002\r\n- \u884c\u5217\u53ca\u7d22\u5f15\u5747\u4ece1\u5f00\u59cb\uff08\u6bb5\u843d\u7d22\u5f15\u9664\u5916\uff0c\u7279\u5b9a\u51fd\u6570\u4e2d\u6bb5\u843d\u7d22\u5f15\u4e3a0\u5f00\u59cb\uff09\u3002\r\n- Word\u8868\u683c\u4e2d\u5408\u5e76\u5355\u5143\u683c\u5f71\u54cd\u884c\u5217\u7d22\u5f15\u7684\u8bed\u4e49\uff0c\u8bf7\u6839\u636e\u5b9e\u9645\u5408\u5e76\u60c5\u51b5\u8c03\u6574\u53c2\u6570\u3002\r\n- \u4e0a\u6807\u548c\u4e0b\u6807\u6587\u672c\u7684\u6807\u8bb0\u8bed\u6cd5\u9700\u4e25\u683c\u4f7f\u7528\u82f1\u6587\u62ec\u53f7\uff1a\u201c^()\u201d \u8868\u793a\u4e0a\u6807\uff0c\u201c_()\u201d \u8868\u793a\u4e0b\u6807\u3002\r\n- \u5bf9\u6bb5\u843d\u5b57\u4f53\u5927\u5c0f\u8bbe\u7f6e\u53c2\u6570\uff0c\u9700\u4f20\u5165 `docx.shared.Pt` \u6216 `docx.shared.Length` \u7c7b\u578b\u5bf9\u8c61\uff0c\u793a\u4f8b\u4e2d\u7684\u6570\u503c\u4e3a\u793a\u610f\uff0c\u4f7f\u7528\u65f6\u8bf7\u6ce8\u610f\u8f6c\u6362\u3002\r\n- \u63d2\u5165LaTeX\u516c\u5f0f\u9700\u8981 `spire.doc` \u5e93\uff0c\u5b89\u88c5\u53ca\u4f7f\u7528\u8bf7\u53c2\u8003\u5b98\u65b9\u6587\u6863\u3002\r\n\r\n\u8054\u7cfb\u6211\u4eec\r\n========\r\n\r\n\u5982\u9047\u4efb\u4f55\u95ee\u9898\u6216\u8005\u529f\u80fd\u5efa\u8bae\uff0c\u8bf7\u901a\u8fc7\u4e0b\u5217\u65b9\u5f0f\u8054\u7cfb\u4f5c\u8005\uff1a\r\n\r\n- \u79f0\u547c\uff1a\u738b\u5148\u751f (Name: Jhonie)\r\n- E-mail: queenelsaofarendelle2022@gmail.com / 2570518164@qq.com\r\n- QQ\uff1a2570518164\r\n\r\n---\r\n\r\n\u611f\u8c22\u4f7f\u7528 FreeWork \u529e\u516c\u81ea\u52a8\u5316\u5de5\u5177\u5305\uff01\u6b22\u8fce\u53cd\u9988\u4e0e\u4ea4\u6d41\u3002\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "\u7b80\u5355\u53c8\u5b9e\u7528\u7684office\u64cd\u4f5c\u51fd\u6570\uff01(Simple and practical office operation functions!)",
    "version": "1.0.10",
    "project_urls": null,
    "split_keywords": [
        "python",
        " office",
        " excle",
        " word",
        " file's operation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49994e20c5c8c004ab3d794fc1918d9e3982b070c7cda745f1ed6b9133a99aea",
                "md5": "ca408e5e10af1ce7418a9f8265b58e6f",
                "sha256": "b967b35989520a36e95def4cec952a3e795563eff3c3ea4b25df6c3bb1fa3781"
            },
            "downloads": -1,
            "filename": "FreeWork-1.0.10.zip",
            "has_sig": false,
            "md5_digest": "ca408e5e10af1ce7418a9f8265b58e6f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 28630,
            "upload_time": "2025-08-14T03:50:12",
            "upload_time_iso_8601": "2025-08-14T03:50:12.108174Z",
            "url": "https://files.pythonhosted.org/packages/49/99/4e20c5c8c004ab3d794fc1918d9e3982b070c7cda745f1ed6b9133a99aea/FreeWork-1.0.10.zip",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-14 03:50:12",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "freework"
}
        
Elapsed time: 0.45845s