RealGrid2 Guide
Export to Excel 🆕
Excel Export

excel export

Convert the dataset to an Excel file according to the column structure displayed in the current grid and save it as a local file or upload it to the server.

※ The jszip library is required to use the export function.

<script src="/scripts/jszip.min.js"></script>

Excel export

Exports the appearance and data of the current grid to an external document according to the settings specified with the exportGrid() function.

Specify whether to include the area in the document.

  • default - Prints as is currently displayed in the grid.
  • visible - The output includes the relevant area unconditionally.
  • hidden - Do not include unconditionally. In the GridExportOptions API document, you can check the setting model specified when exporting the grid displayed on the screen to an external document such as Excel.
var excelType = Boolean(
    document.querySelector('input[name="excelType"]:checked').value
);
var showProgress = document.getElementById("chkShowProgress").checked;
var indicator = document.querySelector('input[name="indicator"]:checked').value;
var header = document.querySelector('input[name="header"]:checked').value;
var footer = document.querySelector('input[name="footer"]:checked').value;
 
gridView.exportGrid({
    type: "excel",
    target: "local",
    fileName: "gridExportSample.xlsx",
    showProgress: showProgress,
    progressMessage: "Exporting to Excel.",
    indicator: indicator,
    header: header,
    footer: footer,
    compatibility: excelType,
    done: function () {
        //Function to be executed after export is complete
        alert("done excel export");
    },
});

Remote Excel export

If you want to send Excel data to the server and download it from the server, you can specify target: "remote", url: "server processing address". JAVA MVC Project sample files can be downloaded from the link below.

Remote Export Sample

//Client
gridView.exportGrid({
    type: "excel",
    target: "remote",
    url: "/remote/ExcelXBin",
    fileName: "gridExportSample.xlsx",
});
package com.realgrid.remote;
 
import java.io.OutputStream;
import java.util.Base64;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
@Controller
public class ExcelXBin {
    @RequestMapping(value="/ExcelXBin", method=RequestMethod.POST)
    public void excelXBin(HttpServletRequest request, HttpServletResponse response) throws Exception {
        // Receive
        String fileName = request.getParameter("fileName");
        String data = request.getParameter("data");
 
        if (data.length() > 0) {
        // Decode
        byte[] filedata = Base64.getDecoder().decode(data);
 
        // Response Header
        response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
        response.addHeader("Content-Type","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.addHeader("Pragma", "no-cache");
 
        //Write
        OutputStream os = response.getOutputStream();
        os.write(filedata);
        os.flush();
        }
    }
 
}