簡體   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