Skip to main content

Notifications

CSV To New Excel Table

takolota1 Profile Picture Posted by takolota1 4,617

 

takolota_0-1666901862004.png


Quickly & Easily Convert Various CSVs to New Excel Tables


Takes in most types of CSV data, dynamically identifies the header names, and creates an Excel table in a new or existing workbook.

No premium, 3rd party, or Office Script actions required. Only standard connectors.

 

(Works on comma-separated files where any items with in-data commas are surrounded in double quotes “String1, String2” but comma separated arrays with double quotes inside an item may also cause issues.)

 

For example, here is a CSV I downloaded from a random SharePoint list:
CSVData.png

 

And I did not create any template doc table, & I did not adjust any names. I just selected the CSV file in my OneDrive, then ran the flow to get this output...
ExcelTableData.png

(But if you’re just downloading this template, then you will need to change the “Create table” action document library reference to your OneDrive folder instead of the id that is in there by default)

If needed, you should also be able to dynamically change the destination Excel to an existing workbook & worksheet based on other values in your flow. And the CSV data can automatically come from any preceding actions.

 

If you use something other than the default OneDrive action to get your CSV data, then add the CSV output to the "CSV_Data" field in the "Compose CSV data + Set-up" action.

If your CSV header row with column names is not the 1st row in your CSV, make sure to adjust the "ColumnNamesRow" value in the "Compose CSV data + Set-up" action to match the correct CSV row number.

This template is really just a combination of...
-The CSV to Dataset template with manual column mapping: https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/CSV-to-Dataset/td-p/1508191

-@RezaDorrani's video on exporting data to an Excel table: https://youtu.be/Kupz71dWYyY 

-@Paulie78's video on fast exporting to an Excel table: https://youtu.be/AA-D4lgjR3o 

 


Please 1st try downloading the below zip file & importing the whole flow as described in this post: https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/CSV-To-New-Excel-Table/m-p/1891765/highlight/true#M1118 

If the standard zip file import method does not work for you, then you can try an alternative Power Apps Solution import method here: Re: CSV To New Excel Table - Page 15 - Power Platform Community (microsoft.com)

Or an alternative clipboard copy & paste import method from these 3 posts
https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/CSV-To-New-Excel-Table/m-p/1841481/highlight/true#M1009 
https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/CSV-To-New-Excel-Table/m-p/1841499/highlight/true#M1010 
https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/CSV-To-New-Excel-Table/m-p/1841504/highlight/true#M1011 
https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/CSV-To-New-Excel-Table/m-p/1843986/highlight/true#M1014 

 

Warning. The Groups HTTP connector with access to the graph API calls used for this template may be removed soon. You can vote to ask for this not to be removed here: https://ideas.powerautomate.com/d365community/idea/d51463df-6f0c-ed11-a81b-6045bd7c3e3f
You can also try using a different premium HTTP action to make that final call, like what Matt does here: https://www.matthewdevaney.com/quickly-add-multiple-rows-to-excel-table-in-power-automate/ 

 

Version 1.1 of the template flow does just this & uses the PREMIUM Azure HTTP action.

To set up the Azure HTTP action connection, use https://graph.microsoft.com for the url & for the Resource URI:

AzureHTTPURIs.png

 

Version 1.1SP is set up to get the CSV from SharePoint & transfer the new Excel file & new table to SharePoint at the end of the flow.

 

Thanks for any feedback!


Solution Zip Download Link: https://drive.google.com/file/d/1zi3kWaTfUENDEkP3Rpj9a8lMDYhkvIbQ/view?usp=sharing

Categories:

Comments

  • Fernando21 Profile Picture Fernando21
    Posted at
    CSV To New Excel Table
     Hello, 
     
    I have the same issue as autoperfect93, 
       "message": "The response is not in a JSON format.",
       "innerError": "Cannot read server response."
     
    But I have only this error with a csv files with ~70 000 rows.
    When i use it with smallest csv files (~3000 rows) it works perfectly.
     It works even with multiple files.
    And in the case of this big file, I can put smallest files with it, the small files will be converted to excel but not this big one.
     
    Yes, 70000 rows, that means I cannot use the alternative by Office scripts and also I cannot use the premium connector.
    I use the Office Groups HTTP connector.
     
    What could mean the "innererror" : cannot read server response ?
     
    I suppose it's related to the size of the file, where should I put some delays to maybe let time to get the response ?
    I tried some but without success.
     
  • takolota1 Profile Picture takolota1 4,617
    Posted at
    CSV To New Excel Table

    @autoperfect93 

    It may be running into some other error & the error response message is not formatted in proper JSON or something.

    It’s hard to diagnose if it comes on randomly, but the most recent solution package import CSVToNewExcelTable_x_0_0_x.zip includes a Non Premium version of the flow that, instead of a graph call, uses an Office Script to batch create up to like 18,000 rows of a CSV to the new Excel table. But it does take longer to run.

    So if you want to try for something more reliable, are fine with a slower flow, & don’t have CSVs with more than 18,000 rows, then you could try that version instead.

  • autoperfect93 Profile Picture autoperfect93 96
    Posted at
    CSV To New Excel Table

    Hello @takolota ,

     

    I have been using the flow to convert the CSV files into XLSX since the beginning of May but now I started facing the following error:

     

    autoperfect93_0-1717919616147.png

    The flow fails at action "Invoke an HTTP request" with error "The response is not in a JSON format."


    Here is the raw outputs of the step:

     

    "statusCode": 302,
        "headers": {
            "Cache-Control": "private",
            "Location": "/error/error.html?aspxerrorpath=/x/_layouts/xlrestinternal.aspx",
            "Strict-Transport-Security": "max-age=31536000",
            "request-id": "bb1a2b23-8a16-44de-a3c2-fc544db63d0e",
            "client-request-id": "bb1a2b23-8a16-44de-a3c2-fc544db63d0e",
            "x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"France Central\",\"Slice\":\"E\",\"Ring\":\"5\",\"ScaleUnit\":\"000\",\"RoleInstance\":\"SL3RIPS0213B089\"}}",
            "Timing-Allow-Origin": "*",
            "x-ms-apihub-cached-response": "false",
            "x-ms-apihub-obo": "false",
            "Date": "Sun, 09 Jun 2024 07:45:45 GMT",
            "Content-Length": "256",
            "Content-Type": "application/json"
        },
        "body": {
            "error": {
                "code": 302,
                "source": "france-001.azure-apim.net",
                "clientRequestId": "17db72ef-f224-4326-b1ab-d73550e044bb",
                "message": "The response is not in a JSON format.",
                "innerError": "Cannot read server response."
            }
        }
    }

     

    The interesting part is that the error appears randomly. Sometimes the flow finishes in success but it is not stable and the above mentioned error stops the flow and I still am not able to understand what is triggering the issue.

     

    Any advice would be highly appreciated.


    Best Regards,
    Dzhuneyt

  • autoperfect93 Profile Picture autoperfect93 96
    Posted at
    CSV To New Excel Table

    Hi @takolota ,

     

    Thank you so much! I have added 30 seconds before the "Get file content" action in order to give some time for the excel file to be updated with the data.

     

    autoperfect93_0-1715105830188.png

  • takolota1 Profile Picture takolota1 4,617
    Posted at
    CSV To New Excel Table

    @autoperfect93 Because of the AD HTTP action all those steps must happen in OneDrive. Then the SharePoint Create file action will recreate the file in SharePoint to get it over there. By the time it re-reads the content, the new rows from the CSV should be there. If they are not, try adding a delay before retrieving the file contents of the newly updated Excel file & see if that helps. It reads the contents of the file at that moment, not back when the file was empty.

  • autoperfect93 Profile Picture autoperfect93 96
    Posted at
    CSV To New Excel Table

    Indeed. I did put the SharePoint URL but I did some research and noticed this afterwards.

     

    The only issue left is the question "How to take the content of the file in OneDrive for Business to SharePoint"

     

    I think this is due to the action Get file content retrieving the empty excel file created in the "Create file blank Excel"

     

    autoperfect93_0-1715018397989.png

     

     

  • takolota1 Profile Picture takolota1 4,617
    Posted at
    CSV To New Excel Table

    @autoperfect93 I think you input a SharePoint url instead of the MS Graph url as listed in the instructions

    AD-URL.png

  • autoperfect93 Profile Picture autoperfect93 96
    Posted at
    CSV To New Excel Table

    Hi @takolota ,

     

    I have tested the CSV_To_Excel_V1.1 SP Flows. It works but the file I get in SharePoint is empty.


    I think this is due to the action Get file content retrieving the empty excel file created in the "Create file blank Excel"

     

    autoperfect93_0-1715017562063.png

     

    So the step "Create file" actually creates an empty excel file in SharePoint. 

     

  • takolota1 Profile Picture takolota1 4,617
    Posted at
    CSV To New Excel Table

    Version 1.1 SP

    Version 1.1 SharePoint is set up to get the CSV data from a SharePoint file & is set to transfer the new Excel file & new Excel table to SharePoint at the end of the flow.

  • takolota1 Profile Picture takolota1 4,617
    Posted at
    CSV To New Excel Table

    @autoperfect93 

     

    The piece of the flow getting the CSV file content can move to SharePoint to get the file content / CSV text from there.

    Unfortunately the Graph API call only works for files in OneDrive.

    However, with some adjustments we may be able to use a batch create script I have to populate the table instead of the Graph API call.

    https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Excel-Batch-Create-Update-and-Upsert/td-p/1624706

    But using the script instead would reduce performance & limit the CSV size to like 15,000 rows. So you may want to do the CSV to Excel conversion in OneDrive & then move the final Excel file to SP after.