ASP.NET MVC Spreadsheet Overview
The Spreadsheet is part of Telerik UI for ASP.NET MVC, a
professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.
The Telerik UI Spreadsheet HtmlHelper for ASP.NET MVC is a server-side wrapper for the Kendo UI Spreadsheet widget.
The Spreadsheet allows you to edit and visualize tabular data by using cell formatting options, styles, and themes.
Initializing the Spreadsheet
The following example demonstrates how to define the Spreadsheet.
@(Html.Kendo().Spreadsheet()
.Name("spreadsheet")
.Sheets(sheets => {
sheets.Add()
.Name("Food Order")
.MergedCells("A1:F1", "C15:E15")
.Columns(columns =>
{
columns.Add().Width(100);
columns.Add().Width(215);
columns.Add().Width(115);
columns.Add().Width(115);
columns.Add().Width(115);
columns.Add().Width(155);
})
.Rows(rows =>
{
rows.Add().Height(50).Cells(cells =>
{
cells.Add()
.Value("My Company")
.FontSize(25)
.Background("rgb(142,196,65)")
.TextAlign(SpreadsheetTextAlign.Center)
.Color("white");
});
rows.Add().Height(25).Cells(cells =>
{
cells.Add()
.Value("ID")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Product")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Quantity")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Price")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Tax")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Amount")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
});
});
})
)
public class SpreadsheetController : Controller
{
public ActionResult Index()
{
return View();
}
}
Basic Configuration
The following example demonstrates the basic configuration for the Spreadsheet component.
@(Html.Kendo().Spreadsheet()
.Name("spreadsheet")
.Rows(10)
.Columns(10)
.Sheetsbar(true)
.Toolbar(true)
.HtmlAttributes(new { style = "width:100%" })
.Toolbar(t => t.Home(true).Data(false).Insert(false))
.Excel(excel => excel
.ProxyURL(Url.Action("Index_Save", "Spreadsheet"))
)
.Pdf(pdf => pdf
.ProxyURL(Url.Action("Index_Save", "Spreadsheet"))
)
.Sheets(sheets =>
{
sheets.Add()
.Name("Food Order")
.MergedCells("A1:F1", "C15:E15")
.Columns(columns =>
{
columns.Add().Width(100);
columns.Add().Width(215);
columns.Add().Width(115);
columns.Add().Width(115);
columns.Add().Width(115);
columns.Add().Width(155);
})
.Rows(rows =>
{
rows.Add().Height(50).Cells(cells =>
{
cells.Add()
.Value("My Company")
.FontSize(25)
.Background("rgb(142,196,65)")
.TextAlign(SpreadsheetTextAlign.Center)
.Color("white");
});
rows.Add().Height(25).Cells(cells =>
{
cells.Add()
.Value("ID")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Product")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Quantity")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Price")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Tax")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
cells.Add()
.Value("Amount")
.Background("rgb(212,223,50)")
.TextAlign(SpreadsheetTextAlign.Center);
});
});
})
)
Functionality and Features
- Comments
- Custom functions
- Cell formatting
- Images
- Import and export of data
- End user guide
- Sorting and Filtering
- Disabled Cells
- Validation
- Custom Cell Editors
Events
You can subscribe to all Spreadsheet events. For a complete example on basic Spreadsheet events, refer to the demo on using the events of the Spreadsheet.
The following example demonstrates how to subscribe to the changing
and change
events.
@(Html.Kendo().Spreadsheet()
.Name("spreadsheet")
.Events(events => events
.Changing("onChanging")
.Change("onChange")
)
.Sheets(sheets =>
{
sheets.Add()
.Name("Sheet1")
.Columns(columns =>
{
columns.Add().Width(115);
})
.Rows(rows =>
{
rows.Add().Height(25).Cells(cells =>
{
cells.Add()
.Value("ID")
.TextAlign(SpreadsheetTextAlign.Center);
});
});
})
)
<script>
function onChanging(e) {
// Handle the changing event.
}
function onChange(e) {
// Handle the change event.
}
</script>
Referencing Existing Instances
To reference an existing Kendo UI Spreadsheet instance, use the jQuery.data()
configuration option. Once a reference is established, use the Spreadsheet client-side API to control its behavior.
// Place the following after the Spreadsheet for ASP.NET MVC declaration.
<script>
$(document).ready(function() {
// The Name() of the Spreadsheet is used to get its client-side instance.
var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
});
</script>