Skip to content

csv_to_excel #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions csv_to_excel/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The code will help to convert a csv to excel.

## Installation

- Install Python to your system.

- Install the module **openpyxl**

- Do it by typing this on Power Shell (for Windows) or Bash (for Linux)

```bash
pip install openpyxl
```

Once **openpyxl** is installed, you can use the script to convert a CSV file to Excel.
44 changes: 44 additions & 0 deletions csv_to_excel/csv_to_excel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import openpyxl
import sys


print("This programme writes the data in any Comma-separated value file (such as: .csv or .data) to a Excel file.")
print("The input and output files must be in the same directory of the python file for the programme to work.\n")

csv_name = input("Name of the CSV file for input (with the extension): ")
sep = input("Separator of the CSV file: ")
excel_name = input("Name of the excel file for output (with the extension): ")
sheet_name = input("Name of the excel sheet for output: ")


try:
wb = openpyxl.load_workbook(excel_name)
sheet = wb.get_sheet_by_name(sheet_name)

file = open(csv_name,"r",encoding = "utf-8")
except:
print("File Error!")
sys.exit()


row = 1
column = 1


for line in file:

line = line[:-1]
line = line.split(sep)


for data in line:

sheet.cell(row,column).value = data

column += 1

column = 1
row += 1

wb.save(excel_name)
file.close()
2 changes: 2 additions & 0 deletions csv_to_excel/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. Python
2. openpyxl python library