Python Forum
Convert Xls files into Csv in on premises sharpoint
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert Xls files into Csv in on premises sharpoint
#1
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
deanhystad write Aug-29-2024, 06:22 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button
Reply
#2
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?
Reply
#3
(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.
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python convert multiple files to multiple lists MCL169 6 3,241 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  Separate text files and convert into csv marfer 6 4,733 Dec-10-2021, 12:09 PM
Last Post: marfer
  Finding location within a premises metro17 1 1,824 Jan-20-2021, 01:24 AM
Last Post: Larz60+
  Convert a PDF files to HTML files Underground 4 14,562 Oct-25-2020, 09:12 PM
Last Post: Larz60+
  convert old excel files(xls) to xlsm zarize 1 4,083 Jul-14-2020, 02:12 PM
Last Post: DeaD_EyE
  How to convert python files from 32 bits tto 64 bits sylas 2 5,885 Oct-29-2017, 03:51 AM
Last Post: Larz60+
  Convert grib files to text files tuxman 6 11,113 Sep-15-2017, 03:26 PM
Last Post: nilamo
  Convert .MTS files pberrett 16 20,373 Apr-16-2017, 03:54 PM
Last Post: pberrett

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020