谁有导出的例子阿 给共享一下哟
解决方案 »
- 端口被封闭了,用什么方法可以访问吗?
- 已经快没分了,还是得问:还是处理数据库删除出错的问题!请看里面的源码!
- 太奇怪了.请问我如何在程序里发送email,(553 You are not authorized to send mail as<MAIL FROM:<[email protected]>>,authentication is re
- AdoQuery不支持过滤时设定为不区分大小写吗?
- 请教高手 关于分布开发的更新问题???急啊 !!求救?
- 怎么把一个文件拷贝到另一个目录?
- 查询语句问题
- 请问如何断开拨号上网时所建立的网络连接?
- 关于数据库的几个问题??
- Delphi7 导出文件Excel版本过低,不能兼容其他软件。。。。。。
- 问两个sql server考试题目(明天要交卷了,还做不出来,急急急)
- intraweb
begin
dxdbgrid1.SaveToHTML(ExtractFilePath(Application.ExeName)+'a.html',false);
ShowMessage('數據導成html成功');
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ShellAPI, StdCtrls, DB, DBTables, Grids, DBGrids;type
TForm1 = class(TForm)
Button1: TButton;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function ColorToHtml(mColor: TColor): string;
function StrToHtml(mStr: string; mFont: TFont = nil): string;
function DBGridToHtmlTable(mDBGrid: TDBGrid; mStrings: TStrings;
mCaption: TCaption = ''): Boolean;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.ColorToHtml(mColor: TColor): string;
begin
mColor := ColorToRGB(mColor);
Result := Format('#%.2x%.2x%.2x',
[GetRValue(mColor), GetGValue(mColor), GetBValue(mColor)]);
end; { ColorToHtml }function TForm1.StrToHtml(mStr: string; mFont: TFont = nil): string;
var
vLeft, vRight: string;
begin
Result := mStr;
Result := StringReplace(Result, '&', '&', [rfReplaceAll]);
Result := StringReplace(Result, '<', '<', [rfReplaceAll]);
Result := StringReplace(Result, '>', '>', [rfReplaceAll]);
if not Assigned(mFont) then Exit;
vLeft := Format('<FONT FACE="%s" COLOR="%s">',
[mFont.Name, ColorToHtml(mFont.Color)]);
vRight := '</FONT>';
if fsBold in mFont.Style then begin
vLeft := vLeft + '<B>';
vRight := '</B>' + vRight;
end;
if fsItalic in mFont.Style then begin
vLeft := vLeft + '<I>';
vRight := '</I>' + vRight;
end;
if fsUnderline in mFont.Style then begin
vLeft := vLeft + '<U>';
vRight := '</U>' + vRight;
end;
if fsStrikeOut in mFont.Style then begin
vLeft := vLeft + '<S>';
vRight := '</S>' + vRight;
end;
Result := vLeft + Result + vRight;
end; { StrToHtml }function TForm1.DBGridToHtmlTable(mDBGrid: TDBGrid; mStrings: TStrings;
mCaption: TCaption = ''): Boolean;
const
cAlignText: array[TAlignment] of string = ('LEFT', 'RIGHT', 'CENTER');
var
vColFormat: string;
vColText: string;
vAllWidth: Integer;
vWidths: array of Integer;
vBook: string;
I, J: Integer;
begin
Result := False;
if not Assigned(mStrings) then Exit;
if not Assigned(mDBGrid) then Exit;
if not Assigned(mDBGrid.DataSource) then Exit;
if not Assigned(mDBGrid.DataSource.DataSet) then Exit;
if not mDBGrid.DataSource.DataSet.Active then Exit;
vBook := mDBGrid.DataSource.DataSet.Book;
mDBGrid.DataSource.DataSet.DisableControls;
try
J := 0;
vAllWidth := 0;
for I := 0 to mDBGrid.Columns.Count - 1 do
if mDBGrid.Columns[I].Visible then begin
Inc(J);
SetLength(vWidths, J);
vWidths[J - 1] := mDBGrid.Columns[I].Width;
Inc(vAllWidth, mDBGrid.Columns[I].Width);
end;
if J <= 0 then Exit;
mStrings.Clear;
mStrings.Add(Format('<TABLE BGCOLOR="%s" BORDER=1 WIDTH="100%%">',
[ColorToHtml(mDBGrid.Color)]));
if mCaption <> '' then
mStrings.Add(Format('<CAPTION>%s</CAPTION>', [StrToHtml(mCaption)]));
vColFormat := '';
vColText := '';
vColFormat := vColFormat + '<TR>'#13#10;
vColText := vColText + '<TR>'#13#10;
J := 0;
for I := 0 to mDBGrid.Columns.Count - 1 do
if mDBGrid.Columns[I].Visible then begin
vColFormat := vColFormat + Format(
' <TD BGCOLOR="%s" ALIGN=%s WIDTH="%d%%">DisplayText%d</TD>'#13#10,
[ColorToHtml(mDBGrid.Columns[I].Color),
cAlignText[mDBGrid.Columns[I].Alignment],
Round(vWidths[J] / vAllWidth * 100), J]);
vColText := vColText + Format(
' <TD BGCOLOR="%s" ALIGN=%s WIDTH="%d%%">%s</TD>'#13#10,
[ColorToHtml(mDBGrid.Columns[I].Title.Color),
cAlignText[mDBGrid.Columns[I].Alignment],
Round(vWidths[J] / vAllWidth * 100),
StrToHtml(mDBGrid.Columns[I].Title.Caption,
mDBGrid.Columns[I].Title.Font)]);
Inc(J);
end;
vColFormat := vColFormat + '</TR>'#13#10;
vColText := vColText + '</TR>'#13#10;
mStrings.Text := mStrings.Text + vColText;
mDBGrid.DataSource.DataSet.First;
while not mDBGrid.DataSource.DataSet.Eof do begin
J := 0;
vColText := vColFormat;
for I := 0 to mDBGrid.Columns.Count - 1 do
if mDBGrid.Columns[I].Visible then begin
vColText := StringReplace(vColText, Format('>DisplayText%d<', [J]),
Format('>%s<', [StrToHtml(mDBGrid.Columns[I].Field.DisplayText,
mDBGrid.Columns[I].Font)]),
[rfReplaceAll]);
Inc(J);
end;
mStrings.Text := mStrings.Text + vColText;
mDBGrid.DataSource.DataSet.Next;
end;
mStrings.Add('</TABLE>');
finally
mDBGrid.DataSource.DataSet.Book := vBook;
mDBGrid.DataSource.DataSet.EnableControls;
vWidths := nil;
end;
Result := True;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
DBGridToHtmlTable(DBGrid1, Memo1.Lines, Caption);
Memo1.Lines.SaveToFile('c:\temp.htm');
ShellExecute(Handle, nil, 'c:\temp.htm', nil, nil, SW_SHOW);
end;end.
EXEC master..xp_cmdshell 'bcp 库名.dbo.表名 out e:\temp.html -c -q -U"" -P""'