这个小程序是从EXCl里把数据导入数据库,再根据模板打印。但是现在的问题是,程序打的时候点打印有数据,只要导入数据后打印就是空白。大家看一看我的源码哪儿有问题。

  • 主题发起人 linsscel
  • 开始时间
L

linsscel

Unregistered / Unconfirmed
GUEST, unregistred user!
这个小程序是从EXCl里把数据导入数据库,再根据模板打印。但是现在的问题是,程序打的时候点打印有数据,只要导入数据后打印就是空白。大家看一看我的源码哪儿有问题。(50)<br />这个小程序是从EXCl里把数据导入数据库,再根据模板打印。但是现在的问题是,程序打的时候点打印有数据,只要导入数据后打印就是空白。大家看一看我的源码哪儿有问题。implementation{$R *.dfm}procedure TForm1.ToolButton1Click(Sender: TObject);
//EXCl导入数据var excelx,excely,excelz,excelw: string;
ExcelApp,workbook: Variant;
ExcelRowCount,i,j:integer;
begin
adodataset1.Close;
adodataset1.CommandText:='select * from jbbxx';
adodataset1.Open;
if form1.OpenDialog1.Execute then
try excelapp:= CreateOleObject('Excel.Application');
WorkBook := ExcelApp.WorkBooks.Open(form1.opendialog1.FileName);//使用opendialog对话框指定excel档路径 ExcelApp.Visible := false;
ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
j:=2;
for i := 0 to excelrowcount - 1do
begin
excelx := excelapp.Cells[j,1].Value;
excely := excelapp.Cells[j,2].Value;
excelz := excelapp.Cells[j,3].Value;
excelw := excelapp.Cells[j,4].Value;
if ((excelx='') and (excely='')) then
exit //指定excel档的第 i 行 ,第 1,2(看情况而定)行如果为空就退出,这样的设定,最好是你的档案力这两行//对应数据库中不能为空的数据 else
begin
form1.adodataset1.Insert;
form1.adodataset1.FieldByName('chinaname').AsString:= excelx;
//excel档的第一列插入到test表的 name栏位;
form1.adodataset1.FieldByName('englishname').AsString:= excely;
form1.adodataset1.FieldByName('jhh').AsString:= excelz;
//excel档的第二列插入到test表的 address 栏位;
form1.adodataset1.FieldByName('jhr').AsString:=excelw;
form1.adodataset1.Post;
j:=j+1;
end;
end;
finally WorkBook.Close;
ExcelApp.Quit;
ExcelApp := Unassigned;
WorkBook := Unassigned;
adodataset1.Close;
adodataset1.CommandText:='select * from jbbxx';
adodataset1.Open;
//Application.MessageBox('数据已导入完成','提示信息',MB_OK);
end else
Application.MessageBox('数据已导入失败','提示信息',MB_OK);
end;
procedure TForm1.ToolButton4Click(Sender: TObject);
//清除所有数据var LQuery:Tadoquery;
begin
LQuery:=TADOQuery.Create(nil);
try LQuery.Connection:=ADODataSet1.Connection;
lquery.SQL.Add('delete * from jbbxx');
lquery.ExecSQL;
lquery.SQL.Clear;
finally LQuery.Free;
end;
adodataset1.Close;
adodataset1.CommandText:='select * from jbbxx';
adodataset1.Open;
end;
procedure TForm1.ToolButton2Click(Sender: TObject);
//根据模版打印begin
if RadioButton1.Checked=true then
begin
frxreport1.LoadFromFile('pr.fr3');
frxReport1.PrepareReport();
frxreport1.Print();
end else
if radiobutton2.Checked=true then
begin
frxreport1.LoadFromFile('pr1.fr3');
frxReport1.PrepareReport();
frxreport1.Print();
end;
end;
procedure TForm1.ToolButton3Click(Sender: TObject);
begin
if panel2.Visible=true then
panel2.Visible:=false else
panel2.Visible:=true;
end;
 
L

linsscel

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么都没人回答我的问题。那位高手帮忙看一看啊。谢谢
 
Z

znxia

Unregistered / Unconfirmed
GUEST, unregistred user!
代码上看不出来什么问题。导入后,先看看数据库有没有数据。在ToolButton2Click中先预览看看有没有数据。
 
L

linsscel

Unregistered / Unconfirmed
GUEST, unregistred user!
程序首次打开时预览有数据,只要导入新数据后就没数据了。
 
Z

znxia

Unregistered / Unconfirmed
GUEST, unregistred user!
frxreport1每次使用完后都释放,下次使用时再创建。
 
L

linsscel

Unregistered / Unconfirmed
GUEST, unregistred user!
我把原程序发给你帮忙看一下,给个邮箱。我把所有的积分都给你!行不
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
512
import
I
I
回复
0
查看
629
import
I
S
回复
0
查看
816
SUNSTONE的Delphi笔记
S
顶部