更正:
  100分求助,怎样将TstringGrid中的内容保存到Word中,并有同样的表格形式,fixedcols:=1,fixedrows:=1时,怎样让其中的,某一行的第一列特别显眼

解决方案 »

  1.   

    var
      MSWord: Variant;
      i,j,k: integer;
    begin
      MSWord := CreateOleObject('Word.BASIC');
      MSWord.FileNew('Normal');
      with StringGrid1 do   //给StringGrid1填数字
        for I := 0 to ColCount - 1 do
          for J:= 0 to RowCount - 1 do
            begin
              K := K + 1;
              Cells[I,J] := IntToStr(K);
            end;
      with StringGrid1 do //将StringGrid1的内容导出
        for I := 0 to ColCount - 1 do
          begin
          MSWord.InsertBreak;
          for J:= 0 to RowCount - 1 do
            begin
            MSWord.Insert(',' + Cells[i,j]);
            end;
         end;
      //将选定的数据区转换成二维表格
      MSWord.EditSelectAll;
      MSWord.TextToTable(ConvertFrom :=2 , NumColumns := StringGrid1.ColCount );
      //设置表格内线、上线和下线
      MSWord.BorderInSide;
      MSWord.BorderTop;
      MSWord.BorderBottom;
      MSWord.AppShow;
    end;别忘了uses Word97, Comobj, OleServer;
      

  2.   

    好注意,请问STRINGGRID中如何实现字段的显示排列与用SQL所赋的值对应呢?谢谢
      

  3.   

    如果要显示查询结果为什么不用dbgrid呢?
    stringgrid和sql的结果集都是二维的,用代码控制stringgrid显示sql结果也是容易的。
      

  4.   

    为什么word中的二维表格第一列是空的
      

  5.   

    上面的代码有问题,用这个:
    var
      MSWord: Variant;
      i,j,k: integer;
    begin
      MSWord := CreateOleObject('Word.BASIC');
      MSWord.FileNew('Normal');
      with StringGrid1 do   //给StringGrid1填数字
        for I := 0 to RowCount - 1 do
          for J:= 0 to ColCount- 1  do
            begin
              K := K + 1;
              Cells[j,i] := IntToStr(K);
            end;
      with StringGrid1 do //将StringGrid1的内容导出
        for I := 0 to RowCount - 1 do
          begin
            for J:= 0 to ColCount - 1 do
            begin
            if J>0 then
            MSWord.Insert(','+Cells[j,i])
            else
            MSWord.Insert(Cells[j,i])
            end;
            if I<RowCount-1 then
            MSWord.InsertBreak;
         end;
      //将选定的数据区转换成二维表格
      MSWord.EditSelectAll;
      MSWord.TextToTable(ConvertFrom :=2 , NumColumns := StringGrid1.ColCount );
      //设置表格内线、上线和下线
      MSWord.BorderInSide;
      MSWord.BorderTop;
      MSWord.BorderBottom;
      MSWord.AppShow;
    end;
      

  6.   

    看看Word 的VBA帮助,你就会作更多的效果!
      

  7.   

    uses
        comobj;procedure inserttable(AWordApp:olevariant;agrid:Tstringgrid);
    var
      AWordDocument,mytable,Insertpoint,ARange:olevariant;
      i,j:byte;
    begin
      if AWordApp.documents.count>0 then
        AWordDocument:=awordapp.activedocument
      else
        AwordDocument:=awordapp.documents.add;  Insertpoint:=Awordapp.selection.end;  mytable:=AWordDocument.Tables.Add(AWordDocument.range(insertpoint,insertpoint),
               Agrid.rowcount,Agrid.colcount);       //新表格
      mytable.rows.item(1).height:=30;
      mytable.columns.item(1).width:=50;
      mytable.rows.item(1).shading.BackgroundPatternColorIndex := wdgray25;
      mytable.columns.item(1).shading.BackgroundPatternColorIndex := wdgray25;  for i:=1 to Agrid.rowcount do
      for j:=1 to Agrid.colcount do
      begin
          mytable.cell(i,j).range.text:=Agrid.cells[j-1,i-1];
          mytable.cell(i,j).range.font.size:=12;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
        app:olevariant;
    begin
        app:=createoleobject('word.application');
        app.visible:=true;
        inserttable(app,stringgrid1);
    end;