Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.10.27;
Скачать: CL | DM;

Вниз

Зацените   Найти похожие ветки 

 
Добра_желатель   (2003-10-08 14:19) [0]

В коде оставлены ремарки для понятности кому как
Процедура копирования содержимого Грида в буфер, для встаdки в Excel

procedure TTT.AppCopyToBufferExecuteTarget(Grid: TDBGrid);
var
s: string;
st: TStringStream;
DS: TDataSet;
BM: TBookmarkStr;
KB: array[0..KL_NAMELENGTH] of Char;

function GetHeaderStr: string;
var
I: Integer;
begin
Result := "";
for I := 0 to Grid.Columns.Count - 1 do
begin
if I > 0 then st.WriteString(#9);//Result := Result + #9;
//Result := Result + Grid.Columns[I].Title.Caption;
st.WriteString(Grid.Columns[I].Title.Caption);
end;
end;

function GetRecordStr: string;
var
I: Integer;
Field: TField;
begin
//Result := #13#10;
st.WriteString(#13#10);
for I := 0 to Grid.Columns.Count - 1 do
begin
if I > 0 then st.WriteString(#9);//Result := Result + #9;
Field := Grid.Columns[I].Field;
if Field.DataType = ftFloat then
//Result := Result + Field.asString
st.WriteString(Field.asString)
else
//Result := Result + Field.DisplayText;
st.WriteString(Field.DisplayText);
end;
end;

function GetFooterStr: string;
var
I: Integer;
begin
//Result := #13#10;
st.WriteString(#13#10);
for I := 0 to Grid.Columns.Count - 1 do
begin
if I > 0 then st.WriteString(#9);//Result := Result + #9;
//Result := Result + Grid.GetFooterValue(I);
st.WriteString(Grid.GetFooterValue(I));
end;
end;

begin
inherited;
st := TStringStream.Create(s);
Screen.Cursor := crHourGlass;
try
if Grid.Columns.Count = 0 then exit;
DS := Grid.DataSource.DataSet;
if Grid.SelectedRows.Count = 0 then
begin
if Grid.SelectedField.DataType = ftFloat then
//s := s + Grid.SelectedField.asString
st.WriteString(Grid.SelectedField.asString)
else
//s := s + Grid.SelectedField.DisplayText;
st.WriteString(Grid.SelectedField.DisplayText);
end
else
begin
{s := }GetHeaderStr;
BM := DS.Bookmark;
DS.DisableControls;
try
DS.First;
while not DS.Eof do
begin
If Grid.SelectedRows.IndexOf(DS.Bookmark) >= 0 then
{s := s + }GetRecordStr;
DS.Next;
end;
finally
DS.Bookmark := BM;
DS.EnableControls;
end;
if dgFooter in Grid.Options then
{s := s + }GetFooterStr;
end;
GetKeyboardLayoutName(KB);
//LoadKeyboardLayout("00000409", KLF_ACTIVATE); // eng
LoadKeyboardLayout("00000419", KLF_ACTIVATE); // rus
try
Clipboard.AsText := st.DataString;//s;
finally
LoadKeyboardLayout(KB, KLF_ACTIVATE);
end;
finally
Screen.Cursor := crDefault;
st.Free;
end;
end;


 
Nerv ©   (2003-10-08 14:55) [1]

http://delphiworld.narod.ru/base/dbgrid_export_to_excel_or_clipboard.html



Страницы: 1 вся ветка

Текущий архив: 2003.10.27;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.028 c
3-89181
RealShip
2003-10-08 15:16
2003.10.27
Ошибка


1-89231
Lam
2003-10-15 11:08
2003.10.27
Путь


3-89105
Данила
2003-10-08 12:59
2003.10.27
Результаты в DBgrid.


3-89108
AndDem
2003-10-08 11:47
2003.10.27
TADOStoredProc и возвращаемые значения


3-89167
paa
2003-10-07 06:43
2003.10.27
Мастера помогите с вставкой записи в базу