📄 45.txt
字号:
begin
Ds_Master:=Sinput.DataSource.DataSet;
if Ds_Master.IsEmpty or (not Ds_Master.Active) then
exit
else
begin
Ds_Master.DisableControls;
Ds_Master.First;
try
ExcelApplication1:=TExcelApplication.Create(Application);
ExcelWorksheet1:=TExcelWorksheet.Create(Application);
ExcelWorkbook1:=TExcelWorkbook.Create(Application);
ExcelApplication1.Connect;
except
Application.MessageBox('Excel 没有安装','系统提示',
MB_IConERROR + mb_Ok);
Abort;
end;
end;
try
screen.Cursor:=crsqlwait;
ExcelApplication1.Workbooks.Add(emptyparam,0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1]as _worksheet);
for j :=0 to Ds_Master.FieldCount-1 do
begin
ExcelWorksheet1.Cells.Item[1,j+1]:=Ds_Master.Fields[j].DisplayLabel;
ExcelWorksheet1.Cells.Item[1,j+1].font.size:='14';
end;
stringlist1:=Tstringlist.Create;
clipboard.Clear;
with Ds_Master do
begin
open;
first;
end;
while not Ds_Master.Eof do
begin
str1:='';
for i := 0 to Ds_Master.FieldCount-1 do
begin
str1:=str1+Ds_Master.Fields[i].AsString+#9;
Application.ProcessMessages;
end;
stringlist1.Add(str1);
Ds_Master.Next;
end;
//dataset.Free;
//dataset.Refresh;
clipboard.AsText:=stringlist1.Text;
i:=Ds_Master.FieldCount;
j:=Ds_Master.RecordCount+1; //ExcelWorksheet1.Cells.i
//i:=cells.
//ExcelWorksheet1.Paste; //从A1开始粘贴
//srt1:=ExcelWorksheet1.Cells.Item[i,j];
//ExcelWorksheet1.Range['a2','z1000'].PasteSpecial(0,0,0,0);
//ExcelWorksheet1.Range['a2','b4'].PasteSpecial(0,0,0,0);
//i:=ExcelWorksheet1.Cells.Row[2];
//j:=ExcelWorksheet1.Cells.Rows.Column;
//fortest:=string(ExcelWorksheet1.Cells.Name);
//fortest:=ExcelWorksheet1.Cells.Item[j,i];
//fortest:=string(ExcelWorksheet1.Cells.Range[i,j] );
//ExcelWorksheet1.Range['a2'].PasteSpecial(0,0,0,0);
range1:=excelrange(j,i);
ExcelWorksheet1.Range['a2',range1].PasteSpecial(0,0,0,0);
stringlist1.Free;
clipboard.Clear;
ExcelWorksheet1.Columns.AutoFit;
ExcelApplication1.Disconnect;
ExcelApplication1.Visible[0]:=true;
screen.Cursor:=crdefault;
//dataset.Refresh;
Ds_Master.EnableControls;
Application.MessageBox('数据转换成功!','系统',
MB_ICONINFORMATION+Mb_ok);
except
stringlist1.Free;
clipboard.Clear;
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
ExcelApplication1.Free;
ExcelWorkbook1.Free;
ExcelWorksheet1.Free;
screen.Cursor:=crdefault;
Application.MessageBox('错误!','数据转换失败!',
Mb_iconerror+Mb_ok);
Ds_Master.EnableControls;
end;
end;
Top
9 楼eytech(亿源)回复于 2004-06-29 19:03:04 得分 0 QuantumGrid4 这个控件是免费的吗
Top
10 楼jackting()回复于 2004-06-29 19:09:04 得分 0 var Str,Constr:string; i:smallint;
begin
with qrytmp do
begin
close;
sql.Clear;
sql.Add(' select NostypeName from __stk_rpt(nolock) group by NosType,NostypeName order by NosType ');
open;
first;
while not eof do
begin
str:=str+chr(9)+fieldbyname('NostypeName').asstring;
next;
end;
end;
m_1.Lines.Add(str);
Constr:='';
with qrystkrpt do
begin
first;
while not eof do
begin
str:='';
for i:= 0 to qrytmp.RecordCount+2 do
begin
str:=str+fields[i].Value+chr(9);
end;
m_1.Lines.Add(str);
next;
end;
end;
str:='C:\report\test.txt';
m_1.Lines.SaveToFile(str);
WINEXEC(pchar('C:\Program Files\Microsoft Office\Office\Excel.EXE '+ str ),
SW_SHOWMAXIMIZED);
end;
Top
11 楼ltmb118()回复于 2004-06-30 09:09:31 得分 0
可以搜索一下相关的帖子,很多的
Top
12 楼zhxfzhxf1(zhxfzhxf1)回复于 2004-06-30 17:00:43 得分 0 可以搜索一下相关的帖子,很多的
可以直接使用SQL Server的语句来实现,很简单
Top
13 楼zhboy(孔方兄)回复于 2004-06-30 18:07:06 得分 0 用f1book大概就6,7行代码,就可以实现,而且就算机器上没有安装excel同样可以导成excel格式,是真正的excel格式,不是那些用分隔符分隔的文本文件。
Top
14 楼lyq(阿飞)回复于 2004-06-30 19:34:06 得分 0 用dxdbgrid.
dxdbgrid.savetoxls()
Top
15 楼bob008(冻冬)回复于 2004-06-30 19:57:17 得分 0 郁闷, 那么麻烦吗?偶有个例子,自己做的,要就留下油箱,或者过两天到DELPHIBOX上下载,偶最近没时间上传,查询导出的部分有的,你可以看下。
Top
16 楼jijl2001(jijl2001)回复于 2004-06-30 20:04:57 得分 0 我要我的油箱是jijl2001@163.com谢谢
Top
17 楼kuangyulai(不务正业)回复于 2004-07-01 09:44:29 得分 0 to bob008(冻冬)
kuangyulai@163.com
*******************************************************************************************************
ADOQuery 连接Excel 进行sql查询计算字段时问题!楼主macd99(小袁)2003-04-20 17:13:29 在 Delphi / VCL组件开发及应用 提问
ADOQuery 连接Excel 进行sql查询计算字段时报错“参数State 没有默认值“sql语句如下:望高手能给与提示,在下万分感谢
query_ado.Active:=false;
query_ado.SQL.Clear;
query_ado.SQL.Add('select * from ['+TableName+'] where state="ma"');
query_ado.Active:=true;
问题点数:0、回复次数:7
Top
1 楼Intelement(零℃)回复于 2003-04-20 20:04:58 得分 0 试试
'SELECT * FROM [' + TableName + '] WHERE STATE =''MA'''
Top
2 楼NewDelphior(我是菜鸟)回复于 2003-04-20 20:28:11 得分 0 看看这样吧!
'SELECT * FROM [ ' + TABLENAME + '] WHERE STATE = '''MA''''
Top
3 楼Intelement(零℃)回复于 2003-04-20 20:30:35 得分 0 楼上的兄弟
你这个字符串有语法错误。
Top
4 楼macd99(小袁)回复于 2003-04-21 20:17:37 得分 0 state 是 '计算字段'如果是查询其它的"数据字段" 就不会报错!
这是什么原因啊!望高手能给我解答!
Top
5 楼Intelement(零℃)回复于 2003-04-21 20:26:06 得分 0 比较在XLS中有N列
ID1 ID2 ID3
其中 ID3 = ID1 + ID2
你要查询的条件是 ID4 = 100
你可以这样写
'SELECT * FROM [' + TableName + '] WHERE ID1 + ID2 = 100'
*****************************************************************************************************
在delphi中如何将查询结果导出到excel中,楼主chw_csdn_chw(chw)2002-09-06 20:11:38 在 Delphi / VCL组件开发及应用 提问
在delphi中如何将查询结果导出到excel中,
问题点数:30、回复次数:3
Top
1 楼dongxsoft(浮云化雨)回复于 2002-09-06 20:16:19 得分 30unit ExcelU;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Dialogs,
Db, DBTables, Excel2000, OleServer, Variants,ComObj,QForms;
procedure ExcelConnect;
procedure ExcelInsertUserData;
procedure ExcelDisConnect;
procedure GetUserData(var UserCount,FieldsCount: Integer);
var
XLApp: Variant;
implementation
uses Module,Main;
procedure ExcelConnect;
begin
try
XLApp:= CreateOLEObject('Excel.Application');
XLApp.Visible:= True;
except
ShowMessage('请检查有没有正确安装Excel?');
Abort;
end;
XLApp.Application.Caption:= '数据表';
XLApp.workBooks.Add(XlWBatWorkSHeet);
XLApp.workBooks[1].workSHeets[1].Name:='明细列表';
end;
procedure ExcelInsertUserData;
var
i, Row, Column: Integer;
UserCount,FieldsCount: Integer;
// xl: OleVariant;
ExcelSheet,Range: OleVariant;
begin
Row:= 1;
GetUserData(UserCount,FieldsCount);
if UserCount < 1 then
begin
ShowMessage('aaaastrg');
Exit;
end;
// XLApp.Range['A1:'+IntToStr(FieldsCount)+IntToStr(UserCount+1)]; //加一行的标题
//设置列宽
XLApp.Range['A1', 'A1'].ColumnWidth := 10;
XLApp.Range['B1', 'B1'].ColumnWidth := 20;
XLApp.Range['C1', 'C1'].ColumnWidth := 40;
XLApp.Range['D1', 'D1'].ColumnWidth := 10;
XLApp.Range['E1', 'E1'].ColumnWidth := 10;
XLApp.Range['F1', 'F1'].ColumnWidth := 10;
XLApp.Range['G1', 'G1'].ColumnWidth := 10;
//设置列头
ExcelSheet:= XLApp.WorkBooks[1].WorkSheets['明细列表'];
//设置报表横向显示
ExcelSheet.PageSetup.Orientation := xlLandscape;
//设置第一列为字符方式
XLApp.Range['A:A'].NumberFormatLocal:= '@';
ExcelSheet.Cells.Item[Row,1]:= '编码';
ExcelSheet.Cells.Item[Row,2]:= '名称';
ExcelSheet.Cells.Item[Row,3]:= '地址';
ExcelSheet.Cells.Item[Row,4]:= '联系方式';
ExcelSheet.Cells.Item[Row,5]:= '类型';
ExcelSheet.Cells.Item[Row,6]:= '编号';
ExcelSheet.Cells.Item[Row,7]:= '是否合格用户';
Row:= Row+1;
with DataMod.QSamUser do
begin
Close;
Open;
while Not Eof do
begin
Column:= 1;
for i:=1 to FieldsCount do
begin
Excelsheet.Cells.Item[Row,Column]:= Fields[i-1].AsString;
Column:= Column+1;
end;
Row:= Row+1;
Next;
end;
Excelsheet.Columns.AutoFit;
//画单元格边框
{ for i:= 1 to RecordCount + 1 do
begin
Range:= XLAPP.ExcelWork[1].ExcelSheet['明细列表'].Range['A2:G' + inttostr(i)];
Range.Borders.LineStyle := xlContinuous;
Range.WrapText:=True;
Range.VerticalAlignMent:=xlCenter;
Range.HorizontalAlignment:=xlCenter;
end; }
end;
end;
procedure ExcelDisConnect;
begin
if not VarIsEmpty(XlApp) then
Begin //清除内存中的excel,不做保存
XlApp.DisplayAlerts:=false;
XlApp.quit;
end;
end;
procedure GetUserdata(var UserCount,FieldsCount: Integer);
begin
with DataMod.QSamUser do
begin
Close;
SQL.Clear;
SQL.Add('select * from sampleuserlist');
Prepare;
Open;
UserCount:= RecordCount;
FieldsCount:= Fields.Count;
end;
end;
end.
Top
2 楼chw_csdn_chw(chw)回复于 2002-09-06 23:05:26 得分 0 请讲道理
不要just copy and paste.
不过还是谢谢大虾的help
Top
3 楼xpdelphi(九重天)回复于 2002-09-06 23:26:59 得分 0 源代码都给你了,还要怎样讲道理?哈哈!
****************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -