edgar_prospero
12-07-2012, 20:18:37
que hay tengo un problemilla, haber quien mepuede echar la mano estoy exportando una informacion a excel pero no se como hacerle para que me sume una columna ya que no siempre es el mismo rango varia dependiendo la consulta acontinuacion pongo mi codigo para ver donde puedo agregar para que me sume una columna
procedure TForm5.BitBtn6Click(Sender: TObject);
var Excel : Variant;
var Libro : Variant;
var i:integer;
var j: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[2,1]:= ' Inventario en proceso del departamento: '+dep2.Text + ' A ' +dep3.Text;
Libro.Cells.Item[2,1].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:=2;
query.SQL.Clear;
query.SQL.Add('SELECT * FROM arm0062 WHERE departamento>=:inidep and departamento<=:findep and tipo_material>=:inimat and tipo_material<=:finmat 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.Open;
while not Query.EOF do
begin
Libro.Cells [1,1] := 'CLASIC AND BASIC SA DE CV';
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;
end;
procedure TForm5.BitBtn6Click(Sender: TObject);
var Excel : Variant;
var Libro : Variant;
var i:integer;
var j: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[2,1]:= ' Inventario en proceso del departamento: '+dep2.Text + ' A ' +dep3.Text;
Libro.Cells.Item[2,1].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:=2;
query.SQL.Clear;
query.SQL.Add('SELECT * FROM arm0062 WHERE departamento>=:inidep and departamento<=:findep and tipo_material>=:inimat and tipo_material<=:finmat 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.Open;
while not Query.EOF do
begin
Libro.Cells [1,1] := 'CLASIC AND BASIC SA DE CV';
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;
end;