一个word文档,里面有个不规则的表格式的模板。现在想根据一个数据集的内容来填充这份word并打印,要求一页要打印指定个数的表格式内容。用vba宏录制过,发现对粘贴上去的表很难控制其起点。有其它好方法么!?

解决方案 »

  1.   

    /// <summary> 
    /// 从Excel读取数据 
    /// </summary> 
    /// <param name="filePath">路径</param> 
    /// <returns>DataSet</returns> 
    public DataSet ImportFromExcel(string filePath) 

    DataSet ds = new DataSet(); 
    string connString = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = " + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""; 
    DataTable table = OleDbHelper.GetExcelTables(connString); 
    if(table == null || table.Rows.Count <= 0) 

    return null; 
    } foreach(DataRow dr in table.Rows) 

    string cmdText = "select * from [" + dr["TABLE_NAME"].ToString() + "]"; 
    DataTable dt = OleDbHelper.FillDataTable(connString, cmdText); 
    dt.TableName = dr["TABLE_NAME"].ToString(); 
    ds.Tables.Add(dt); 
    } return ds; 
    } 接下来只要把DataSet写入数据库
      

  2.   

    记得好像有个第三方的控件做这个事情挺好的,可以自己根据宏命令将数据集的内容插入到word中去