社区
Delphi
帖子详情
如何将stringgrid的内容弄到word里面去
newair
2003-05-29 08:58:17
如何将stringgrid的内容弄到word里面去
...全文
50
16
打赏
收藏
如何将stringgrid的内容弄到word里面去
如何将stringgrid的内容弄到word里面去
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
16 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
fhuibo
2003-08-31
打赏
举报
回复
study
pressman
2003-08-30
打赏
举报
回复
up
cxz7531
2003-08-30
打赏
举报
回复
上面的程序有点小问题,应该把V.Insert(str + #13#10);下移一行
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, OleServer, Word97, ComObj;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
V: OleVariant;
str: string;
i, j: Integer;
begin
// 打开OLE服务器
V := CreateOleObject('Word.Basic.9');
// 调用OLE服务器包含的方法
V.FileNew('Normal');
for I := 0 to StringGrid1.RowCount - 1 do
begin
str := '';
for J := 0 to StringGrid1.ColCount - 1 do
begin
str := str + StringGrid1.Cells[j, I] + ' ';
end;
V.Insert(str + #13#10);
end;
// 将Word文件保存,文件名是C:\test.doc
V.FileSaveAs('C:\test2.doc', , , );
BitBtn1.Caption := '保存完毕!!';
end;
end.
cxz7531
2003-08-30
打赏
举报
回复
这是个完整的把TStringGrid的数据导入word的程序,测试正确
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, OleServer, Word97,ComObj;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var
V: OleVariant;
str: string;
i, j: Integer;
begin
// 打开OLE服务器
V := CreateOleObject('Word.Basic.9');
// 调用OLE服务器包含的方法
V.FileNew('Normal');
for I := 0 to StringGrid1.RowCount - 1 do
begin
str := '';
for J := 0 to StringGrid1.ColCount - 1 do
begin
str := str + StringGrid1.Cells[j, I] + ' ';
V.Insert(str + #13#10);
end;
end;
// 将Word文件保存,文件名是C:\test.doc
V.FileSaveAs('C:\test.doc', , , );
BitBtn1.Caption := '保存完毕!!';
end;
end.
xjlqlqlq
2003-08-29
打赏
举报
回复
用粘贴板操作。。。
bxh2dai
2003-08-28
打赏
举报
回复
: Kingron(单身走我路……) 你说的这个网站怎么打不开啊
newair
2003-08-14
打赏
举报
回复
............................
things
2003-06-01
打赏
举报
回复
gz
fansnaf
2003-05-30
打赏
举报
回复
循环导入即可。
fhuibo
2003-05-30
打赏
举报
回复
study
DelphiBoy2003
2003-05-30
打赏
举报
回复
blueshrimp(下着沙-软件民工) 怎么连ADOConnection都出来了
Kingron
2003-05-29
打赏
举报
回复
http://kingron.delphibbs.com 上面有一个支持Grid的导出Word的控件
blueshrimp
2003-05-29
打赏
举报
回复
unit UnitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls, Buttons, Word2000,
OleServer;
type
TForm_Main = class(TForm)
ADOCon_Sample: TADOConnection;
ADOD_Sample: TADODataSet;
DataS_Sample: TDataSource;
DBG_Sample: TDBGrid;
BitBtn1: TBitBtn;
Label1: TLabel;
WordApp: TWordApplication;
WordDoc: TWordDocument;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form_Main: TForm_Main;
implementation
{$R *.dfm}
procedure TForm_Main.FormCreate(Sender: TObject);
begin
//指向数据库
ADOCon_Sample.Connected := False;
ADOCon_Sample.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + ExtractFileDir(Application.Exename) + '\' + 'Sample.mdb;Persist Security Info=False';
ADOCon_Sample.Connected := True;
ADOD_Sample.Active := True;
end;
procedure TForm_Main.BitBtn1Click(Sender: TObject);
var
FindText, ReplaceWith : array[0..14] of OleVariant;
StartPos, FileName : OleVariant;
ReplaceCount : integer;
begin
if DBG_Sample.Fields[0] = nil then exit;
//连接
WordApp.Disconnect;
WordApp.Connect;
WordApp.Visible := True;
Filename := ExtractFileDir(Application.Exename) + '\' + 'Sample.doc';
WordApp.Documents.Open(Filename,EmptyParam,EmptyParam,EmptyParam, EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
WordDoc.Disconnect;
WordDoc.ConnectTo(WordApp.ActiveDocument);
WordDoc.Activate;
//编号
FindText[0] := 'bianhao';
ReplaceWith[0] := DBG_Sample.Fields[0].AsString;
//采样日期
FindText[1] := 'caiyangriqi';
ReplaceWith[1] := DBG_Sample.Fields[1].AsString;
//送样日期
FindText[2] := 'songyangriqi';
ReplaceWith[2] := DBG_Sample.Fields[2].AsString;
//样品来源
FindText[3] := 'yangpinlaiyuan';
ReplaceWith[3] := DBG_Sample.Fields[3].AsString;
//样品名称
FindText[4] := 'yangpinmingcheng';
ReplaceWith[4] := DBG_Sample.Fields[4].AsString;
//商标
FindText[5] := 'shangbiao';
ReplaceWith[5] := DBG_Sample.Fields[5].AsString;
//样品数量
FindText[6] := 'yangpinshuliang';
ReplaceWith[6] := DBG_Sample.Fields[6].AsString;
//样品批号
FindText[7] := 'yangpinpihao';
ReplaceWith[7] := DBG_Sample.Fields[7].AsString;
//包装
FindText[8] := 'baozhuang';
ReplaceWith[8] := DBG_Sample.Fields[8].AsString;
//样品阶段
FindText[9] := 'yangpinjieduan';
ReplaceWith[9] := DBG_Sample.Fields[9].AsString;
//采样人
FindText[10] := 'caiyangren';
ReplaceWith[10] := DBG_Sample.Fields[10].AsString;
//记录人
FindText[11] := 'jiluren';
ReplaceWith[11] := DBG_Sample.Fields[11].AsString;
//状态
FindText[12] := 'zhuangtai';
ReplaceWith[12] := DBG_Sample.Fields[12].AsString;
//检验项目
FindText[13] := 'jianyanxiangmu';
ReplaceWith[13] := DBG_Sample.Fields[13].AsString;
//合同编号
FindText[14] := 'hetongbianhao';
ReplaceWith[14] := DBG_Sample.Fields[14].AsString;
//替换开始处
StartPos := 0;
for ReplaceCount := 0 to 14 do
begin
WordDoc.range(StartPos).find.execute(FindText[ReplaceCount], EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, ReplaceWith[ReplaceCount], EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
end;
//WordDoc.PrintOut;
end;
end.
newair
2003-05-29
打赏
举报
回复
我要用word打印stringgrid啊
newair
2003-05-29
打赏
举报
回复
........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
newair
2003-05-29
打赏
举报
回复
..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Delphi将
String
grid
指定行添加到Memo控件中.rar
Delphi将
String
grid
指定行添加到Memo控件中,选中
String
Grid
中的行,点击右下角的“添加”按钮,即可将选中的
String
Grid
行数据添加到下边的Memo控件中显示。部分源代码如下: procedure TForm1.FormCreate(Sender:...
HookSG源码---Hook其他程序中的
String
Grid
的
内容
Hook其他程序中的
String
Grid
的
内容
String
Grid
导出到EXcel
使用C++ builder6,
String
Grid
导出到EXcel,导出新的excel文件或者模板。两个程序的代码在文档中
string
grid
多选拖拽换行
使用
string
grid
实现行多选, 然后通过拖拽移动选择行位置 按住ctrl可以多选不连续的行
Delphi中
String
Grid
动态绑定下拉列表
Delphi中
String
Grid
动态绑定下拉列表
Delphi
5,386
社区成员
262,729
社区内容
发帖
与我相关
我的任务
Delphi
Delphi 开发及应用
复制链接
扫一扫
分享
社区描述
Delphi 开发及应用
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章