Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Servers (https://www.clubdelphi.com/foros/forumdisplay.php?f=9)
-   -   Auto Ajustar Celdas Excel desde Delphi (https://www.clubdelphi.com/foros/showthread.php?t=85971)

nicolasjavier 01-06-2014 19:23:24

Auto Ajustar Celdas Excel desde Delphi
 
Hola, tengo el siguiente código para exportar datos a una planilla Excel, mi pregunta es cómo podría lograr que el ancho de las celdas de Excel quede autoajustado segun el texto que tengan?

Muchas Gracias!


Código Delphi [-]
procedure TFormPerfiles.Button3Click(Sender: TObject);
var
fila:integer;
begin
      fila := 2;
     ExcelApplication2.Connect;
     ExcelApplication2.Visible[0] := True;
     ExcelWorkbook2.ConnectTo(ExcelApplication2.Workbooks.Add(EmptyParam,0));
     ExcelWorksheet2.ConnectTo(ExcelApplication2.Sheets[1] as _WorkSheet);

     //Exportamos datos del DBGrid a excel
     With ExcelWorksheet2.Cells do
       begin
       Item[1,1].Value :='Perfil';
       Item[1,2].Value :='Modulo';
       Item[1,3].Value :='Tarea';

       end;

     QueryRave.First;
     While Not queryrave.Eof do
       begin
         With ExcelWorksheet2.Cells do
          begin
            Item[Fila,1].Value := Queryrave.FieldByName('desc_perfil').AsString;
            Item[Fila,2].Value := Queryrave.FieldByName('desc_modulo').AsString;
            Item[fila,3].value:=  Queryrave.FieldByName('desc_tarea').AsString;
            Inc(Fila);
            Queryrave.Next;
          end;
       end;//While
     ExcelWorksheet2.Disconnect;
     ExcelWorkbook2.Disconnect;
     ExcelApplication2.Disconnect;
end;

nicolasjavier 02-06-2014 15:17:08

Ya lo solucione poniendo dentro del while
Código Delphi [-]
ExcelWorksheet2.Columns.AutoFit;


La franja horaria es GMT +2. Ahora son las 04:28:08.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi