Python Forum
Convert Xls files into Csv in on premises sharpoint - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Convert Xls files into Csv in on premises sharpoint (/thread-43096.html)



Convert Xls files into Csv in on premises sharpoint - Andrew_andy9642 - Aug-29-2024

Hi team,

Today i just joined the forum and like to seek your experties . i am trying to convert Xls files in the on premises SharePoint in our company to Csv ,

i have below code so far can some one help me to make this work for some reason it is not working for me i know the code below is not completed
import pandas as pd  
import os  
import glob  
  
# Replace the folder_url with the SharePoint URL of the document folder  
folder_url = 'https://company.sharepoint.com/:f:/s/Source/ErzWHfGHqWxAt_G0F09schwBN8Heo9khieMVLKbG0jbLzQ'  
  
# Get a list of all XLS files in the folder  
xls_files = glob.glob(f'{folder_url}/*.xls')  
  
# Iterate over each XLS file and convert it to CSV  
for xls_file in xls_files:  
    # Read the XLS file using pandas  
    df = pd.read_excel(xls_file)  
  
    # Get the filename without the extension  
    filename = os.path.splitext(os.path.basename(xls_file))[0]  
  
    # Replace the output_folder_path with the desired path for the CSV files  
    output_folder_path = 'https://company.sharepoint.com/:f:/s/Source/ErzWHfGHqWxAt_G0F09schwBN8Heo9khieMVLKbG0jbLzQ

'  
  
    # Create the output folder if it doesn't exist  
    os.makedirs(output_folder_path, exist_ok=True)  
  
    # Convert the DataFrame to CSV  
    csv_file_path = f'{output_folder_path}/{filename}.csv'  
    df.to_csv(csv_file_path, index=False)  
  
    print(f'File converted and saved as {csv_file_path}')  
Thanks & lookin for your help Smile


RE: Convert Xls files into Csv in on premises sharpoint - deanhystad - Aug-29-2024

Please describe what you mean by "not working". Are you getting any files in xls_files? Can you read the excel file? Can you make the directories for the output?


RE: Convert Xls files into Csv in on premises sharpoint - Andrew_andy9642 - Aug-30-2024

(Aug-29-2024, 06:27 PM)deanhystad Wrote: Please describe what you mean by "not working". Are you getting any files in xls_files? Can you read the excel file? Can you make the directories for the output?

Hi ,

Nothing happening with the code i shared , i believe there is more to it and i don't know what it is . a little did i believe authentication to on premises sharepoint link is missing ... hope i was able explain but let me know if you need any thing.


RE: Convert Xls files into Csv in on premises sharpoint - deanhystad - Aug-30-2024

The python package index has many packages for working with sharepoint files. I would start by looking at some of those.

https://pypi.org/search/?q=sharepoint