我怎样建立一个word模板(空白表格,多页、多字段),然后把数据库中数据添入其中呢?

解决方案 »

  1.   

    var
      SavePath: OleVariant;
      Word:Variant;
      MyDoc:Variant;
      MyTable:Variant;
      Range: Variant;
      i,j: Integer;
    begin
      if SaveDialog.Execute then
        SavePath:=SaveDialog.FileName;
      Word :=CreateOleObject('word.application');
      Word.visible :=True;
      MyDoc :=Word.Documents.add;
      if FGrid=Grid then
        begin
          Word.Selection.TypeText('数据库表说明');
        end;
      if FGrid=EGrid then
        begin
          Word.Selection.TypeText('表'+Grid.Cells[1,FRow].ForeText+'的结构说明');
        end;
      Word.Selection.Font.Name:='宋体';
      Word.Selection.Font.Size:=9;
      Range :=Word.Selection.Range;
      MyTable :=MyDoc.tables.Add(Range,FGrid.RowCount-1,FGrid.ColCount-2);
      for j:=2 to FGrid.ColCount-1 do
        begin
          MyTable.Columns.Item(j-1).Width:=FGrid.ColWidths[j];
          for i:=1 to FGrid.RowCount-1 do
            MyTable.Cell(i,j-1).Range.Text:=FGrid.Cells[j,i].ForeText;
        end;  MyDoc.SaveAs(SavePath);
      

  2.   

    谢谢石之轩的指点,我是一个初级Delphi,对你上面提到的有些地方不明白:比如:if FGrid=Grid then//FGrid是变量吗?在这里起到什么作用呢?
        begin
          Word.Selection.TypeText('数据库表说明');
        end;
      if FGrid=EGrid then//EGrid又是值得什么呢?
        begin
          Word.Selection.TypeText('表'+Grid.Cells[1,FRow].ForeText+'的结构说明');
        end;
    另外,我遇到的问题是这种情况:word模板已建好,数据在数据库表中,相当于一个空白表格,然后把库中数据对照位置填入;能帮我吗?这几天把我跟难住了,又要急用,所以请您帮忙,望指教!谢谢。(攒够分数全给你至少100分--累加)
      

  3.   

    在Delphi中利用word的问题在大家的帮助下有了明显的进展,我又遇到了以下问题,望各路高手指点:
      1。Word中有表格,怎样得到该表格?
      2。怎样解决调用word模板时的绝对路径(客户端调用)问题?
      3。怎样使光标定位到某一页(或下一页)?