MoreBeerMorePower

Power Platform中心だけど、ノーコード/ローコード系を書いてます。

Read CSV file content in Power Apps w/o Flow

The requirement to import CSV files in Power Apps is very popular, and is an expected feature in the case of bulk data registration, for example. So far, it has been known to pass a CSV file to Power Automate, and returns the resulting read text to Power Apps as a response.

In this post, I will show you an advanced technique how to read the contents of a CSV file on Power Apps without using Power Automate.

STEP1. Convert file content to Base64 string

This is recently well-know method to convert file (blob) into base64 (datauri) in Power Apps.

First, put an attachment control which is copied from Form control, an image control, and a button on the screen.

For the Image Control, set the first "Value" of the Attachment Control.

Button is used to convert file content to dataUri using the JSON function. Here the result is set to the variable varDataUri.

Check varDataUri in the some CSV file, you will see that the file contents have been converted to dataUri (base64 string) shown below.

STEP2. Decode Base64 string to plain text

If the resulting Base64 string can be converted (decoded) to plain text, then the CSV file contents can be loaded onto Power Apps.

This method has already been described in my previous post. Here I copied the formula from the blog and replace the input base64 string that is fixed with varDataUri.

mofumofupower.hatenablog.com

However, CSV files may contain a BOM (Byte order mark) in the header, which must be removed if it is included at the beginning of the file. The temporary variable named InputB64 in the expression is rewritten as follows

    InputB64:
        If(
            StartsWith(Substitute(varDataUri,"data:application/octet-stream;base64,",""),"77u/"),
            Substitute(varDataUri,"data:application/octet-stream;base64,77u/",""),//Remove BOM
            Substitute(varDataUri,"data:application/octet-stream;base64,","")
        ),

That's all. With a few very simple steps, we were able to display the CSV file on Power Apps. After this, please check the Internet for several good examples on how to parse the resulting CSV and register the data.

Limitation

In this method, the base64 string is broken down into individual bytes and stored once in an array.

The Sequence function is used to do this, but this function has an upper limit of 50000 lines, so the CSV must be below 50000 characters. (Roughly 48KB)