代码之家  ›  专栏  ›  技术社区  ›  Berch

Python库将数据从sqlite导入word doc

  •  -1
  • Berch  · 技术社区  · 6 年前

    我在sqlite数据库(文本和图像)中存储了数据,并希望将其导入.doc/.docx格式。我使用下面的参考资料来尝试实现同样的目标。

    1. Python-docx
    2. docx-mailmerge

    期待您的反馈,如果这些是最好的图书馆的工作?如果您能给我提供任何符合要求的文件,我将不胜感激。

    为了避免因缺乏研究而被否决, link here . 这个问题只是为了了解,如果有其他好的替代品,我目前正在使用的。谢谢你

    1 回复  |  直到 6 年前
        1
  •  0
  •   jeevs    6 年前

    Sqlite是Python标准库的一部分。这里有一个链接到 concise tutorial 以下是简短摘录:

    import sqlite3
    conn = sqlite3.connect('sqlite_file')
    c = conn.cursor()
    
    # Create a table
    c.execute('CREATE TABLE {tn} ({nf} {ft})'\
        .format(tn='my_table', nf='name', ft='VARCHAR'))
    
    conn.commit()
    # insert table
    c.execute("INSERT INTO {tn} ({cn}) VALUES ('test')".\
        format(tn='my_table', cn='name'))
    conn.commit()
    # select rows
    c.execute('SELECT * FROM {tn}'.format(tn='my_table'))
    all_rows = c.fetchall()
    
    for row in all_rows:
        # do something