John John - 1 year ago 102
ASP.NET (C#) Question

Import excel doc, the display in proper format

Just trying to increase my programming ability at the moment so any help would be much appreciated.

In my project i've used (aspx)

<asp:Panel ID="Excel" runat="server">


ExcelFile ef = new ExcelFile();
string fileName = @"C:\\location of excel doc";
ef.LoadXlsx(fileName, XlsxOptions.PreserveMakeCopy);

StringBuilder sb = new StringBuilder();

foreach (ExcelWorksheet sheet in ef.Worksheets)
sb.AppendFormat("------{0}--------", sheet.Name);

foreach (ExcelRow row in sheet.Rows)
foreach (ExcelCell cell in row.AllocatedCells)
if (cell.Value != null)
Label x = new Label();
x.Text = cell.Value.ToString();

sb.AppendFormat("{0}({1})", cell.Value, cell.Value.GetType().Name);


This works fine but it displays the Excel file as a big lump of text clumped together, I would appreciate it if someone could give me a tip or somewhere to get started on how to display the output in a nice table.

Answer Source

You should use a GridView control to display the data fetched from an excel sheet.

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