Skip to content

Instantly share code, notes, and snippets.

@BlurryLight
Created April 2, 2022 13:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BlurryLight/e677730a9dfa4fef9c029b655a26d617 to your computer and use it in GitHub Desktop.
Save BlurryLight/e677730a9dfa4fef9c029b655a26d617 to your computer and use it in GitHub Desktop.
convert csv excel
import win32com.client as win32
from win32com.client import constants
from pathlib import Path
excel = win32.gencache.EnsureDispatch('Excel.Application') # office
# excel = win32.gencache.EnsureDispatch('ket.Application') # wps
excel.Visible = False
input_path = Path("input.csv").absolute()
output_path = Path(".").absolute()
csv = excel.Workbooks.Open(str(input_path))
csv.Activate()
csv.SaveAs(
str(output_path/"output.xlsx"), FileFormat=constants.xlOpenXMLStrictWorkbook # xlsx
)
csv.Close(False)
excel.Quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment