ASP.NET MVC Controls > Controls > FlexSheet > Quick Start: Load Excel to FlexSheet |
The FlexSheet control in your application can be unbound, bound to a data source, and can even display data loaded from an excel file. It offers you a flexible spreadsheet experience, allowing you to load existing excel file or workbook in FlexSheet, modify its data and even save it as an excel or a workbook file remotely or on the client side.
This section discusses how to use FlexSheet control in your application, and load an excel file or workbook instance in it on the server side.
This can be accomplished in the following steps.
Note: The ComponentOne template for ASP.NET MVC Edition automatically registers the required resources, and adds the relevant references and packages to your application. Therefore, you need not follow the Steps 1 to 5 above if your application is created using ComponentOne template. |
The following image shows workbook data loaded from the server in the FlexSheet control.
Complete the following steps to license your application for using FlexSheet control.
licenses.licx |
Copy Code
|
---|---|
C1.Web.Mvc.LicenseDetector, C1.Web.Mvc C1.Web.Mvc.Sheet.LicenseDetector, C1.Web.Mvc.FlexSheet |
For more information on how to add license to your application, refer to Licensing.
Complete the following steps to add the ASP.NET MVC Edition references and FlexSheet references to your project.
Note: |
Complete the following steps to configure your application to use Financial Charts.
web.config
file to open it.<system.web.webPages.razor></system.web.webPages.razor>
tags.
HTML |
Copy Code
|
---|---|
<add namespace="C1.Web.Mvc" /> <add namespace="C1.Web.Mvc.Fluent" /> <add namespace="C1.Web.Mvc.Sheet" /> <add namespace="C1.Web.Mvc.Sheet.Fluent" /> |
_ViewImports |
Copy Code
|
---|---|
@addTagHelper *, C1.AspNetCore.Mvc @addTagHelper *, C1.AspNetCore.Mvc.FlexSheet |
Complete the following steps to register the required resources for using FlexSheet control.
_Layout.cshtml
to open it.<head></head>
tags.
_Layout.cshtml |
Copy Code
|
---|---|
@Html.C1().Styles()@Html.C1().Scripts().Basic().FlexSheet() |
_Layout.cshtml |
Copy Code
|
---|---|
<c1-styles /> <c1-scripts> <c1-flex-sheet-scripts /> </c1-scripts> |
For more information on how to register resources, refer to Registering Resources.
Loading Excel files in FlexSheet and saving FlexSheet data to Excel files have dependency on jszip.min.js file. Therefore, you need to add it in your application, and provide reference to it in the respective view or in <head> section of _Layout.cshtml file. Complete the following steps to add the jszip.min.js file to your application.
Note that, this example considers Visual Studio IIS (Internet Information Services) of your machine as the Server and browser as the client. |
Complete the following steps to initialize a FlexSheet control.
Add a new Controller
Default1Controller
).C# |
Copy Code
|
---|---|
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; |
Add a View for the controller:
Index()
.Index.cshtml
to open it.Index.cshtml |
Copy Code
|
---|---|
<script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script> <div> @(Html.C1().FlexSheet().Load("~/Content/ExcelFiles/WorkBook.xlsx").Width(1500).Height(800) ) </div> |
Index.vbhtml |
Copy Code
|
---|---|
@Imports C1.Web.Mvc @Imports C1.Web.Mvc.FlexSheet.Fluent @Imports C1.Web.Mvc.FlexSheet @Imports C1.Web.Mvc.Grid <script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script> @(Html.C1().FlexSheet() _ .Load("~/Content/ExcelFiles/Product.xlsx") _ .Width("1500px") _ .Height("800px") ) |
HTML |
Copy Code
|
---|---|
<script src= "http://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"> </script> <div> <c1-flex-sheet class="flexSheet" file-path="~/FilestoLoad /Workbook.xlsx" height="800px" width="1500px"></c1-flex-sheet> </div> |