Copy and past embedded images from one Excel file to another with Microsoft Graph on Sharepoint

Lexignot 65 Reputation points
2024-05-11T21:13:46.8266667+00:00

Hello,

Is there a way to copy and past embedded images from one Excel file to another with Microsoft Graph on SharePoint? I was able to copy the data from one Excel file to another with the following script but the format is not preserved and the embedded images return #VALUE in the destination file. I am using Python and my intention is to use Azure Function to automate the script.

Thanks in advance for your answers.

    # Get data including styles from the source sheet
    get_data_url = f"https://graph.microsoft.com/v1.0/sites/{site_id}/drives/{library_id}/items/{source_file_id}/workbook/worksheets/{source_sheet_name}/range(address='{source_address}')"
    response = requests.get(get_data_url, headers=headers)
    if response.status_code != 200:
        raise Exception("Failed to get data from source sheet")
    
    data_with_styles = response.json()

    # Update the target sheet with copied data and styles
    update_data_url = f"https://graph.microsoft.com/v1.0/sites/{site_id}/drives/{library_id}/items/{target_file_id}/workbook/worksheets/{target_sheet_name}/range(address='{target_address}')"
    response = requests.patch(update_data_url, headers=headers, json=data_with_styles)
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,837 questions
Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
1,541 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,866 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 32,166 Reputation points Microsoft Vendor
    2024-05-13T02:29:36.05+00:00

    Hi @Lexignot,

    Per my research, there is no such api to copy images from one Excel file to another by graph. You could refer to the following document

    Working with Excel in Microsoft Graph

    We could try to copy the whole excel file by following graph

    https://graph.microsoft.com/v1.0/sites/{siteid}/drives/{driveid}/Items/{file id which you want to copy}/copy
    
    Request Body: 
    {   
        "parentReference": {     
                                "driveId": "{Same driveid of above call}",     
                                "id": "{Folderid}"   
                           },   
        "name": "contosoplan(copy).xlsx" 
    } 
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful