Excel
Excel
Loading Worksheets
Excel for .NET makes it easy to read Excel files in your applications, and you don't even need to have Microsoft® Excel installed.
Features
Description
Excel for .NET makes it easy to read Excel files in your applications, and you don't even need to have Microsoft® Excel installed. You can use the data from your Excel files in any number of ways. In this demo we use the C1XLBook component to load and extract the data into arrays which are used as the data source for our C1Chart control.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | using Microsoft.AspNetCore.Mvc; using MvcExplorer.Models; using System; using C1.Excel; namespace MvcExplorer.Controllers { public partial class ExcelController : Controller { C1XLBook _xlBook = new C1XLBook(); public ActionResult LoadingWorksheets() { try { _xlBook.Load(Startup.Environment.WebRootPath + "\\Temp\\Houston.xlsx" ); } catch (Exception) { //Response.Write("Unable to load Excel file: Houston.xlsx"); return View(); } DrillDataPoints dps = GetChartData(_xlBook); return View(dps.DrillDataPointSeries); } DrillDataPoints GetChartData(C1XLBook book) { // Get first sheet var sheet = book.Sheets[0]; // Get location, date, and cell count var location = sheet[1, 1].Value as string ; var date = (DateTime)sheet[2, 1].Value; var count = sheet.Rows.Count - 5; // label.Text = string.Format("{0}, {1} points", location, count); // Get values into arrays for charting var drillData = new DrillDataPoints(count); for ( int r = 0; r < count; r++) { drillData.Temperature[r] = ( double )sheet[r + 5, 1].Value; drillData.Pressure[r] = ( double )sheet[r + 5, 2].Value; drillData.Conductivity[r] = ( double )sheet[r + 5, 3].Value; drillData.Ph[r] = ( double )sheet[r + 5, 4].Value; drillData.Depth[r] = r; } drillData.ScaleValues(); // Send data to chart return drillData; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | @using C1.Web.Mvc.Chart @model IEnumerable< DrillDataPoint > < c1-flex-chart id = "ControlId" > < c1-flex-chart-series name = "Temperature" chart-type = "Line" binding = "Temperature" > </ c1-flex-chart-series > < c1-flex-chart-series name = "Pressure" chart-type = "Area" binding = "Pressure" > </ c1-flex-chart-series > < c1-flex-chart-series name = "PressConductivityure" chart-type = "Spline" binding = "Conductivity" > </ c1-flex-chart-series > < c1-flex-chart-series name = "Ph" chart-type = "Line" binding = "Ph" > </ c1-flex-chart-series > < c1-flex-chart-axis c1-property = "AxisX" major-unit = "200" > </ c1-flex-chart-axis > < c1-items-source source-collection = "Model" ></ c1-items-source > </ c1-flex-chart > @section Description{ < p > @Html .Raw(ExcelRes.LoadingWorkSheets_Text0)</ p > } |