繁体   English   中英

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

[英]Inserting the degree symbol into the word document using python

我正在使用python https://github.com/mikemaccana/python-docx模块,并且我试图仅将度数符号添加到我的Word文档中,而看不到如何做。

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

度=“some_numberº”

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

我创建了一个空文档,其中包含以下文本:

EmptyDocx12度

  • 保存为document.docx
  • document.docx 重命名为document.zip
  • 打开拉链并解压缩
  • 打开一个名为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 ,另一个包含度数符号。

因此,它只是存储为º或charCode186。要包括您的字符串,请用characterCode 186替换字符串中度数的字符代码,它应该可以工作(例如使用正则表达式)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM