سؤال

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

In my asp.net project i've used (aspx)

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

(aspx.cs)

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.AppendLine();
            sb.AppendFormat("------{0}--------", sheet.Name);

            foreach (ExcelRow row in sheet.Rows)
            {
                sb.AppendLine();
                foreach (ExcelCell cell in row.AllocatedCells)
                {
                    if (cell.Value != null)
                    {
                        Label x = new Label();
                        x.Text = cell.Value.ToString();
                        Excel.Controls.Add(x);

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

        Console.WriteLine(sb.ToString());

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.

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top