数据导出EXCEL的问题

Description of your first forum.

数据导出EXCEL的问题

帖子love_yb97 » 星期二, 2010年1月5日 16:24


数据格式如下(大概有3千条记录)
 字段一             字段二         字段三
煤气发生量 测管流量计A    28160073
煤气发生量 差压变送器   5002957
混合煤气          差压变送器   4977266
混合煤气           压力变送器   DXY0005
混合煤气          热电阻   无
。。。。。。。。。。。。。。。。。
上述记录我可以导出到EXCEL中,但有一个问题,我需要将“字段一”相同内容在导出时候进行单元格合并,在delphi中如何操作,请高手详细告之,谢谢。
导出excel结果:(就是对字段一相同数据进行合并)
 字段一             字段二         字段三
                   测管流量计A    28160073
煤气发生量        差压变送器   5002957
                   差压变送器   4977266
混合煤气           压力变送器   DXY0005
                   热电阻   无
 
 
 

数据导出EXCEL的问题

帖子szhcracker » 星期二, 2010年1月5日 17:05


不大明白LZ的意思
 
 
 

数据导出EXCEL的问题

帖子79023864 » 星期二, 2010年1月5日 17:47


有个第三方控件 XLSREADWRITEII,可以达到你的目的
网上找找呗
 
 
 

数据导出EXCEL的问题

帖子chyzpc » 星期三, 2010年1月6日 08:18


QQ:292044357
我有专用技术,不便附代码
 
 
 

数据导出EXCEL的问题

帖子zhengrong117 » 星期三, 2010年1月6日 09:38


uses comobj

procedure MergeCells(FileName: string);
  function GetRepRange(x, y: integer): string;
  var fX, fY: string;
  begin
    if y <= 0 then
      fX := 'A';
    if y <= 26 then
      fX := chr(64 + y);
    if y > 26 then
      fX := chr(64 + (y div 26)) + chr(64 + (y mod 26));

    fY := IntToStr (x);
    Result := fX + fY;
  end;
var //
  i, j: integer;
  s1, s2: string;
  Excel: Variant;
  WorkBook: Variant;
  xl: olevariant;
begin
  Excel := CreateOLEObject('Excel.Application');
  Excel.WorkBooks.Open(FileName);
  Excel.WorkSheets[1].Activate;
  WorkBook := Excel.ActiveWorkBook;
  try
    Excel.Application.ScreenUpdating := False;
    Excel.Application.DisplayAlerts := False;

    j := 1;
    while Trim (Excel.Cells[j, 1].Value) <> '' do begin
      s1 := Trim(Excel.Cells[j, 1].Value);
      s2 := Trim(Excel.Cells[j + 1, 1].Value);
      i := j + 1;
      while s1 = s2 do begin
        Inc(i);
        s2 := Trim(Excel.Cells[i, 1].Value);
      end;
      Dec(i);
      Excel.Range[GetRepRange(j, 1) + ':' + GetRepRange(i, 1)].Merge(xl);
      j := i + 1;
    end;
  finally
    Excel.ActiveWorkBook.Save;
    Excel.DisplayAlerts := False;
    WorkBook.Close;
    Excel.DisplayAlerts := False;
    Excel.Quit;
    Excel := Unassigned;
    VarClear(Excel);
  end;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
  MergeCells('C:\01.xlsx');
end;
 
 
 

数据导出EXCEL的问题

帖子love_yb97 » 星期四, 2010年1月7日 12:38


已经自己解决问题了,谢谢各位捧场!!
 
 
 

数据导出EXCEL的问题

帖子love_yb97 » 星期四, 2010年1月7日 12:39


多人接受答案了。