Delphi6 + Excel 怎么做呢?
如何把一查询到的记录导入Excel呢?
帮帮我好吗?Up也有分的;
有例子吗?没有也可以的,只要能说一说;
如何把一查询到的记录导入Excel呢?
帮帮我好吗?Up也有分的;
有例子吗?没有也可以的,只要能说一说;
解决方案 »
- 我明明阻止了WM_NCPAINT事件,但鼠标移到标题栏,还是会绘制系统按钮
- 请问grid中数据的格式怎么设置?
- 急问:delphi 用ADO控件是如何提交事务
- 帮我做个同步专家这样的软件要多少钱啊! 有诚意的出个价, 制作人要在上海哦
- 哪有计算机水平考试高程教材电子书下?王春森写的那本
- 给点建议哈:)毕业论文:微机实验室的网络化管理!!!!
- 请教:动态创建控件的问题
- 如何将广西文本文件转换为*.db文件?
- 怎样解决分析汇总中遇到的问题??(
- 有人用过TExcelApplication控件吗,一个最简单的例子但老有问题,请帮助看看
- 关于在线程中使用回调函数以及C++静态成员的问题
- 用Installshield Express3.5制作安装版时,请问怎样依据SQL脚本创建数据库?
begin
dm.tbtoexcel.close;
dm.tbtoexcel.sql.clear;
dm.tbtoexcel.sql.add('select * from '+trim(DBLookupComboBox1.Text));
dm.tbtoexcel.open;
dm.tbtoexcel.active:=true;
dbgrid1.DataSource:=dm.dstoexcel;
dbgrid1.DataSource.DataSet:=dm.tbtoexcel;
end;procedure Tfrmtoexcel.BitBtn1Click(Sender: TObject);
var
i,j:integer;
f:TextFile;
sl:TStringList;
begin
with dm.tbtoexcel do
begin
if (not dm.tbtoexcel.Active) then
Exit; if (not SaveDialog1.Execute) then
Exit; AssignFile(f,SaveDialog1.FileName);
try
Rewrite(f);
except
Showmessage('保存文件失敗!');
CloseFile(f);
Exit;
end; Screen.Cursor := crHourGlass;
DisableControls;
sl := TStringList.Create;
sl.Clear;
for i:=0 to FieldCount-1 do
begin
if (Fields[i].Visible) then
sl.Add(Fields[i].DisplayLabel);
end;
writeln(f,sl.CommaText); First;
for j:=0 to RecordCount-1 do
begin
sl.Clear;
for i:=0 to FieldCount-1 do
begin
if (Fields[i].Visible) then
sl.Add(VarToStr(Fields[i].Value));
end;
writeln(f,sl.CommaText);
Next;
end; sl.Free;
CloseFile(f);
EnableControls;
Screen.Cursor := crDefault;
end; // withend;
可是delphi6的我没有找到啊;
5的在6的上边好像不可以用的;
好吧,我将我以前作的一个单元给你,把分给我吧
如果有不明白的地方,上Msn或QQ
你是狐狸,对不对;
呵呵,分不能全给你的,要给这个贴子的,另外给你开个贴子;
我希望直接导入到Excel里;
我希望可以直接导入到Excel里
http://www.csdn.net/expert/topic/996/996596.xml?temp=.2106592
考虑到速度的问题所以用CSV.
i, Row, Column: Integer;
RecordCounts,FieldsCount: Integer;
ExcelSheet,Range: OleVariant;
XLApp : OleVariant;
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:='Xgto';
Row:= 1;
with Query1 do
begin
Close;
UnPrePare;
SQL.Clear;
SQL.Add('Select * from zcbdb');
PrePare;
Open;
First;
Last;
RecordCounts := RecordCounts;
FIeldsCount := FieldCount;
end;
if RecordCounts < 1 then
begin
ShowMessage('aaaastrg');
Exit;
end;
//设置列宽
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]:= '字段名1';
ExcelSheet.Cells.Item[Row,2]:= '字段名1';
ExcelSheet.Cells.Item[Row,3]:= '字段名1';
ExcelSheet.Cells.Item[Row,4]:= '字段名1';
ExcelSheet.Cells.Item[Row,5]:= '字段名1';
ExcelSheet.Cells.Item[Row,6]:= '字段名…';
ExcelSheet.Cells.Item[Row,7]:= '字段名n';
Row:= Row+1;
with Query1 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;
//画单元格边框
end;
end;
PROCEDURE PUB_INSET_EXCEL(DataSet: TDataSet;dbgrid1 :Tdbgrid);
var
i,j: Integer;
Sheet,ColumnRange: Variant;begin
try
wiat_tsForm :=Twiat_tsForm.create(application);
wiat_tsForm.show;
wiat_tsForm.UPDATE;wiat_tsForm.Label7.caption :='正在处理数据,共有'+inttostr(dataset.RecordCount)+'用户数据,请稍后...';
wiat_tsForm.ProgressBar1.Visible :=true;
wiat_tsForm.Label6.Visible :=true;
wiat_tsForm.Animate1.Visible :=false;
wiat_tsForm.Animate2.Visible :=true;
wiat_tsForm.Animate2.BringToFront ;wiat_tsForm.update;
XLApp:= CreateOleObject('Excel.Application');
XLApp.Workbooks.Add(xlWBatWorkSheet);
XLApp.Workbooks[1].WorkSheets[1].Name := 'jlbtj'; Sheet := XLApp.Workbooks[1].WorkSheets['jlbtj'];
ColumnRange := XLApp.Workbooks[1].WorkSheets['jlbtj'].Columns;
dataset.First ;
for i :=1 to dbgrid1.Columns.Count do
Sheet.Cells[1, i] :=dbgrid1.Columns[i-1].Title.Caption ; wiat_tsForm.ProgressBar1.Min :=0;
wiat_tsForm.ProgressBar1.Max :=dataset.RecordCount+1;
wiat_tsForm.ProgressBar1.Step := 1; for i := 2 to dataset.RecordCount+1 do
begin
wiat_tsForm.update;
wiat_tsForm.label6.caption :=inttostr(round(i*100/dataset.RecordCount))+'%';
wiat_tsForm.ProgressBar1.StepIt ;
for j:=1 to dbgrid1.Columns.Count do
begin
Sheet.Cells[i, j] := DBGrid1.Fields[j-1].asstring;
end;
dataset.Next ;
end;
finally
wiat_tsForm.close;wiat_tsForm.Free;
XLApp.Visible := True;
end;
END;