题目如上:
效果为:班级 姓名 分数一年级 刘备 20
张飞 21
赵云 60
二年级 关羽 50
曹操 12
效果为:班级 姓名 分数一年级 刘备 20
张飞 21
赵云 60
二年级 关羽 50
曹操 12
解决方案 »
- 关于ClientDataSet查询的问题(在线等)
- 结构指针地址值转换
- COM组件中使用线程的问题?
- 高难的组件问题呦!
- 散分1
- 都说delphi编译器好,具体怎么体现的,我觉得查错和运行都跟vb差不多
- if rb1.Checked := true then//rb1 is radiobutton提示错误。type of expression must be boolean
- 请问在中文windows环境中写的英文帮助,在英文win98下出错,提示“制作帮助文件的语言不被当前windows版本支持”,请问如何解决
- 大哥们啊!我是要和所有的文件建立关联,不管什么文件的扩展名,双击自动打开我的程序。
- 请问Mdb 数据库支不支持插入记录?谢谢!
- 这个WSAEventSelect的server类怎么用?(请大家帮忙,我会很快结帖)
- 小妹初学,向高手求救...显示窗体 但要隐藏一些它的事件
Self.ExcelApplication1:=TExcelApplication.Create(self);
Self.ExcelApplication1.Connect;
except
messagebox(application.Handle,'无法生成Excel报表,请确定安装了Excel后重试','信息',mb_ok or mb_iconinformation);
exit;
end;
Self.ExcelApplication1.Visible[0]:=false;
self.ExcelApplication1.DisplayAlerts[0]:=False;
Self.ExcelApplication1.Caption:='统计报表';
Self.ExcelApplication1.Workbooks.Add(EmptyParam,0);
//Self.ExcelApplication1.Workbooks.Add(EmptyParam,1);
Self.ExcelWorkbook1.ConnectTo(self.ExcelApplication1.Workbooks[1]);
self.ExcelWorksheet1:=TExcelWorkSheet.Create(self);
self.ExcelWorksheet1.ConnectTo(self.ExcelWorkbook1.Worksheets[1] as _worksheet); self.ExcelWorksheet1.Range['A1','A1'].columnwidth:=length('总计(一共有多少条数据)');
self.ExcelWorksheet1.Range['A1','A1'].WrapText:=true;
self.ExcelWorksheet1.Cells.Item[2,1].Interior.colorindex:=15;
self.ExcelWorksheet1.Cells.Item[2,1].BorderAround(xlcontinuous,xlthin,xlautomatic,clblack);
self.ExcelWorksheet1.Cells.Item[2,1]:='总计(一共有多少条数据)';
self.ExcelWorksheet1.Cells.Item[3,1].BorderAround(xlcontinuous,xlthin,xlautomatic,clblack);
self.ExcelWorksheet1.Cells.Item[3,1]:=inttostr(cou1);
self.ExcelWorksheet1.Cells.Item[2,2].Interior.colorindex:=15;
self.ExcelWorksheet1.Cells.Item[2,2].BorderAround(xlcontinuous,xlthin,xlautomatic,clblack);
self.ExcelWorksheet1.Range['B1','B1'].columnwidth:=length('w2选择a的个数');
self.ExcelWorksheet1.Range['B1','B1'].WrapText:=true;
self.ExcelWorksheet1.Cells.Item[2,2]:='w2选择a的个数';
self.ExcelWorksheet1.Cells.Item[3,2].BorderAround(xlcontinuous,xlthin,xlautomatic,clblack);
self.ExcelWorksheet1.Cells.Item[3,2]:=inttostr(cou2); self.ExcelWorksheet1.Cells.Item[2,3].Interior.colorindex:=15;
self.ExcelWorksheet1.Cells.Item[2,3].BorderAround(xlcontinuous,xlthin,xlautomatic,clblack);
self.ExcelWorksheet1.Range['C1','C1'].columnwidth:=length('W2选择a时w4选择b的个数');
self.ExcelWorksheet1.Range['C1','C1'].WrapText:=true;
self.ExcelWorksheet1.Cells.Item[2,3]:='W2选择a时w4选择b的个数';
self.ExcelWorksheet1.Cells.Item[3,3].BorderAround(xlcontinuous,xlthin,xlautomatic,clblack);
self.ExcelWorksheet1.Cells.Item[3,3]:=inttostr(cou3); self.ExcelWorksheet1.Cells.Item[2,4].Interior.colorindex:=15;
self.ExcelWorksheet1.Cells.Item[2,4].BorderAround(xlcontinuous,xlthin,xlautomatic,clblack);
self.ExcelWorksheet1.Range['D1','D1'].columnwidth:=length('w4占所有W4不等于空的个数的百分比');
self.ExcelWorksheet1.Range['D1','D1'].WrapText:=true;
self.ExcelWorksheet1.Cells.Item[2,4]:='w4占所有W4不等于空的个数的百分比';
self.ExcelWorksheet1.Cells.Item[3,4].BorderAround(xlcontinuous,xlthin,xlautomatic,clblack);
self.ExcelWorksheet1.Cells.Item[3,4]:=r;
self.ExcelWorksheet1.SaveAs('f:\统计报表.xls');
for i:=1 to row do
begin
if i=row then
Exit;
if self.ExcelWorksheet1.Cells.Item[i,1]=self.ExcelWorksheet1.Cells.Item[i+1,1] then
Self.ExcelWorksheet1.Range['1'+inttostr(i),'1'+inttostr(i+1)].MergeCells:=True;
end;
i,row,column:Integer;//数据行列变量
query:TDataSet;
begin
//连接电子表格
try
ExcelApplication1.Connect;
except
MessageDlg('是否正确安装了EXCEL?',mterror,[mbOK],0);
Abort;
end; ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption:='数据导出';
ExcelApplication1.Workbooks.Add(null,0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
excelworksheet1.connectto(excelworkbook1.worksheets[1] as _worksheet);
//设置数据第一行表头
for i:=1 to DBGrid1.FieldCount do
begin
ExcelWorksheet1.Cells.Item[1,i]:=DBGrid1.Fields[i-1].FieldName;
end;
//导出数据
query:=DBGrid1.DataSource.DataSet;
row:=2;//从第二行开始;
with query do
begin
First;
while not Eof do
begin
column:=1;
for i:=1 to FieldCount do
begin
ExcelWorksheet1.Cells.Item[row,column]:=Fields[i-1].Value;
column:=column+1;
end; Next;
row:=row+1;
end;
end; for i:=3 to row do
begin
if i=row then
Exit;
if self.ExcelWorksheet1.Cells.Item[i,2]=self.ExcelWorksheet1.Cells.Item[i+1,2] then
Self.ExcelWorksheet1.Range['1'+inttostr(i),'1'+inttostr(i+1)].MergeCells:=True;
end;
ExcelApplication1.Disconnect; //断开连接
end;
这样会提示出错:请帮我看看
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EVariantInvalidOpError with message 'Invalid variant operation'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------