简体   繁体   English

将输出打印到任何文件(.doc / .xml / .xls)中的表中,而无需像xlwt这样的单独包

[英]Print the output in a table in any file(.doc/.xml/.xls) without having a separate package like xlwt

I am new to programming and tried to write a python script for my work. 我是编程新手,并尝试为自己的工作编写python脚本。 It worked well. 运行良好。 I need to print the output in an excel. 我需要在Excel中打印输出。 Finally i was able to do it with xlwt. 终于我能够用xlwt做到这一点。 Here is the script. 这是脚本。

def sh(dir):   
a = xlwt.Workbook()
sheet = a.add_sheet('sheet1')
n = 0
for r,d,f in os.walk(dir):
    for files in f:
        if files.endswith(".xml"):
            print files
            dom=parse(os.path.join(r, files))
            name = dom.getElementsByTagName('rev')
            title = dom.getElementsByTagName('title')
            sheet.write(n, 0, files)
            sheet.write(n, 1, title[0].firstChild.nodeValue)
            sheet.write(n, 2, name[0].firstChild.nodeValue)
            n += 1
            print title[0].firstChild.nodeValue
            print name[0].firstChild.nodeValue
a.save('sha.xls')

Now the problem is I work in the files in CITRIX server. 现在的问题是我在CITRIX服务器中的文件中工作。 The admin doesn't know how to add the package to python installed in our server. 管理员不知道如何将软件包添加到安装在我们服务器中的python中。 I tried raising many tickets, but failed in all. 我曾尝试筹集许多票,但都失败了。 Now i gotta do all the work with the standard package with python 3.3. 现在我要使用python 3.3使用标准包进行所有工作。 I need a solution now. 我现在需要一个解决方案。 How i can print the output in a table format without having any package? 我如何在没有任何包装的情况下以表格格式打印输出?

eg the output will be 例如输出将是

1_1543-CRA 119 1364_2.xml   Router Processor Card      A1

IS there a way to do this? 有没有办法做到这一点? Please help. 请帮忙。

I got it. 我知道了。 In the print statement, i included this statement "sep='\\t'" and exported the output to csv. 在print语句中,我包括了该语句“ sep ='\\ t'”,并将输出导出到csv。

eg 例如

print (files, title[0].firstChild.nodeValue, name[0].firstChild.nodeValue, sep='\\t') 打印(文件,标题[0] .firstChild.nodeValue,名称[0] .firstChild.nodeValue,sep ='\\ t')

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

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