从本地计算机导入一个Excel模板,然后根据Excel模板的字段填充相应的数据,然后保存,保存格式跟模板的要一样。这个在Delphi里面怎么实现,有什么控件可以使用吗?请高手帮忙,非常急,帮忙实现了我高分献上,先谢谢了!

解决方案 »

  1.   

    你说的是什么呢?是不是想把固定格式的EXCEL里的数据导入到数据库?
      

  2.   

    可以用stringgrid来做~~~此Excel模板最好第一列不要为空,根据此列来判断导入行数~~
    既然格式固定,也就是导入到stringgrid中的cell也是固定的了~~~
    然后根据cell[i,j]来填充数据~~
    至于保存应该不是问题了吧~~~
      

  3.   

    使用sql语句导入 如下:
    select cast(fdate as datetime) fdate,cast(forderno as varchar) forderno,cast(fnumber as varchar) fnumber,
    cast(fqty as decimal(28,10)) fqty,cast(fprice as decimal(28,10)) fprice,cast(famount as decimal(28,10)) famount,
    cast(freceiver as varchar) freceiver,cast(ffetchadd as varchar) ffetchadd,
    cast(ffetchstyle as varchar) ffetchstyle,cast(fnote as varchar) fnote,cast(fstockflag as varchar) fstockflag,'' ferrorflag from 
    OPENROWSET('Microsoft.Jet.OLEDB.4.0',
    'Excel 8.0;hdr=yes;Database=D:\TEST.xls', [Sheet1$])
    where isnull(frelateflag,'')<>'Y'
    order by forderno
      

  4.   

    可以用stringgrid来做~~~此Excel模板最好第一列不要为空,根据此列来判断导入行数~~ 
    既然格式固定,也就是导入到stringgrid中的cell也是固定的了~~~ 
    然后根据cell[i,j]来填充数据~~ 
    至于保存应该不是问题了吧~~~ 
    ------------------------------------------------------------------------------------
    你可以说详细一点吗?还有我所说的模板是可以改变的,也就是说里面的列数可以增加和减少,我应该怎么样去判断这个模板有多少列,还有每列的内容(字段名称)。
      

  5.   

    如果格式不固定,则需要根据cell[i,j]中内容来判断了~~例子1: 
      if cell[i,j]='日期' then 
      cell[i,j+1]:=datetostr(now);//在日期下面的格子填日期
    例子2: 
      if cell[i,j]='日期' then 
      cell[i+1,1]:=datetostr(now);//在日期左边的格子填日期