【问题标题】:Import excel doc, the display in proper format导入excel doc,以正确的格式显示
【发布时间】:2013-01-15 11:09:15
【问题描述】:

目前只是想提高我的编程能力,因此非常感谢任何帮助。

在我的 asp.net 项目中我使用过 (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());

这很好用,但它会将 Excel 文件显示为一大块聚集在一起的文本,如果有人能给我提示或在某个地方开始如何在漂亮的表格中显示输出,我将不胜感激。

【问题讨论】:

    标签: asp.net excel import-from-excel


    【解决方案1】:

    您应该使用 GridView 控件来显示从 Excel 工作表中获取的数据。

    【讨论】:

    • 你能给我一个例子吗?
    猜你喜欢
    • 1970-01-01
    • 2019-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 2020-03-30
    • 2019-10-15
    相关资源
    最近更新 更多