简体   繁体   English

xml代码以格式化Word文档模板问题中的粗体代码段

[英]xml code to format bold snippet in word document template issue

I am constructing a sentence to insert into a word xml template. 我正在构建一个句子以插入到xml模板中。 My python 2.7 code is below 我的python 2.7代码如下

#Create a list using a function that returns a comma formatted list of dealers

if len(myList) > 0:
    if len(myList) > 1:
        testText = list_format(myList) + " dealers."
    else:
        myText = myList[0] + " dealer."

#Contruct sentence

    #myBlurb = "<w:cr/><w:r><w:rPr><w:b/></w:rPr><w:t>My Favorite Cars - </w:t></w:r><w:r><w:t> My favorite cars are available at </w:t></w:r>"  + myText + "<w:cr/>"
    myBlurb = "<w:cr/>My Favorite Cars - My favorite cars are available at " + myText + "<w:cr/>"
else:
    myBlurb = ""

If a list exists (not = 0) Then 如果存在列表(不等于0),则

I am trying to get the following output: 我正在尝试获得以下输出:

My Favorite Cars - My favorite cars are available at (list of dealers) dealers. 我最喜欢的车-我的最爱车可以在(经销商列表)经销商处购买。

There is a newline above and below this line. 在该行的上方和下方都有一个换行符。 The first three words and the dash are bold. 前三个字和破折号为粗体。 All other words are not bold. 其他所有单词都不是粗体的。

This works but contains no bold text 这有效,但不包含粗体文本

myBlurb = "<w:cr/>My Favorite Cars - My favorite cars are available at " + myText + "<w:cr/>"

But when I try to bold, it bombs. 但是当我尝试大胆时,它就会炸弹。 It does not seem to like either of these (+ myText + "<w:cr/>") (separately or together) appended on the end. 似乎不喜欢将这两个(+ myText + "<w:cr/>") (单独或一起)附加在末尾。

This does not work 这行不通

myBlurb = "<w:cr/><w:r><w:rPr><w:b/></w:rPr><w:t>My Favorite Cars - </w:t></w:r><w:r><w:t> My favorite cars are available at </w:t></w:r>"  + myText + "<w:cr/

What am I missing here? 我在这里想念什么?

It always helps if you describe how "This does not work" in detail, but I think this is what you're missing (just the code from the end of the entire string, for clarity's sake): 如果您详细描述“这是行不通的”,它总是有帮助的,但是我认为这是您所缺少的(为了清楚起见,只是整个字符串末尾的代码):

</w:t></w:r><w:r><w:t>"  + myText + "< /w:t></w:r><w:cr/>" 

myText should be handled just like the static runs you want to write to the document - it needs to be declared as a run containing text. myText应该像要写入文档的静态运行一样处理-需要将其声明为包含文本的运行。

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

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