CaptainKoffski

XLS from Pandas

Jun 10th, 2021 (edited)
743
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. out_xlsx=r'C:\tmp\output.xlsx'
  2. out_xls=r'C:\tmp\output.xls'
  3. df.to_excel(out_xlsx, index=False, engine='xlsxwriter')
  4. ps = 'script.ps1'
  5. with open(ps, 'w') as f:
  6.     f.write(textwrap.dedent('''\
  7.        param ($inputFile, $outputFile)
  8.        $myDir = split-path -parent $MyInvocation.MyCommand.Path
  9.        $Excel = New-Object -ComObject Excel.Application
  10.        $wb = $Excel.Workbooks.Open($inputFile)
  11.        $wb.SaveAs($outputFile, 56)
  12.        $Excel.Quit()
  13.    '''))
  14. p = subprocess.Popen(['powershell.exe',
  15.                       '-ExecutionPolicy', 'Bypass',
  16.                       '.\\' + ps,
  17.                       '"' + out_xlsx + '"',
  18.                       out_xls])
  19. p.communicate()
RAW Paste Data