/*****************************/
/* definicion de variables */
/*****************************/
string ls_dir_formato,ls_dir_formato_new
Integer li_fila,li_ret,j,m
boolean lb_exist,lb_resultado
integer li_startRow, li_endRow, li_startCol, li_endCol
OLEObject excelApp, workbooks, workbook, worksheets,sheet
/***************************************************/
/* movemos ubicacion y nombre del formato */
/***************************************************/
ls_dir_formato = 'C:\temp\formato_original.xls'
ls_dir_formato_new = 'C:\temp\formato_nuevo.xls'
/************************/
/* si existe lo elimina */
/************************/
lb_exist = FileExists(ls_dir_formato_new)
If lb_exist Then FileDelete(ls_dir_formato_new)
/********************************/
/* Abrimos el archivo Excel */
/********************************/
excelApp = CREATE OLEObject
li_ret = excelApp.ConnectToNewObject("Excel.Application")
If li_ret < 0 then
MessageBox("Error Conectandose a Excel !",string(li_ret))
return
End if
workbooks = excelApp.Workbooks
workbook = excelApp.Application.Workbooks.Open(ls_dir_formato)
/*************************/
/* Hace Excel visible */
/************************/
excelApp.Application.Visible = true ///esto es optativo
worksheets = workbook.Worksheets
/******************/
/* primera hoja */
/******************/
sheet = worksheets.Item[1]
/**********************************************/
/* Especificar la celda y asignar el valor */
/**********************************************/
/*************************************/
/* ejemplo de celda combinadas */
/*************************************/
sheet.Range("BW" + String(11) + ":BY" + String(11)).Value = dw_1.object.campo1[1]
sheet.Range("BZ" + String(11) + ":CB" + String(11)).Value = dw_1.object.campo2[1]
sheet.Range("CC" + String(11) + ":CE" + String(11)).Value =dw_1.object.campo3[1]
/********************************************/
/* ejemplo de celda por columna y fila */
/********************************************/
sheet.Cells("21", 2).Value = dw_1.object.campo1[1]
sheet.Cells("21", 37).Value =dw_1.object.campo2[1]
sheet.Cells("23", 2).Value = dw_1.object.campo3[1]
sheet.Cells("23",37).Value = dw_1.object.campo4[1]
/*******************/
/* Segunda hoja */
/*******************/
sheet = worksheets.Item[2]
sheet.Cells("5",3).Value = dw_1.object.titulo1[1]
sheet.Cells("6",3).Value = dw_1.object.campo1[1]
sheet.Cells("7",3).Value = dw_1.object.titulo2[1]
sheet.Cells("8",3).Value = dw_1.object.campo2[1]
sheet.Cells("9",3).Value = dw_1.object.titulo3[1]
sheet.Cells("10",3).Value = dw_1.object.campo3[1]
// ojo puedes usar un For / Next si deseas llenar las celdas de varios registros
dw_1.retrieve()
li_fila = rowcount(dw_1)
m =1
For j = 1 to li_fila
sheet.Cells(string(m),3).Value = dw_1.object.titulo1[j]
sheet.Cells(string(m),3).Value = dw_1.object.campo1[j]
m = m +1
Next
/*****************************************/
/* Guardar y cerrar el archivo Excel */
/*****************************************/
lb_resultado = excelApp.Application.ActiveWorkbook.Saveas(ls_dir_formato_new)
If lb_resultado = FALSE then
messagebox("Atención","Error generando la hoja ")
Else
messagebox("Atención","La hoja excel fue generada")
End if
excelApp.Application.Quit()
excelApp.DisconnectObject()
Destroy excelApp
Comentarios sobre la versión: 12.5 (0)
No hay comentarios