Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3ce96dd

Browse files
CSV-To-Excel Converter Added
1 parent f05226e commit 3ce96dd

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

‎CSV-To-Excel/CSV-To-Excel.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!python3
2+
# -*- coding: utf-8 -*-
3+
4+
import openpyxl
5+
import sys
6+
7+
#inputs
8+
print("This programme writes the data in any Comma-separated value file (such as: .csv or .data) to a Excel file.")
9+
print("The input and output files must be in the same directory of the python file for the programme to work.\n")
10+
11+
csv_name = input("Name of the CSV file for input (with the extension): ")
12+
sep = input("Separator of the CSV file: ")
13+
excel_name = input("Name of the excel file for output (with the extension): ")
14+
sheet_name = input("Name of the excel sheet for output: ")
15+
16+
#opening the files
17+
try:
18+
wb = openpyxl.load_workbook(excel_name)
19+
sheet = wb.get_sheet_by_name(sheet_name)
20+
21+
file = open(csv_name,"r",encoding = "utf-8")
22+
except:
23+
print("File Error!")
24+
sys.exit()
25+
26+
#rows and columns
27+
row = 1
28+
column = 1
29+
30+
#for each line in the file
31+
for line in file:
32+
#remove the \n from the line and make it a list with the separator
33+
line = line[:-1]
34+
line = line.split(sep)
35+
36+
#for each data in the line
37+
for data in line:
38+
#write the data to the cell
39+
sheet.cell(row,column).value = data
40+
#after each data column number increases by 1
41+
column += 1
42+
43+
#to write the next line column number is set to 1 and row number is increased by 1
44+
column = 1
45+
row += 1
46+
47+
#saving the excel file and closing the csv file
48+
wb.save(excel_name)
49+
file.close()

‎CSV-To-Excel/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Prerequisites for running the CSV-To-Excel
2+
- Python 3.6 or higher
3+
- pip
4+
- openpyxl, sys
5+
6+
7+
## How to Use
8+
1. Clone the repository
9+
2. Open the terminal and navigate to the directory where the repository is cloned
10+
3. Run the following command to install the required packages
11+
```bash
12+
pip install openpyxl
13+
```
14+
4. Once openpyxl is installed, you can use the script below to convert a CSV file to an Excel spreadsheet.
15+
5. Run the following command to run the bot
16+
```bash
17+
python3 CSV-To-Excel.py
18+
```
19+
20+
21+
22+
## Developer
23+
- [Kalivarapubindusree]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /