Ver Mensaje Individual
  #3  
Antiguo 04-06-2008
Betus Betus is offline
Registrado
 
Registrado: may 2008
Posts: 3
Reputación: 0
Betus Va por buen camino
Smile

capo979...No se si esto te sirva, después de buscar bastante (no encontré nada concreto) y sacar deducciones, hice este procedimiento con el que se puede insertar combo boxes en Excel desde Delphi:

procedure InsertaComboEnCelda(x,y:Integer; rangoCeldas,tituloMsjError,msjError:String);
begin
try
Libro.Cells.Item[x,y].Validation.Delete;
Libro.Cells.Item[x,y].Validation.Add(xlValidateList,AlertStyle := xlValidAlertStop,Operator := xlBetween, Formula1:=rangoCeldas);
Libro.Cells.Item[x,y].Validation.IgnoreBlank := True;
Libro.Cells.Item[x,y].Validation.InCellDropdown := True;
Libro.Cells.Item[x,y].Validation.InputTitle := '';
Libro.Cells.Item[x,y].Validation.ErrorTitle := tituloMsjError;
Libro.Cells.Item[x,y].Validation.InputMessage := '';
Libro.Cells.Item[x,y].Validation.ErrorMessage := msjError;
Libro.Cells.Item[x,y].Validation.ShowInput := True;
Libro.Cells.Item[x,y].Validation.ShowError := True;
except
CancelaOperacionExcel('Error: No se puede insertar lista en la celda ['+IntToStr(x)+','+IntToStr(y)+'].');
end;
end;

Para insertar validaciones de longitud en las celdas:

procedure InsertaValidacionLongitudEnCelda(x,y,longMin,longMax:Integer; tituloMsjError,msjError:String);
begin
try
Libro.Cells.Item[x,y].Validation.Delete;
Libro.Cells.Item[x,y].Validation.Add(xlValidateTextLength,AlertStyle := xlValidAlertStop,Operator := xlBetween, Formula1:=longMin, Formula2:=longMax);
Libro.Cells.Item[x,y].Validation.IgnoreBlank := True;
Libro.Cells.Item[x,y].Validation.InCellDropdown := True;
Libro.Cells.Item[x,y].Validation.InputTitle := '';
Libro.Cells.Item[x,y].Validation.ErrorTitle := tituloMsjError;
Libro.Cells.Item[x,y].Validation.InputMessage := '';
Libro.Cells.Item[x,y].Validation.ErrorMessage := msjError;
Libro.Cells.Item[x,y].Validation.ShowInput := True;
Libro.Cells.Item[x,y].Validation.ShowError := True;
except
CancelaOperacionExcel('Error: No se puede insertar validación de longitud en la celda ['+IntToStr(x)+','+IntToStr(y)+'].');
end;
end;

Para insertar validaciones de fecha den las celdas al capturar:

procedure InsertaValidacionFechaEnCelda(x,y:Integer; fechaMin,fechaMax,tituloMsjError,msjError:String);
begin
try
Libro.Cells.Item[x,y].Validation.Delete;
Libro.Cells.Item[x,y].Validation.Add(xlValidateDate,AlertStyle := xlValidAlertStop,Operator := xlBetween, Formula1:=fechaMin, Formula2:=fechaMax);
Libro.Cells.Item[x,y].NumberFormat := 'dd/mm/aaaa;@';
Libro.Cells.Item[x,y].Validation.IgnoreBlank := True;
Libro.Cells.Item[x,y].Validation.InCellDropdown := True;
Libro.Cells.Item[x,y].Validation.InputTitle := '';
Libro.Cells.Item[x,y].Validation.ErrorTitle := tituloMsjError;
Libro.Cells.Item[x,y].Validation.InputMessage := '';
Libro.Cells.Item[x,y].Validation.ErrorMessage := msjError;
Libro.Cells.Item[x,y].Validation.ShowInput := True;
Libro.Cells.Item[x,y].Validation.ShowError := True;
except
CancelaOperacionExcel('Error: No se puede insertar validación de fecha en la celda ['+IntToStr(x)+','+IntToStr(y)+'].');
end;
end;

Como puedes ver, dentro del try, lo único que cambia en cada procedimiento es el Validation.Add (voy a ver como fusiono estos tres procedimientos -y los demás que pueda necesitar- en uno solo).

Ahh, tienes que declarar estas constantes:

xlValidateList = 3;
xlValidateTextLength = 6;
xlValidateDate = 4;
xlValidAlertStop = 1;
xlBetween = 1;

...y rangoCeldas, debes pasarlo al primer procedimiento por ejemplo: '=$E$4:$E$5'...esto le indica al procedimiento que los valores que va a tomar el combo se encuentran ubicados entre las celdas E4:E5, en mi caso, en estas dos celdas tengo los valores: Persona moral y Persona física respectivamente.

Saludos...

P.D. Volviendo a mi requerimiento particular, hay una página en la que encontré algo de cómo hacer combo boxes maestro-detalle...La página es:

http://www.todoexpertos.com/categori...diendo-de-otra

Si alguien logra hacer esto, que no sea ojaldra, que lo comparta!!!
Responder Con Cita