|
|
import streamlit as st |
|
|
import pandas as pd |
|
|
from io import BytesIO |
|
|
|
|
|
|
|
|
styles = """ |
|
|
<style> |
|
|
/* Button styles */ |
|
|
div.stButton > button { |
|
|
color: #ffffff; /* Text color */ |
|
|
font-size: 20px; |
|
|
background-image: linear-gradient(0deg, #a2c2e1 0%, #003b5c 100%); /* Light blue to deep blue gradient */ |
|
|
border: none; |
|
|
padding: 10px 20px; |
|
|
cursor: pointer; |
|
|
border-radius: 15px; |
|
|
display: inline-block; |
|
|
width: 100%; /* Make button fit column width */ |
|
|
} |
|
|
div.stButton > button:hover { |
|
|
background-color: #00ff00; /* Hover background color */ |
|
|
color: #ff0000; /* Hover text color */ |
|
|
} |
|
|
/* Title styles */ |
|
|
h1 { |
|
|
background-image: linear-gradient(0deg, #a2c2e1 0%, #003b5c 100%); /* Light blue to deep blue gradient */ |
|
|
-webkit-background-clip: text; |
|
|
-webkit-text-fill-color: transparent; |
|
|
font-size: 36px; |
|
|
} |
|
|
</style> |
|
|
""" |
|
|
|
|
|
|
|
|
st.markdown(styles, unsafe_allow_html=True) |
|
|
|
|
|
|
|
|
st.markdown("<h1>CSV and Excel Appender</h1>", unsafe_allow_html=True) |
|
|
st.write("A website that is used for appending multiple CSV and Excel files and converting them to a desired format.") |
|
|
|
|
|
|
|
|
uploaded_files = st.file_uploader("Upload CSV or Excel files", type=["csv", "xlsx", "xls"], accept_multiple_files=True) |
|
|
|
|
|
if uploaded_files: |
|
|
|
|
|
df_list = [] |
|
|
|
|
|
for i, uploaded_file in enumerate(uploaded_files): |
|
|
|
|
|
file_name = uploaded_file.name |
|
|
|
|
|
|
|
|
if uploaded_file.type == "text/csv": |
|
|
if i == 0: |
|
|
|
|
|
df = pd.read_csv(uploaded_file) |
|
|
|
|
|
headers = df.columns |
|
|
else: |
|
|
|
|
|
df = pd.read_csv(uploaded_file, names=headers, header=0) |
|
|
elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": |
|
|
if i == 0: |
|
|
|
|
|
df = pd.read_excel(uploaded_file) |
|
|
|
|
|
headers = df.columns |
|
|
else: |
|
|
|
|
|
df = pd.read_excel(uploaded_file, names=headers, header=0) |
|
|
|
|
|
elif uploaded_file.type == "application/vnd.ms-excel": |
|
|
|
|
|
if i == 0: |
|
|
|
|
|
df = pd.read_excel(uploaded_file, engine='xlrd') |
|
|
|
|
|
headers = df.columns |
|
|
else: |
|
|
|
|
|
df = pd.read_excel(uploaded_file, names=headers, header=0, engine='xlrd') |
|
|
|
|
|
|
|
|
df['file_name'] = file_name |
|
|
df_list.append(df) |
|
|
|
|
|
|
|
|
merged_df = pd.concat(df_list, ignore_index=True) |
|
|
|
|
|
|
|
|
st.markdown("<h1>Appended Data</h1>", unsafe_allow_html=True) |
|
|
st.dataframe(merged_df) |
|
|
|
|
|
|
|
|
col1, col2, col3 = st.columns(3) |
|
|
|
|
|
with col1: |
|
|
|
|
|
csv_output = BytesIO() |
|
|
merged_df.to_csv(csv_output, index=False) |
|
|
csv_output.seek(0) |
|
|
st.download_button( |
|
|
label="Download Merged CSV File", |
|
|
data=csv_output, |
|
|
file_name="merged_data.csv", |
|
|
mime="text/csv" |
|
|
) |
|
|
|
|
|
with col2: |
|
|
|
|
|
excel_output = BytesIO() |
|
|
with pd.ExcelWriter(excel_output, engine='xlsxwriter') as writer: |
|
|
merged_df.to_excel(writer, index=False) |
|
|
excel_output.seek(0) |
|
|
st.download_button( |
|
|
label="Download Merged Excel File", |
|
|
data=excel_output, |
|
|
file_name="merged_data.xlsx", |
|
|
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" |
|
|
) |
|
|
else: |
|
|
st.write("") |