简体   繁体   English

使用xlwt(python)附加工作表

[英]appending sheet using xlwt (python)

I am attempting to append a number of sheets from one excel file into a single sheet in another excel file. 我试图将一个excel文件中的一些工作表附加到另一个excel文件中的单个工作表中。

My code looks like this: 我的代码看起来像这样:

rb2= xlrd.open_workbook(ValidationReport + "2.xlsx")

for sheet in rb2.sheets():
    rowx += 5
    w_sheet.write(rowx, colx, sheet)

wb.save(ValidationReport + ".xls")

and I get the following error: 我收到以下错误:

Exception: Unexpected data type class 'xlrd.sheet.Sheet'

When I replace the sheet object with a string, that string will write to the desired file once for every sheet in my read file. 当我用字符串替换工作表对象时,该字符串将为我的读取文件中的每个工作表写入一次所需的文件。 Is there a way to write the contents of a single sheet to the bottom of a different excel file using xlwt? 有没有办法使用xlwt将单个工作表的内容写入不同excel文件的底部?

For those of you who are not new to Python, this may seem like a no brainer, but for somebody like me, it took a while to figure out. 对于那些不熟悉Python的人来说,这看起来似乎不是一件容易的事情,但对于像我这样的人来说,需要一段时间才能弄明白。

It is SO MUCH easier to try and manipulate csv files than excel files, and once I made the switch over, things moved much more quickly. 尝试操作csv文件比excel文件更容易,一旦我完成切换,事情就会快得多。

My new code looks something like this: 我的新代码看起来像这样:

        df["Iflag"] = df.Independent.where((df.Independent == 0) | (df.Independent == 1 )).notnull().astype(int)
            Iflag = df[df.Iflag == 0]
            pd.DataFrame(Iflag, columns=["ID","Independent"]).to_csv(my.csv, mode='ab')

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

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