tips for exporting database information to an excel file with the help of ajax request and javascript

Recently, I built an application using NDWS with sapui5 _javascript. Within the application, there is a table that contains data synced with the server's database. My goal is to retrieve this data from the table and export it to an Excel document. Here is the code snippet for triggering this action:

var oExportToExcelButton = new sap.ui.commons.Button( {
            text : "Export to Excel",
            width : '120px',
            style : sap.ui.commons.ButtonStyle.Emph,
            press : function() {

                var jsonDataObject = oController.model.getProperty("/matreqs");
                var taskIdFromView = sap.ui.getCore().byId("taskId").getValue();
                var jsonData = JSON.stringify(jsonDataObject);

                $.ajax("api/wpi/processrequest/getexcelexportfile?taskId="
                    + taskIdFromView, {
                    context : this,
                    type : "POST",
                    processData : false,
                    contentType : "application/json",
                    data : jsonData,
                    error : function(request, status, error) {
                        console.log(error);
                    },
                    success : function(data) {
                        oController.getRequestParameterValue();
                        console.log(data);
                        top.close();
                    }
                });
            }
        });

The getRequestParameterValue() function resides in the controller:

getRequestParameterValue: function(name) {
        var half = location.search.split("&" + name + "=")[1];

        if (!half) half = location.search.split("?" + name + "=")[1];

        return half ? decodeURIComponent(half.split("&")[0]) : null;
    })

I am fairly new to programming, so I apologize if my explanation is not very clear. Any assistance or guidance would be greatly appreciated!

Answer №1

When dealing with data in your Buttons press event, you can easily access it on the client side using

oController.model
            .getProperty("/matreqs");
. From there, you have the ability to send this data to your server-side Service (such as a Java Servlet) to handle the conversion into a valid Excel file.

I recommend using Apache POI for this task, as it has worked well for me in the past.

If you require further information, feel free to reach out.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for Showing Certain Slides When the Page Loads

When using jQuery filter effects to organize div slides on a page, I encountered an issue where all the divs containing different slides are displayed on page load instead of just the default chosen ['active'] div. The filter effect itself is fun ...

A proposal for implementing constructor parameter properties in ECMAScript

TypeScript provides a convenient syntax for constructor parameter properties, allowing you to write code like this: constructor(a, public b, private _c) {} This is essentially shorthand for the following code: constructor(a, b, _c) { this.b = b; thi ...

Stop ajax loading animation for a specific scenario

I usually have a global ajax load animation that runs during every ajax call. However, there are certain cases where I need to disable this effect. How can I achieve that? This is the code for the global animation : $(document).ajaxStart(function(){ $ ...

Utilize Android accelerometer data to bring objects to life with animation

Utilizing an Android app, I am streaming accelerometer data to a Python script on my PC. The data is then saved to a text file. My goal is to utilize Javascript and jQuery to animate a 3D CSS cuboid (representing the device) to replicate the movements capt ...

Can one validate a single route parameter on its own?

Imagine a scenario where the route is structured as follows: companies/{companyId}/departments/{departmentId}/employees How can we validate each of the resource ids (companyId, departmentId) separately? I attempted the following approach, but unfortunate ...

Issue with Firefox compatibility in Backbone.js

Greetings! I am currently utilizing Backbone.js and require.js for my application, experiencing difficulty with template rendering in Firefox. Interestingly, it works without issues in both Chrome and IE. Allow me to present the code responsible for rende ...

What could be the reason for typescript not issuing a warning regarding the return type in this specific function?

For instance, there is an onClick event handler attached to a <div> element. The handler function is supposed to return a value of type React.MouseEventHandler<HTMLDivElement> | undefined. Surprisingly, even if I return a boolean value of fal ...

Unable to open javascript dialog box

One issue I encountered involves a jqGrid where users have to click a button in order to apply any row edits. This button is supposed to trigger a dialog box, which will then initiate an ajax call based on the selected option. The problem lies in the fact ...

Acquiring JSON-formatted data through the oracledb npm package in conjunction with Node.js

I am currently working with oracledb npm to request data in JSON format and here is the select block example I am using: const block = 'BEGIN ' + ':response := PK.getData(:param);' + 'END;'; The block is ...

The array in Ajax is consistently limited to a size of 1

Having an issue with retrieving the value of checked checkboxes using a function. When alerting the values in JavaScript, it shows '1,2,3' which is correct. However, when retrieving it from PHP, the array size is always 1. HTML CODE: function ...

Troubleshooting: AngularJS directive not functioning properly with $http request

This is the structure of my code: View: <form action="./?app,signin" method="post" id="signinform" name="signinform" novalidate vibrating loginform> (...) </form> JavaScript: angular.module('loginApp', []) .directive('log ...

Checking Sudoku Solutions on Codewars

I have come across this JavaScript code which seems to be functioning correctly. However, I am curious about the line board[3][8] != board[8][3] and how it checks for repeating row and column numbers. Can someone please provide an explanation? Thank you! ...

Assign the value/text of a div element by using JavaScript/jQuery within a PHP loop

I'm struggling to figure out how to set the value/text of a div using javascript/jquery inside a loop. Can anyone offer some guidance on this issue? Goals: Extract data from a database. Use javascript/jquery to assign the extracted data to an eleme ...

I have to make sure not to input any letters on my digipas device

There is a slight issue I am facing. Whenever I input a new transfer of 269 euros with the bank account number BE072750044-35066, a confirmation code is required. The code to be entered is 350269. https://i.stack.imgur.com/YVkPc.png The digits 350 corres ...

Move the DIV element to a static section within the DOM

In my Vue app, I have implemented methods to dynamically move a DIV called 'toolbox' to different sections of the DOM. Currently, the DIV is positioned on the bottom right of the screen and remains static even when scrolling. My goal is to use t ...

Implement AJAX in CodeIgniter to send data to a file and receive a response indicating if the operation was successful or not

I am currently working on developing a basic php chat feature for my website using CodeIgniter and Ajax. Rather than storing the messages in a database table, I have opted to save them in an HTML file. However, whenever I try to send a message by clicking ...

Unleashing the potential of an endless animation by incorporating pauses between each iteration

I am trying to create an infinite animation using animate css but I want to add a delay between each iteration. After exploring various options, I first attempted to achieve this using plain JavaScript. Here is the HTML snippet: <div id="item" class= ...

How do you modify the SVG viewport using code?

I am looking to create a feature that allows all images inside an SVG object to be moved. My plan is to use JavaScript, and possibly jQuery, to handle mouse events (down, move, up) in order to change the viewport of the SVG. However, I am currently facing ...

Exploring the power of Foundation For Apps and Angular by seamlessly displaying dynamic data sourced from

I'm currently working with Foundation for Apps, a framework that incorporates elements of AngularJS. My goal is to display the content from a local JSON file by accessing it through a controller and rendering the results as 'cards'. Addition ...

Observing the state of a variable within a directive using a service from a different module

I currently have two modules named "core" and "ui". The "ui" module has a dependency on the "core" module. Below is the code for my core.js file: var core = angular.module('core', [ 'ngRoute' ]); // Services core.service('httpI ...