FlexSheet supports loading data in it from an Excel file or workbook provided by client. Moreover, it allows saving the data in FlexSheet to Excel file or workbook on client-side.
The following code examples demonstrate how to enable client loading of excel in FlexSheet. In the below example, client loading of excel occurs on button click. Load method is called when a user clicks on the button to load excel data in FlexSheet.
ClientLoadController.cs
C# |
Copy Code
|
---|---|
public class ClientLoadController : Controller { // GET: /<controller>/ public ActionResult Index() { return View(); } } |
ClientLoad.cshtml
HTML |
Copy Code
|
---|---|
<script> function load() { var flex = wijmo.Control.getControl("#clientLoadSheet"); var fileInput = wijmo.getElement('#importFile'); if (flex && fileInput.files[0]) { flex.load(fileInput.files[0]); } } </script> <div> <input type="file" class="form-control" id="importFile" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" /> <button class="btn btn-default" onclick="load()">Load</button> <br /><br /> <c1-flex-sheet class="flexSheet" id="clientLoadSheet" selected-sheet-index="0" width="500px" height="700px"> <c1-unbound-sheet column-count="8" row-count="20" name="Unbound"></c1-unbound-sheet> </c1-flex-sheet> </div> |
Saving the FlexSheet data to an Excel file or workbook is also supported on the client side. This can be accomplished through save method. The following code examples demonstrate how to enable saving FlexSheet data to Excel file on the client side. In the below example save method is invoked on button click.
ClientSaveController.cs
C# |
Copy Code
|
---|---|
public class ClientSaveController : Controller { // GET: /<controller>/ public static List<Sale> SALES = Sale.GetData(50).ToList(); public ActionResult Index() { return View(SALES); } |
ClientSaving.cshtml
HTML |
Copy Code
|
---|---|
@using C1MvcFSheetNew.Models; @model IEnumerable<sale> <script> function save() { var flex = wijmo.Control.getControl("#clientSaveSheet"); var fileNameInput = wijmo.getElement("#fileName"); var fileName = 'FlexSheet.xlsx'; flex.save(fileName); } </script> <div> <button class="btn btn-default" onclick="save()">Save</button> <br /><br /> <c1-flex-sheet class="flexSheet" id="clientSaveSheet" selected-sheet-index="0" width="500px" height="700px"> <c1-bound-sheet> <c1-items-source source-collection="Model"></c1-items-source> </c1-bound-sheet> <c1-unbound-sheet column-count="8" row-count="20" name="Unbound"></c1-unbound-sheet> </c1-flex-sheet> </div> |