Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aspose-com-gists/4af150b623f1b55ed757375a029df798 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/4af150b623f1b55ed757375a029df798 to your computer and use it in GitHub Desktop.
Convert TXT File to CSV in Python
from aspose.cells import Workbook, TxtLoadOptions, SaveFormat
# Step 1: Define load options with tab delimiter
load_options = TxtLoadOptions()
load_options.separator = '\t' # Tab-delimited text
# Step 2: Load the TXT file
workbook = Workbook("tab_delimited.txt", load_options)
# Step 3: Save as CSV file
workbook.save("converted.csv", SaveFormat.CSV)
from aspose.cells import Workbook, SaveFormat
# Step 1: Load the TXT file
workbook = Workbook("sample_data.txt")
# Step 2: Save as CSV file
workbook.save("output.csv", SaveFormat.CSV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment