Created
April 2, 2022 13:27
-
-
Save BlurryLight/e677730a9dfa4fef9c029b655a26d617 to your computer and use it in GitHub Desktop.
convert csv excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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