We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to prevent importing excel file containing unknown formula in Spreadsheet

Platform: JavaScript |
Control: ejSpreadSheet |
Published Date: August 3, 2018 |
Last Revised Date: May 22, 2019

Description

This knowledge base explains how to prevent importing excel file containing unknown formula in Spreadsheet with alert message.

Solution

 It can be achievable by sending PreventUnknownFormulas option with import request in “Spreadsheet.Open()” method.

 

JAVASCRIPT

HTML

 

<div id="Spreadsheet"></div>

 

JS

 

$("#Spreadsheet").ejSpreadsheet({
    importSettings:
    {
        importMapper: "Spreadsheet/Import",
    }
});

 

Web API

 

[AcceptVerbs("POST")]
public string Import()
{
    // Get imported file here, which is imported from file upload control.
    var files = HttpContext.Current.Request.Files;
    ImportRequest importRequest = new ImportRequest();
    //To prevent importing excel with unknown formula
    importRequest.PreventUnknownFormulas = true;
    importRequest.FileStream = files[0].InputStream;
    // Returns the result.
    return Spreadsheet.Open(importRequest);
}

 

MVC

CSHTML

 

@(Html.EJ().Spreadsheet<object>("Spreadsheet")
    .ImportSettings(import =>
    {
        import.ImportMapper("Home/Import");
    })
)

 

C#

 

public string Import(ImportRequest importRequest)
{
    //To prevent importing excel with unknown formula
    importRequest.PreventUnknownFormulas = true;
    // Returns the result.
    return Spreadsheet.Open(importRequest);
}

 

ASP

ASPX

 

<ej:Spreadsheet ID="Spreadsheet" runat="server">
    <ImportSettings ImportMapper="SpreadsheetHandler.ashx" />
</ej:Spreadsheet>

 

ASHX.CS

 

public void ProcessRequest(HttpContext context)
{
    var files = context.Request.Files;
    ImportRequest importRequest = new ImportRequest();
    //To prevent importing excel with unknown formula
    importRequest.PreventUnknownFormulas = true;
    importRequest.FileStream = files[0].InputStream;
    string SpreadsheetData = Spreadsheet.Open(importRequest);
    context.Response.Write(SpreadsheetData);
}

 

The following output is displayed as the result of above behavior,

 

spreadsheet importing sample preview

Figure: Notify the user with message when excel file with unsupported formula is imported in Spreadsheet.

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon