简体   繁体   English

使用Python 3的xlwings问题

[英]xlwings issue using Python 3

I'm making a database-ish python 3 program that saves tkinter entries into an excel file. 我正在做一个数据库式的python 3程序,它将tkinter条目保存到excel文件中。 I really like using xlwings , so please find the solution with xlwings . 我真的很喜欢使用xlwings ,所以请找到解决xlwings Anyways, here is the issue: 无论如何,这是问题所在:

from tkinter import *
import xlwings as xw    
def save() :
    entrylist = [entry1.get(), entry2.get(), entry3.get(), entry4.get(), entry5.get(), 
    entry6.get(), entry7.get(), entry8.get(), entry9.get()]

        if len(entrylist[i]) != 0 and entry2.get() == entry3.get():
            teller = int(xw.Range('M1').value) + 1

            for i in range(0,3):
                rowlist = ["A"+ str(teller), "B"+ str(teller), "C"+str(teller), "D"+str(teller)]
                rowcode = "\'"+ rowlist[i] + "\'"
                xw.Range(rowcode).value = entrylist[i]

        xw.Range('M1').value = teller
        wb.save('klantendatabase.xlsx')

Now the problem is that the following piece of code is not allowed: 现在的问题是不允许以下代码:

xw.Range(rowcode).value = entrylist[i]

This is only allowed like this (A1 is an example cellnumber from the excel file):: 仅允许这样(A1是excel文件中的一个示例单元号):

xw.Range('A1').value = entrylist[i]

Is there a way to make the xw.Range().value take a variable? 有没有办法使xw.Range().value成为变量?

Make sure to set up your service to run on an https set up rather than http. 确保将服务设置为在https设置而非http上运行。 Generally port 8080 is most reliable for security. 通常,端口8080对于安全性最为可靠。 After that run your code in debug mode and run a database diff from your source code. 之后,以调试模式运行代码,然后从源代码运行数据库diff。 This should take care of all the log messages. 这应该处理所有日志消息。

You don't need to wrap rowcode with quotation marks, they are already strings. 您不需要用引号将行rowcode包装起来,因为它们已经是字符串了。 This works: 这有效:

import xlwings as xw

wb = xw.Workbook()
rowcode = 'A1'
xw.Range(rowcode).value = 'some value'

Although it might be easier in your case to use indices like so: xw.Range((i,j)).value 尽管在您的情况下使用这样的索引可能会更容易: xw.Range((i,j)).value

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

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