我想做一个自动报表的东西,就是从一些子表中提出一些数据
然后写到汇总表中,请问如何实现.最好有例子.分不够可再加.
请高手不吝赐教.
然后写到汇总表中,请问如何实现.最好有例子.分不够可再加.
请高手不吝赐教.
解决方案 »
- delphi2009能否使用Expressbar
- fastReport中,假如字段不存在会报错,怎么实现没有该字段也不报错,并显示0。
- FastReport如何实现列扩展
- dbgrideh不能编辑了,不知道为什么?
- serversocket断开问题
- 请问在delphi7中当把窗体最大化时,要把里面的控件自动放大相应的比例,是修改那个属性,有没有这样的属性?
- 商业逻辑,不知大家把它放在哪里处理?
- 如何从字符串中提取单词?
- Delphi7的升级补丁谁能给出一个下载链接?
- 我在delphi5 enterprise上打ado补丁时,输入要serial number 和authorization,请问他们是什么?
- 有办法编写一个既是Exe又是DLL的程序吗?
- 能够实现按下回车键后转换成按下TAB键吗?
ConnectExcelAdoDataSet(FileName:String)
begin
ConnectStr:String;
//TempResult:Boolean;
begin
Result:=False;
ExcelAdoConnection.Connected:=False;
try
ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Mode=ReadWrite;Extended Properties=Excel 8.0;';
ConnectStr:=ConnectStr+'Data Source='+FileName+';';
ConnectStr:=ConnectStr+'Persist Security Info=False';
ExcelAdoConnection.ConnectionString:='';
ExcelAdoConnection.ConnectionString:=ConnectStr;
ExcelAdoConnection.LoginPrompt:=False;
ExcelAdoConnection.Connected:=True;
if ExcelAdoConnection.Connected=True then
begin
Result:=True;
end
else
begin
try
ConnectStr:='Provider=Microsoft.Jet.OLEDB.4.0;Mode=ReadWrite;Extended Properties=Excel 7.0;';
ConnectStr:=ConnectStr+'Data Source='+FileName+';';
ConnectStr:=ConnectStr+'Persist Security Info=False';
ExcelAdoConnection.ConnectionString:='';
ExcelAdoConnection.ConnectionString:=ConnectStr;
ExcelAdoConnection.LoginPrompt:=False;
ExcelAdoConnection.Connected:=True;
if ExcelAdoConnection.Connected=True then
begin
Result:=True;
end;
except
Result:=False;
end;
end;
except
Result:=False;
end;
Result:=Result;
end;
这是连接Excel的函数,if ConnectExcelAdoDataSet(//Excel文件名) then
begin
with ExcelADODataSet do
begin
CommandType:=cmdTable;
CommandText:='[Sheet1$]';
Active:=True;
end;
end
else
begin
MessageBox(Application.Handle,'打开文件失败!','系统提示',MB_ICONINFORMATION or MB_OK);
exit;
end;建立两个Ado对两个Excel表进行操作就行了!
我现在用的是组件,请给个例子,谢谢!
function OpenExcel(ExcelApplication: TExcelApplication):boolean;
begin
Result := True;
try
ExcelApplication.Connect;
ExcelApplication.Visible[1] := True;
if not (ExcelApplication.Workbooks.Count > 0) then
begin
ExcelApplication.Workbooks.add(emptyparam,1);
end;
CellRow := 1;
CellCol := 1;
except
Application.MessageBox('您没有安装Excel,请安装后再使用','提示',mb_ok);
Result := False;
end;
end;
procedure OutputExcel(ExcelApplication: TExcelApplication;DataSet: TQuery;Flag: integer);
var
Sheet1 : OleVariant; // Excel文件中的一页
j : integer; //循环控制表量
FieldNum: integer; //字段个数
begin
Sheet1 := ExcelApplication.Workbooks[1].Sheets[1];
Sheet1.visible := true;
if Flag = 0 then
begin
FieldNum := DataSet.FieldCount -1;
end
else
begin
FieldNum := DataSet.FieldCount -3;
end;
for j := 0 to FieldNum do // 输出标题
begin
Sheet1.Cells[CellRow,CellCol + j] := '''' + DataSet.Fields[j].DisplayLabel;
Sheet1.Cells[cellrow,CellCol + j].Font.Name := '宋体';
Sheet1.Cells[cellrow,CellCol + j].Font.Size := '12';
Sheet1.Cells[cellrow,CellCol + j].Font.Bold := True;
end;
DataSet.First;
while not DataSet.Eof do // 输出内容
begin
Inc(CellRow);
for j := 0 to FieldNum do
begin
Sheet1.Cells[Cellrow,CellCol+j].Font.Name := '宋体';
Sheet1.Cells[cellrow,CellCol+j].Font.Size := '9';
Sheet1.Cells[CellRow,CellCol+j] := '''' + DataSet.Fields[j].AsString;
end;
DataSet.Next;
end;
end;
office
组件联系时,如给TEDIT赋值为EXCEL表中的值时,编译则产生错误,“PROJECT XX。EXE
RAISE EXCEPTION CLASS EINTFCASTERROR WITH MESSAGE ‘INTERFACE NOT SUPPORTED’”
请问为何,应如何解决。谢谢!
好多的人在这里回答的