使用python将度数符号插入word文档

时间:2013-08-01 22:50:00

标签: python python-2.7 ms-word docx

我正在使用python https://github.com/mikemaccana/python-docx模块,我只想简单地将度数符号添加到我的word文档中,但无法看到如何操作。

只需要一个像这样的字符串:

Degree =“some_numberº”

然后我想在我的文档中插入该字符串。

1 个答案:

答案 0 :(得分:0)

我创建了一个空文档,里面有以下文字:

EmptyDocx12Degrees

  • 保存为document.docx
  • 重命名 document.docx至document.zip
  • 打开拉链并将其解压缩
  • 打开 word 文件夹中名为 document.xml 的文件

这是一个记录信息目的的word文档结构的链接:https://stackoverflow.com/tags/docx/info

以下是具有度数的特定文件的document.xml的内容:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document mc:Ignorable="w14 wp14" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
    <w:body>
        <w:p w:rsidR="009565D8" w:rsidRDefault="00986522">
            <w:r>
                <w:rPr>
                    <w:rFonts w:ascii="Arial" w:cs="Arial" w:hAnsi="Arial"/>
                    <w:color w:val="000000"/>
                    <w:sz w:val="21"/>
                    <w:szCs w:val="21"/>
                    <w:shd w:color="auto" w:fill="FFFFFF" w:val="clear"/>
                </w:rPr>
                <w:t>12</w:t>
            </w:r>
            <w:r>
                <w:rPr>
                    <w:rFonts w:ascii="Arial" w:cs="Arial" w:hAnsi="Arial"/>
                    <w:color w:val="000000"/>
                    <w:sz w:val="21"/>
                    <w:szCs w:val="21"/>
                    <w:shd w:color="auto" w:fill="FFFFFF" w:val="clear"/>
                </w:rPr>
                <w:t>º</w:t>
            </w:r>
            <w:bookmarkStart w:id="0" w:name="_GoBack"/>
            <w:bookmarkEnd w:id="0"/>
        </w:p>
        <w:sectPr w:rsidR="009565D8">
            <w:pgSz w:h="16838" w:w="11906"/>
            <w:pgMar w:bottom="1417" w:footer="708" w:gutter="0" w:header="708" w:left="1417" w:right="1417" w:top="1417"/>
            <w:cols w:space="708"/>
            <w:docGrid w:linePitch="360"/>
        </w:sectPr>
    </w:body>
</w:document>

如您所见,它们是标签:<w:t></w:t>。这些标记包含文档的文本。其中一个包含 12 ,另一个包含度数符号。

所以它只是存储为º或charCode 186.要包含你的字符串,用characterCode 186替换字符串中度数的字符代码,它应该可以工作(例如用正则表达式)

相关问题