Exportar a Excel y CdpSelect()

Exportar a Excel y CdpSelect()

Postby miarcod » Tue Jun 07, 2016 6:58 pm

Hola, vuelvo con el tema de la exportación a excel,

Este problema ya lo plantee hace un tiempo pero sigo sin encontrarle una solución ahora estoy intentando solucionarlo pero no se que hacer.

Pongo un ejemplo de codigo que reproduce el problema
Code: Select all  Expand view

#include "Fivewin.ch"


#define xVTop                           -4160
#define xVCenter            -4108
#define xVBottom                        -4107

// Horizontal Aling
#define  xlLeft             -4131
#define  xlCenter               -4108
#define  xlRight                -4152
#define  xlHAlignCenterAcrossSelection      7

#DEFINE FRM_TXT "@"
#DEFINE FRM_NUM "#.##0,00"
#DEFINE FRM_MON "#.##0,00_€;[Rojo]-#.##0,00 _€"
#DEFINE FRM_FEC "dd-mmm-aaa"
#DEFINE FRM_POR "0,00%"
#DEFINE FRM_NONE  

#DEFINE BOLD    .T.
#DEFINE NORMAL  .F.

#DEFINE NFONT   "Arial"
#DEFINE FSIZE   11


REQUEST HB_CODEPAGE_ESWIN
REQUEST HB_CODEPAGE_ESISO


#DEFINE FILE_DBF  "PRUEBA1.DBF"

#DEFINE TXT1    "AÁBCEÉFGHIÍJKMNÑOÓPQRSTUÚÜVWXYZaábcdeéfghiíjklmnñoópqrstuúüvwxyz"
#DEFINE TXT2    "" // "ªº¡!()=¿?"
#DEFINE TXT3    "Limpieza y encintado con mortero acabado rústico, de muro de mamposteria ordinaria, existente, de una cara vista, colocada en seco."
#DEFINE TXT4    "M3 Zapata corrida de cimentación de hormigón armado."

function main()
Local cPage, cFicTmp
Local oExcel, oBook, oSheet, nLin

CrearDBF()
use ( FILE_DBF ) ALIAS "PRUEBA" NEW

SELECT PRUEBA
APPEND BLANK
REPLACE PRUEBA->CAMPO WITH "1 " + TXT1
APPEND BLANK
REPLACE PRUEBA->CAMPO WITH "2 " + TXT2
APPEND BLANK
REPLACE PRUEBA->CAMPO WITH TXT3
APPEND BLANK
REPLACE PRUEBA->CAMPO WITH TXT4

TRY
   oExcel := CreateObject( "excel.application" )
   oBook := oExcel:Workbooks:Add()
   oSheet := oBook:Worksheets( 1 )
CATCH
  MsgInfo("Excel no encontrado")
  RETURN NIL
END

nLin := 0
/*
SetCell(oSheet, ++nLin, 2, "VARIABLES EN MEMORIA PAGINA: " + HB_CDPSELECT(), xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
SetCell(oSheet, ++nLin, 2, TXT1, xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
SetCell(oSheet, ++nLin, 2, TXT2, xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
*/


nlin+=2
SetCell(oSheet, ++nLin, 2, "CAMPOS DE BASE DE DATOS", xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
SELECT PRUEBA
GOTO TOP
DO WHILE !PRUEBA->(EOF())
   SetCell(oSheet, ++nLin, 2, PRUEBA->CAMPO, xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
   SKIP
ENDDO


nlin+=2
SetCell(oSheet, ++nLin, 2, "CAMBIO PAGINA DE CODIGOS", xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)

cPage := HB_CDPSELECT("ESWIN")

/*
SELECT PRUEBA
APPEND BLANK
REPLACE PRUEBA->CAMPO WITH "3 " + TXT1
APPEND BLANK
REPLACE PRUEBA->CAMPO WITH "4 " + TXT2
APPEND BLANK
REPLACE PRUEBA->CAMPO WITH TXT3
APPEND BLANK
REPLACE PRUEBA->CAMPO WITH TXT4
nlin+=2
SetCell(oSheet, ++nLin, 2, "VARIABLES EN MEMORIA", xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
SetCell(oSheet, ++nLin, 2, TXT1, xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
SetCell(oSheet, ++nLin, 2, TXT2, xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
*/

nlin+=2
SetCell(oSheet, ++nLin, 2, "CAMPOS DE BASE DE DATOS", xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
SELECT PRUEBA
GOTO TOP
DO WHILE !PRUEBA->(EOF())
   SetCell(oSheet, ++nLin, 2, PRUEBA->CAMPO, xlLeft, FRM_TXT, NFONT, FSIZE, NORMAL)
   SKIP
ENDDO


oExcel:Visible = .T.

RETURN NIL

//------------------------------------------------------------------------//
STATIC FUNCTION SetCell(oSheet, nLin, nCol, xValue, xHorAlign, xFormat, ;
                                            cFont, nFontSize, lBold)
If xHorAlign != NIL ; oSheet:Cells( nLIn, nCol ):HorizontalAlignment := xHorAlign ; EndIf
If xFormat   != NIL ; oSheet:Cells( nLIn, nCol ):NumberFormat = xFormat           ; EndIf
If nFontSize != NIL ; oSheet:Cells( nLin, nCol ):Font:Size := nFontSize           ; EndIf
If lBold != NIL     ; oSheet:Cells( nLin, nCol ):Font:Bold := lBold               ; EndIf
oSheet:Cells( nLin, nCol):Value := xValue
sysrefresh()
RETURN .T.

//------------------------------------------------------------------------//
STATIC FUNCTION CrearDBF()
Local aDbf , cFile

aDbf := {}
AADD( aDbf, { "CAMPO",  "C", 240, 0 } )
DBCREATE( FILE_DBF, aDbf)
RETURN NIL
 

Los datos están grabados en los fichero con la página de codigos por defecto EN
Si creo la hoja de calculo con la página de codigos con la que están guardados los datos en los ficheros. Los textos no se leen.

Al cambiar la pagina de codigos a ESWIN para crear el EXCEL la mayoría los convierte correctamente pero algunos caracteres no (á, ú, ñ, abreviatura de primera. ..??) no los covierte correctamente.
miarcod
 
Posts: 197
Joined: Tue Oct 11, 2005 2:17 pm

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 81 guests