【问题标题】:how to get the header values of an attached excel sheet in MVC3 Razor如何在 MVC3 Razor 中获取附加的 excel 表的标题值
【发布时间】:2013-03-20 13:47:32
【问题描述】:

在我的 MVC3 Razor 项目中,我有一个疑问。 情况是这样的: 1)我有一个前端,我有一个文件上传和下一页导航按钮。

@using (Html.BeginForm("ConvertToUniCode", "Import", FormMethod.Post, new {enctype = "multipart/form-data"})) { 

        <table>
            <tr><td></td><td></td><td></td></tr>
            <tr>
                <td>
                    <label>Choose File:<input id="selectfile" type='file' data-val="true" data-val-required="please select a file" name='file' /></label></td>
                <td>
                    <input type="submit" value="Next" /></td>
                <td></td>
            </tr>

        </table>
       }

控制器:

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ConvertToUniCode(HttpPostedFileBase file)
        {
        //HttpPostedFile file= new HttpPostedFile();
            if(file.ContentLength>0)
            {
                string fileName =Path.GetFileName(file.FileName);
                string fileSavePath = Server.MapPath("~/App_Data/ImportFileHome/"+ fileName);
                file.SaveAs(fileSavePath);
                FileStream fs = new FileStream(fileSavePath, FileMode.Open, FileAccess.Read);


//Here i need to get the header coloumn values.
            }
2) In the Second page i have a DropDownListFor control for binding the header values one by one.
3) Todo that i need to read the excel sheet header coloumn values.

Excel表格是这样的。

-------------------------------
  Name   |   Age   | Address |    ==> Coloum Header
-------------------------------
jasper   | 26      |India    |

我需要获取标题值名称、年龄、地址。 如何做到这一点。

【问题讨论】:

    标签: asp.net-mvc razor


    【解决方案1】:

    您可以使用 OLEDB。您可以从 this question 收集此信息,它使用 DataTable 方法定义此代码:

    DataTable schemaTable = connection.GetSchema("Columns");
    // Each row can then get the column via:
    string name = (string)row["COLUMN_NAME"];
    

    【讨论】:

      猜你喜欢
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-09
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多