Mané
unread,Mar 4, 2010, 2:01:07 PM3/4/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to dug...@googlegroups.com
procedure mtdExportaGridOpenOffice(var Grid: TDBGrid);
var
vlvDocumento: Variant;
vlvMinhaPlanilha: Variant;
vlvMinhaPagina: Variant;
vlvMinhaCelula: Variant;
vliColuna01, vliColuna02: integer;
vlBKMMarcacao: TBookMark;
vldF: real;
vlvV: Variant;
begin
ConnectOpenoffice;
if IsOpenOfficeConnected then
begin
vlvDocumento := StarDesktop.LoadComponentFromURL('private:factory/scalc', '_blank', 0, dummyArray);
if vlvDocumento.SupportsService('com.sun.star.sheet.SpreadsheetDocument') then
begin
vlvMinhaPlanilha := vlvDocumento.getSheets;
vlvMinhaPagina := vlvMinhaPlanilha.GetByName('Planilha1');
for vliColuna01 := 0 to Grid.Columns.Count - 1 do
begin
vlvMinhaCelula := vlvMinhaPagina.getCellByPosition(vliColuna01, 0);
vlvMinhaCelula.SetString(WideString(Grid.Columns[vliColuna01].Title.Caption));
end;
Grid.DataSource.DataSet.DisableControls;
vlBKMMarcacao := Grid.DataSource.DataSet.GetBookmark;
Grid.DataSource.DataSet.first;
vliColuna02 := 1;
while not Grid.DataSource.DataSet.EOF do
begin
for vliColuna01 := 0 to Grid.Columns.Count - 1 do
begin
vlvMinhaCelula := vlvMinhaPagina.getCellByPosition(vliColuna01, vliColuna02);
try
vlvV := Grid.DataSource.DataSet.Fieldbyname(TColumn(Grid.Columns[vliColuna01]).Fieldname).Value;
vldF := Grid.DataSource.DataSet.Fieldbyname(TColumn(Grid.Columns[vliColuna01]).Fieldname).Value;
if vlvV = vldF then
begin
vlvMinhaCelula.SetValue(vlvV);
end;
except
vlvMinhaCelula.SetString(WideString(Grid.DataSource.DataSet.Fieldbyname(TColumn(Grid.Columns[vliColuna01]).Fieldname).AsString));
end;
end;
Grid.DataSource.DataSet.Next;
inc(vliColuna02);
end;
Grid.DataSource.DataSet.GotoBookmark(vlBKMMarcacao);
Grid.DataSource.DataSet.FreeBookmark(vlBKMMarcacao);
Grid.DataSource.DataSet.EnableControls;
end
else
begin
mtdMensagem('O tipo de arquivo criado esta diferente do que foi solicitado, favor verificar.', mtError, [mbOK], 0);
end;
DisconnectOpenOffice;
end;
end;