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

Identifying the HTML elements beneath the mouse pointer

Does anyone know the method to retrieve the HTML tag located directly under the mouse cursor on a webpage? I am currently developing a new WYSIWYG editor and would like to incorporate genuine drag and drop functionalities (rather than the common insert at ...

reCAPTCHA v3 - Alert: There are no existing reCAPTCHA clients available

After coming across a similar issue on Stack Overflow (link to the question here), I attempted to implement reCAPTCHA on my website to combat spam emails received through the form. Despite following Google's instructions, I encountered an error that p ...

Bootstrapvalidator does not function properly with select2.js

My code is not validating the select field. What could be causing this issue? Can anyone provide a solution? Apologies for my poor English, and thank you in advance for your response. Here is my form: <form name="form_tambah" class="form_tambah"> ...

Issue encountered while validating password using regex pattern?

There seems to be an issue with password validation when requiring 1 upper case, 1 lower case, 1 number, and 1 special character. methods: { validateBeforeSubmit() { this.$validator.localize('en', dict) this.$validator.validate ...

Issue with Electron Remote process failing to take user-defined width and height inputs

I'm currently facing an issue with utilizing remote windows in electron. I am attempting to process user input and use that input to generate a new window with specific width and height. However, when I hit submit, nothing happens. I can't figur ...

Ways to resolve the error message "TypeError: 'setOption' is not a function on type 'MutableRefObject' in React"

CODE export default function EChart({ option, config, resize }) { let chart = useRef(null) let [chartEl, setChartEl] = useState(chart) useEffect(() => { if (resize) { chartEl.resize() } if (!chartEl.cu ...

The jQuery ajax request functions properly on Internet Explorer but does issues arise when used on Firefox, Chrome, or Opera browsers

I have created a test web page to call a WebApi URL and receive a response. The functionality works perfectly in Internet Explorer, but fails in all other browsers. Below is the jQuery code snippet I am using: $(document).ready(function() { jQuery("# ...

What could be causing my JavaScript code to fail to add data when the submit button is

I'm currently working on a Hot and Cold App using JS and jQuery. The problem I'm facing is that upon form submission, the user input inserts a number, and the game should provide feedback by telling them if it's hot, cold, hotter, or colder ...

JavaScript takes the spotlight before CSS

Currently experiencing this issue in Chrome, although Firefox seems to be working fine so far. Here is a greatly simplified version of the problem: HTML: <div class="thumbnail"> <a href='#' id="clickMe">Click me!</a> </d ...

When attempting to send JSON data using Ajax, you may encounter an issue such as receiving an error message

I am currently working on developing a login with Facebook application using Codeigniter. My challenge is passing JSON data to my controller through AJAX. This is the code snippet I am using: var data = JSON.stringify(response); alert(data); $.ajax ...

Issues with the functionality of Google Translate's JavaScript code snippet are causing

After trying out the code snippet provided on w3schools.com, I encountered a discrepancy between the results displayed on the website and those on my personal computer. <div id="google_translate_element"></div> <script> function googleT ...

Utilizing AJAX to dynamically update a DIV element in CodeIgniter's controller

I need to continuously update a small chat between two users every minute. The functionality is working, but I am struggling with implementing an AJAX call to update the DIV that displays the messages. var interval window.onload = function(){ interval ...

Experiencing difficulty in connecting with the service providers

What's the process for obtaining these providers? I recently followed the JavaScript Mastery tutorial step by step, however, I encountered an issue with the useEffect hook to fetch the providers (I even tried using alert to check, but it keeps showin ...

Having issues retrieving a JSON array in PHP with the json_decode function

Can someone assist me with passing and returning an array to a PHP script? I have successfully tested the json_encode portion, but I am facing issues with the json_decode on the PHP side. Javascript scid_list = []; $('.filter_on').each ...

The relative link feature in React Router fails to properly navigate

Currently, I am utilizing the npm package react-router-relative (https://www.npmjs.com/package/react-router-relative) for my project. However, it seems to be having trouble properly switching the URL. Here is how my links are configured: <Link to=&apo ...

Ways to pass a class list from a client to a webmethod using AJAX

I have a list of client-side classes in TypeScript that I need to send to a web method. Here is my TypeScript code: class MakeReportData { LocalName: string; FldSi: number; ViewSi:number; TypeName:string ; CheckBoxshow :boolean ; ...

I came across a fascinating finding during my JavaScript studies, but its origin remains a mystery to

I recently wrote some code and was surprised to find that it did not generate any output. Here is the snippet of code: var a1 = undefined; var a2 = 5; if(a1 > a2) alert(1); if(a1 < a2) alert(2); if(a1 >= a2) alert(3); if(a1 <= a2) ...

What could be the reason for the failure of .simulate("mouseover") in a Jest / Enzyme test?

I have a scenario where a material-ui ListItem triggers the display of a material-ui Popper containing another ListItem on mouse over using the onMouseOver event. While this functionality works as expected, I am facing difficulties replicating the behavior ...

What is the purpose of returning a function in a React Hook?

Currently, I am incorporating Material-UI components into my project and have implemented the AutoComplete component in my application. While exploring an example provided by the Material-UI team, I stumbled upon a fascinating instance of using Ajax data ...

The latest Chrome update has caused a decrease in rendering and loading speeds for Ajax and Angular network

It has been around two weeks since a Chrome update caused trouble for users of my angular app. Previously, the entire single page application loaded in under 4 seconds, but after the update, every user was experiencing load times exceeding 40 seconds. Surp ...