如何使用python3写入Excel?

时间:2019-04-04 02:40:38

标签: excel python-3.x

如何使用python3写入excel

如何将2个值写入第一列A,将其他2个值写入B列,将其他2个值写入c列,直到行结束

  listoflist=[["data1$","data2$"],["content1","content2"],["first","second"]]

   for i,string in enumerate(listoflist):
          for j in string:
            replaced = re.sub("[^a-zA-Z0-9/.' ]+", '', j)
            print(replaced)
             column_count = 2
def excel_file():

     new_row_data =[["heading"],[replaced]]
     workbook = xlsxwriter.Workbook('Input.xlsx')
     workbook.close()

      wb = load_workbook("Input.xlsx")
      ws = wb.worksheets[0]

      for row_data in new_row_data:
               ws.append(row_data)

      wb.save("table.xlsx") 
      print("Please Open the Excel File")


excel_file()

预期输出:希望在excel文件中输出

  Column A      Column B        Column c
  data1         content1        first
  data2         content2        second

0 个答案:

没有答案