如何在excel表的开头插入一个带有Python的xlsxwriter的新列。我插入的excel目标遇到了一个问题:如何在表的开头插入一个新表,不知道xlsxwriter是否有这个功能麻烦你帮助解决这个问题
答案 0 :(得分:0)
嗨,请尝试,
workbook = xlsxwriter.Workbook('filename.xlsx')
worksheet1 = workbook.add_worksheet()
worksheet2 = workbook.add_worksheet()
worksheet1.write('A1', 123)
workbook.close()
此处列指定为A1,值为123。
# These are equivalent.
worksheet.write(0, 0, 'Hello')
worksheet.write('A1', 'Hello')
要在指定位置插入新列,请使用:
def insert_column(self):
# Instantiating a Workbook object by excel file path
workbook = self.Workbook(self.dataDir + 'Book1.xls')
# Accessing the first worksheet in the Excel file
worksheet = workbook.getWorksheets().get(0)
# Inserting a column into the worksheet at 2nd position
worksheet.getCells().insertColumns(1,1)
# Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(self.dataDir + "Insert Column.xls")
print "Insert Column Successfully."