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
Create a Page Variable to store the base64-encoded string returned by your backend API.
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.
From the Marketplace, install the following two flow functions:
Download Files
Export to Downloads
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.
Set the Download URL input to the output of the JavaScript block (the Blob URL).
Configure the filename and other settings as required.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 60 | |
| 33 | |
| 23 | |
| 21 | |
| 19 | |
| 16 | |
| 16 | |
| 15 | |
| 15 | |
| 10 |