Ver Mensaje Individual
  #1  
Antiguo 05-11-2012
edgar_prospero edgar_prospero is offline
Miembro
NULL
 
Registrado: mar 2012
Posts: 202
Reputación: 13
edgar_prospero Va por buen camino
tamaño de hoja al exportar datos a excel

que hay amigos aqui estoy con un problema, estoy mandando un reporte a excel pero quisiera saber su hay la forma de que la hoja quede configurada a la hora de mandar la informacion, me refiero a que ya que tengo la informacion en excel y si le doy en vista previa ya este a a cierto porcentaje el tamaño de la pagina y no haya necesidad de configurarlo manualmente, no se si me explique un poco acontinuacion pongo el codigo que utilizo para mandar el reporte a excel:

Código Delphi [-]
procedure TForm5.BitBtn6Click(Sender: TObject);
var Excel : Variant;
var Libro : Variant;
var i:integer;
var j:integer;
var _FilaIni: integer;

begin

Excel := CreateOleObject ('Excel.Application');

Excel.Visible := True;


Excel.WorkBooks.Add (-4167);

Excel.WorkBooks[1].WorkSheets[1].Name := 'Reporte';

Libro := Excel.WorkBooks[1].WorkSheets['Reporte'];
excel.worksheets[1].Range['B1','B1'].ColumnWidth :=45;
excel.worksheets[1].Range['C1','C1'].ColumnWidth :=13;
excel.worksheets[1].Range['D1','E1'].ColumnWidth :=15;
excel.worksheets[1].Range['F1','F1'].ColumnWidth :=16;
excel.worksheets[1].Range['G1','H1'].ColumnWidth :=9;
excel.worksheets[1].Range['I1','I1'].ColumnWidth :=14;
Libro.Cells.Item[1,1].Font.Bold:=True;
Libro.Cells.Item[1,1].font.size:=16;

Libro.Cells.Item[1,3]:='Fecha Inventario:  '+ FormatDateTime('dd/mm/yyyy',form5.fecha.Date);
Libro.Cells.Item[1,6]:=' Supervisor:  ' +form5.supervisor.Text;
Libro.Cells.Item[2,1]:= ' Inventario en proceso del departamento: '+form5.dep2.Text + '  A  ' +form5.dep3.Text+ '  del  '  + FormatDateTime('dd/mm/yyyy',form5.inifec.Date)+ '  al  '  + FormatDateTime('dd/mm/yyyy',form5.finfec.Date);
Libro.Cells.Item[2,1].Font.Bold:=True;


Libro.Cells.Item[1,3].Font.Bold:=True;
Libro.Cells.Item[1,6].Font.Bold:=True;
Libro.Cells.Item[3,1].Font.Bold:=True;
Libro.Cells.Item[3,2].Font.Bold:=True;
Libro.Cells.Item[3,3].Font.Bold:=True;
Libro.Cells.Item[3,4].Font.Bold:=True;
Libro.Cells.Item[3,5].Font.Bold:=True;
Libro.Cells.Item[3,6].Font.Bold:=True;
Libro.Cells.Item[3,7].Font.Bold:=True;
Libro.Cells.Item[3,8].Font.Bold:=True;
Libro.Cells.Item[3,9].Font.Bold:=True;



Query.Open;
i:=3;

query.SQL.Clear;
query.SQL.Add('SELECT * FROM arm0062 WHERE departamento>=:inidep and departamento<=:findep and tipo_material>=:inimat and tipo_material<=:finmat and fecha>=:inifec and fecha<=:finfec order by  codigo asc ');
query.ParamByName('inidep').Asstring:=inidep.Text;
query.ParamByName('findep').Asstring:=findep.Text;
query.ParamByName('inimat').Asstring:=inimat.Text;
query.ParamByName('finmat').Asstring:=finmat.Text;
query.ParamByName('inifec').AsDate:=inifec.Date;
query.ParamByName('finfec').AsDate:=finfec.Date;
query.Open;

while not Query.EOF do
begin

Libro.Cells [1,1] := ' CLASIC AND BASIC SA DE CV';
Libro.Cells.Item[1,1].HorizontalAlignment := xlHAlignleft;
Libro.Cells [3,1] := 'codigo';
Libro.Cells [3,2] := 'Nombre';
Libro.Cells [3,3] := 'Departamento';
Libro.Cells [3,4] := 'Tipo de Material';
Libro.Cells [3,5] := 'Cantidad piezas';
Libro.Cells [3,6] := 'Cantidad Material';
Libro.Cells [3,7] := 'Unidad';
Libro.Cells [3,8] := 'Costo';
Libro.Cells [3,9] := 'Total';

   i :=i+1;


Libro.Cells [i,1] := Query.FieldByName ('codigo').AsString;
Libro.Cells [i,2] := Query.FieldByName ('nombre').AsString;
Libro.Cells [i,3] := Query.FieldByName ('departamento').AsString;
Libro.Cells [i,4] := Query.FieldByName ('tipo_material').AsString;
Libro.Cells [i,5] := Query.FieldByName ('cant_piezas').AsString;
Libro.Cells [i,6] := Query.FieldByName ('cant_material').AsString;
Libro.Cells [i,7] := Query.FieldByName ('unidad').AsString;
Libro.Cells [i,8] := Query.FieldByName ('costo').AsString;
Libro.Cells [i,9] := Query.FieldByName ('total').AsString;


Query.Next;

end;

Query.Close;


Libro.Cells.Item[i+1,2].Font.Bold:=True;
Libro.Cells.Item[i+1,9].Font.Bold:=True;

Libro.Cells.Item[i+1,2].HorizontalAlignment := xlHAligncenter;


Libro.Cells [i+1,2] := 'TOTAL';

libro.cells[i+1,9].formula:= format( '=SUM(I4:I%d)', [i] );


DEP2.Text:='PRODUCTO TERMINADO';
DEP3.Text:='ALMACEN TEMPORAL';
inifec.Date:=date;
finfec.Date:=date;
iniFEC.SetFocus;
SUPERVISOR.Clear;
fecha.Date:=date;

end;
__________________
saludos!!!
Responder Con Cita