1

我正在使用 python https://github.com/mikemaccana/python-docx模块,我试图只是简单地将度数符号添加到我的 word 文档中,但看不到怎么做。

只要有一个这样的字符串:

度数 = “some_numberº”

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

4

1 回答 1

0

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

EmptyDocx12Degrees

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

这是一个记录信息目的的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,它应该可以工作(例如使用正则表达式)

于 2013-08-02T10:23:26.090 回答