AZhu AZhu -4 years ago 118
ASP.NET (C#) Question

C# Passing data back from Excel to Datagrid in ASP.NET Web Application

I have a ASP.NET web application (Not the MCV application) that is deployed on IIS Express, which calls a Powershell script that invokes an Excel instance on the server and run some macro in the Excel instance.

The end results is currently dumped into a specific range in Excel and I would like to make the results somehow visible in a data grid (or other ways to display it, it is basically just a 6 columns by 20 rows table with headings and numbers) in the web page where it is being called so that the end user who have no access to the server itself could see it.

Is that possible at all? If so how should I do it?

Answer Source

If you've saved your data as .cvs file, open it as a File and put all data in a string, rows are separated with '\n' and '\r' and columns with ','. By using Split(String data, Char separator) method for 2 times and putting it in an array as, you'll be able to cut your data from string and fill it in a DataGrid.

String data = File.ReadAllText(fileName);
String[] myColumns = Split(data,'\n');
String[] myRows = Split(data,',');

The first row is always your column's headers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download