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.
Unfortunately, activation email could not send to your email. Please try again.

Scalable strategy for Excel formula in web applications

By using XlsIO we can do the calculation in server side and view the result in the client side using the memory effectively. This topic gives an overview of how to create a web service that loads an excel template and displays calculated values using Essential XlsIO and their scalability.

 

Steps to achieve this

 

  1. Create a Web Service project
  1. Initialize XlsIO and perform excel formula calculations

 

  1. Create a Web Application project
  1. Refer the Web Service link and initialize the service in the Web Application
  2. Update calculated values in the web application through web service

   

Create a Web Service

 

  1. Create an empty web application and add Web Service (ASMX) item into the project.

 

  1. Refer the below dlls
  1. Syncfusion.Compression.Base.dll
  2. Syncfusion.XlsIO.Web.dll

 

  1. Use the namespace Syncfusion.XlsIO in web service class (WebService1).

 

C#

 

Below code snippet demonstrates on how to create a web service program for calculating values.

 

  1. Initialize ExcelEngine object and open the excel workbook template (FederalTaxCalculatorTemplate.xlsx) in web service class (WebService1).

 

C#

 

  1. Add SetValues and GetValues and GetDefaultValues methods in the class (WebService1). The SetValues method sets the values into worksheet. The GetValues method returns XlsIO calculated values from the worksheet.

 

C#

 

 

  1. Host the Web Service using IIS (Internet Information Services) and browse the web service and copy the link.

 

Create a Web Application

 

  1. Create an empty web application and add a Web Form item named default.aspx into the project.

 

  1. The scenario used here is to calculate Federal Tax Estimation. So, the web page must be designed accordingly. The following screen shot shows the UI part of the application.

 

Figure 1 – UI Screen before Calculation

 

  1.  Here, the input fields are:
  1. Tax Filing Status
  2. No. of filers over age 65
  3. No. of personal exemptions
  4. No. of dependent children
  5. Gross annual income
  6. Adjustments
  7. Itemized deduction

 

The rest of the fields are used to display calculated values from excel workbook.

  1. Now, right-click WebApplication1 project from Solution Explorer and click Add->Service Reference->Advanced->Add Web Reference. Paste the web service link copied earlier in the URL field and click Add Reference button.

 

  1. Following namespace must be used in _default class to initialize web service and access its public methods.

 

C#

 

  1. Initialize the class WebService1 in the _default class.

 

C#

 

  1. Get calculated values from worksheet to display in its respective UI fields. The following code snippet can be used to achieve this.

 

C#

 

  1. Submit button sets the input values to the worksheet and returns its calculated values. The following code snippet illustrates that.

 

C#

 

  1. The following screen shot shows the output of the sample. For the given Gross Income 75000, the tax estimation is calculated by XlsIO and the calculated values are displayed in its respective fields as shown.

Figure 2 – UI Screen after Calculation

 

Note: The tax calculation is just to illustrate the calculation at API levels using Essential XlsIO and not exactly the scale of federal tax estimation.

 

The above sample can be downloaded here.

 

Performance:

  • The memory consumed in the server per user is 10MB. If 10 users access this service an approximate of 100MB is consumed in the server.
  • The execution is faster as the service returns values from the server.
  • The calculated values doesn’t overwrite the cell values and doesn’t affect the calculation of other users.

 

Article ID: Published Date: Last Revised Date: Platform: Control:
5418 09/15/2015 09/15/2015 ASP.NET Web Forms (Classic) XlsIO
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.