1、将不规则的Excel文件,读到页面上,展现为Table.2、在读的过程中替换单元格内容,原Excel文件内容:
|-----|-----|-----|------|-----|-----|-----|-----|
|  a  |  b  |  c  |  d   |  e  |  f  |  g  |  h  |
|-----|-----|-----|------|-----------|-----------|
|1、4 |     |     |      |           |           |
|-----|-----|-----|------|    2.2    |           |
|     |     |     |      |           |           |
|-----|-----|-----|------|-----------|-----------|
|     |     |     |      |           |           |
|-----|-----|-----|------|           |           |
|     |     |     |      |           |           |
|-----|-----|-----|------|-----------|-----------|
 比如1.4,代表后面4列都要替换成数据源(select * from a)的前4列数据
 2.2,   代表后面2列都要替换成数据源(select * from b)的前2列数据看看怎么实现,有原码最佳!

解决方案 »

  1.   

    动态写html代码可以实现,不过很麻烦
      

  2.   

    命名空间using System.Data.OleDb;
    private void excelRead()
    {  
    string pathExcel="haha.xls";   //excel路径 //读取Excel
    pathExcel=Server.MapPath(pathExcel);
    string myString="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" +pathExcel+"';Extended Properties=Excel 8.0";
    OleDbConnection cnnXls = new OleDbConnection(myString); string sqlInBox="select*from [sheet1$]";
    OleDbDataAdapter drInBox=new OleDbDataAdapter(sqlInBox,cnnXls); DataSet dsInBox=new DataSet();
    drInBox.Fill(dsInBox); 

    if(dsInBox.Tables[0].Rows.Count>0)
    {
    for(int i=0;i<dsInBox.Tables[0].Rows.Count;i++)
    {
    string a1=dsInBox.Tables[0].Rows[i].ItemArray[0].ToString().Trim();
    string a2=dsInBox.Tables[0].Rows[i].ItemArray[1].ToString().Trim();
    string a3=dsInBox.Tables[0].Rows[i].ItemArray[2].ToString().Trim();
    Response.Write(a2);
    } }
    }
      

  3.   

    我测试得出 读取得excel
    ---------------------
    name | pwd | ooo |
    ---------------------
         |           |
    -----            ----
         |d          |  
    ---------------------
    第二次读 第二列的为 d 其余的为空我想你的问题已经可以解决了 呵呵
      

  4.   

    ghjhot(ghjhot),你的代码,我看了,看不出来和我问的功能有什么关系.