简体   繁体   English

读取Python CDispatch对象仅给出第一行

[英]Reading Python CDispatch object only gives the first line

first question coming up...have just started using Python 3.6. 出现的第一个问题...刚刚开始使用Python 3.6。 I am creating an XML format document of tabulated data. 我正在创建一个表格数据的XML格式文档。 The document object itself has a collection called CellValues. 文档对象本身具有一个称为CellValues的集合。 Using Dimensions (aka Unicom Intelligence) I can read this collection as a record set and loop round it with .movenext() etc. However when I read it in Python with: 使用Dimensions(也称为Unicom Intelligence),我可以将此集合作为记录集读取,并使用.movenext()等对其进行循环。但是,当我在Python中使用以下命令读取它时:

rs=tomdoc.tables["T0"].cellvalues()
for val in rs:
    print(val)

I only see the first line. 我只看到第一行。 In contrast, when I connect to a SqL database, the returned object is a SQLrows type and prints the whole thing, but this one says it's CDispatch. 相反,当我连接到SqL数据库时,返回的对象是SQLrows类型并打印出整个内容,但是这个表示它是CDispatch。 How can I get it to either loop round or show me the whole recordset? 如何使它循环播放或显示整个记录集? Apologies for my ignorance and thanks in advance :) 对我的无知表示歉意,并在此先感谢:)

Thanks to a colleague, I do now have a working process. 多亏了一位同事,我现在有了一个工作流程。 In fact the collection needs to be indexed this way: 实际上,需要使用以下方式对集合进行索引:

rs = tomdoc.Tables("T0").CellValues

Then it can be read as one normally would read a SQL-type record set: 然后可以将其读取为通常读取SQL类型记录集的方式:

rs.MoveFirst()
while not rs.EOF:
    rowStr = ""
    for f in rs.Fields:
        rowStr += f.value + "\t"
    print(rowStr)
    rs.MoveNext()

I'm not sure why the ["T0"] gave me the first line though - that threw me somewhat and made it look closer than it actually was (one of those jolly things one encounters when mixing objects) so I didn't investigate alternatives for that part of the script :( 我不知道为什么[“ T0”]给了我第一行-这使我有些挣扎,使它看起来比实际更接近(混合对象时遇到的那些快乐的事情之一),所以我没有调查脚本的那部分的替代方案:(

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

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