Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
INC02778
Explorer
2,152

In this blog post, we’ll walk through how to implement Excel file export functionality in SAP Build Apps using a base64-encoded string. This use case is particularly useful when you're working with data returned from a backend API in base64 format—such as when exporting filtered reports or datasets.

Upon applying filters and invoking the backend API, the response returns the Excel file encoded in base64. This string is then stored in a Page Variable, decoded using a JavaScript logic block, and converted into a Blob URL. The Blob URL allows the app to seamlessly trigger a file download, giving users a smooth and intuitive experience.


Step-by-Step Implementation

Step 1: Create a Page Variable

Create a Page Variable to store the base64-encoded string returned by your backend API.

Build Apps Blog 1.png

INC02778_0-1747748367708.png

Step 2: Add a JavaScript Block

In the Logic Editor, drag in a JavaScript block and pass the base64 string to it as an input.
Set the output of the JavaScript block to type URL (Any Protocol).

Paste the following code into the JavaScript block:

 

// Helper: create Blob URL instead of data: URL
function createBlobURL(base64String, mimeType = "application/octet-stream") {
    const byteCharacters = atob(base64String);
    const byteNumbers = new Array(byteCharacters.length);
    for (let i = 0; i < byteCharacters.length; i++) {
        byteNumbers[i] = byteCharacters.charCodeAt(i);
    }
    const byteArray = new Uint8Array(byteNumbers);
    
    const blob = new Blob([byteArray], { type: mimeType });
    return URL.createObjectURL(blob);
}

// Example usage:
const base64Data = inputs.base64Data;
const mimeType = inputs.mimeType || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

const blobURL = createBlobURL(base64Data, mimeType);
console.log(blobURL);

return { result: blobURL };

This function takes the base64-encoded string, decodes it, and converts it into a downloadable Blob URL that can be used in the subsequent download logic.

INC02778_1-1747748495496.png

Step 3: Install Required Flow Functions

From the Marketplace, install the following two flow functions:

  • Download Files

  • Export to Downloads

Build apps blog 2.png

Step 4: Design the Flow Logic

Connect the flow in the following sequence:
JavaScript Block → Download Files → Export to Downloads

This setup ensures the decoded file is first processed and then downloaded properly to the user’s device.

INC02778_0-1747749498842.png

Step 5: Configure the Download Files Block

  • Set the Download URL input to the output of the JavaScript block (the Blob URL).

  • Configure the filename and other settings as required.

INC02778_1-1747749575475.png

Step 6: Configure the Export to Downloads Block

  • Map the inputs of this block to the corresponding outputs of the Download Files block.

  • This will save the file to the user's local device through the export mechanism.

INC02778_2-1747750766277.png

Final Result

Once the user triggers the flow (e.g., by clicking a button), the backend API is called, and the returned base64-encoded Excel file is converted and downloaded — all within the SAP Build Apps environment.

This approach offers a clean, no-code/low-code solution to implementing Excel export functionality, even when the application is consumed via SAP Build Workzone there won't be any issue in exporting the file.

 

 

 

4 Comments