• Martes 30 de Abril de 2024, 02:38

Autor Tema:  Datos  (Leído 5859 veces)

alexis17

  • Miembro MUY activo
  • ***
  • Mensajes: 378
    • Ver Perfil
    • http://www.codigobasico.net
Datos
« en: Lunes 10 de Marzo de 2008, 20:45 »
0
buenas tardes que tal , queria saber si alguien sabe o tiene algun ejemplo de como

importar un documento ya sea en txt o exel y poder cargar esa informacion en una pantalla
ejemplo el documento tiene los campos

nombre
apelido
edad

y cuando coloque importar se me llene la pantalla con dicha informacion

utilizo power builder 6.5
Cada dia aprendo algo nuevo

F_Tanori

  • Moderador
  • ******
  • Mensajes: 1919
  • Nacionalidad: mx
    • Ver Perfil
Re: Datos
« Respuesta #1 en: Martes 11 de Marzo de 2008, 05:58 »
0
el DataWindow trae un metodo para importar archivos.... no estoy seguro si en esa version, tambien puedes usar FILEOPEN

En la ayuda de Powerbuilder debe decirte como... en esta maquina solo tengo PB10

Tal vez te sirva...
Citar

Description

Opens the specified file for reading or writing and assigns it a unique integer file number. You use this integer to identify the file when you read, write, or close the file. The optional arguments filemode, fileaccess, filelock, and  writemode determine the mode in which the file is opened.
Syntax

FileOpen ( filename {, filemode {, fileaccess {, filelock {, writemode
     { encoding }}}}} )

Argument   Description
filename   A string whose value is the name of the file you want to open. If  filename is not on the current directory's relative search path, you must enter the fully qualified name.
filemode (optional)   A value of the FileMode enumerated type that specifies how the end of a file read  or file write is determined. Values are:·   LineMode! — (Default) Read or write the file a line at a time·   StreamMode! — Read blocks of binary data·   TextMode! — Read text blocksFor more information, see Usage below.
fileaccess
 (optional)   A value of the FileAccess enumerated type that specifies whether the file is opened for reading or writing. Values are:·   Read! — (Default) Read-only access·   Write! — Write-only accessIf PowerBuilder does not find the file, a new file is created if the fileaccess argument is set to Write!
filelock (optional)   A value of the FileLock enumerated type specifying whether others have access to the opened file. Values are:·   LockReadWrite! — (Default) Only the user who opened the file has access·   LockRead! — Only the user who opened the file can read it, but everyone has write access·   LockWrite! — Only the user who opened the file can write to it, but everyone has read access·   Shared! — All users have read and write access.
writemode (optional)   A value of the WriteMode enumerated datatype. When  fileaccess is Write!, specifies whether existing data in the file is overwritten. Values are:·   Append! — (Default) Write data to the end of the file·   Replace! — Replace all existing data in the fileWritemode is ignored if the fileaccess argument is Read!
encoding  Character encoding of the file you want to create. Specify this argument when you create a new text file using text or line mode. If you do not specify an encoding, the file is created with ANSI encoding. Values are:·   EncodingANSI! (default)·   EncodingUTF8!·   EncodingUTF16LE!·   EncodingUTF16BE!
Return value

Integer. Returns the file number assigned to filename if it succeeds and -1 if an error occurs. If any argument's value is null, FileOpen returns null.

Usage

The mode in which you open a file determines the behavior of the functions used to read and write to a file. There are two functions that read data from a file: FileRead and FileReadEx, and two functions that write data to a file: FileWrite and FileWriteEx. FileRead and FileWrite have limitations on the amount of data that can be read or written and are maintained for backward compatibility. They do not support text mode. For more information, see FileRead and FileWrite.

The support for reading from and writing to blobs and strings for the FileReadEx and FileWriteEx functions depends on the mode. The following table shows which datatypes are supported in each mode.

Mode   Blob   String
Line   Not supported   Supported
Stream   Supported   Not supported
Text   Supported   Supported
When a file has been opened in line mode, each call to the FileReadEx function reads until it encounters a carriage return (CR), linefeed (LF), or end-of-file mark (EOF). Each call to FileWriteEx adds a CR and LF at the end of each string it writes.
When a file has been opened in stream mode or text mode, FileReadEx reads the whole file until it encounters an EOF or until it reaches a length specified in an optional parameter. FileWriteEx writes the full contents of the string or blob or until it reaches a length specified in an optional parameter.

The optional length parameter applies only to blob data. If the length parameter is provided when the datatype of the second parameter is string, the code will not compile.
In all modes, PowerBuilder can read ANSI, UTF-16, and UTF-8 files.
The behavior in stream and text modes is very similar. However, stream mode is intended for use with binary files, and text mode is intended for use with text files. When you open an existing file in stream mode, the file's internal pointer, which indicates the next position from which data will be read, is set to the first byte in the file.

A byte-order mark (BOM) is a character code at the beginning of a data stream that indicates the encoding used in a Unicode file. For UTF-8, the BOM uses three bytes and is EF BB BF. For UTF-16, the BOM uses two bytes and is FF FE for little endian and FE FF for big endian.
When you open an existing file in text mode, the file's internal pointer is set based on the encoding of the file:

·   If the encoding is ANSI, the pointer is set to the first byte
·   If the encoding is UTF-16LE or UTF-16BE, the pointer is set to the third byte, immediately after the BOM
·   If the encoding is UTF-8, the pointer is set to the fourth byte, immediately after the BOM

If you specify the optional encoding argument and the existing file does not have the same encoding, FileOpen returns -1.
File not found      If PowerBuilder does not find the file, it creates a new file, giving it the specified name, if the fileaccess argument is set to Write!. If the argument is not set to Write!, FileOpen returns -1.

If the optional encoding argument is not specified and the file does not exist, the file is created with ANSI encoding.
When you create a new text file using FileOpen, use line mode or text mode. If you specify the encoding parameter, the BOM is written to the file based on the specified encoding.
When you create a new binary file using stream mode, the encoding parameter, if provided, is ignored.


Citar
This example uses the default arguments and opens the file EMPLOYEE.DAT for reading. The default settings are LineMode!, Read!, LockReadWrite!, and EncodingANSI!. FileReadEx reads the file line by line and no other user is able to access the file until it is closed:

integer li_FileNum

li_FileNum = FileOpen("EMPLOYEE.DAT")

This example opens the file EMPLOYEE.DAT in the DEPT directory in stream mode (StreamMode!) for write only access (Write!). Existing data is overwritten (Replace!). No other users can write to the file (LockWrite!):

integer li_FileNum

li_FileNum = FileOpen("C:\DEPT\EMPLOYEE.DAT", &

        StreamMode!, Write!, LockWrite!, Replace!)

This example creates a new file that uses UTF8 encoding. The file is called new.txt and is in the D:\temp directory. It is opened in text mode with write-only access, and no other user can read or write to the file:

integer li_ret

string ls_file

ls_file = "D:\temp\new.txt"

 li_ret = FileOpen(ls_file, TextMode!, Write!, &

    LockReadWrite!, Replace!, EncodingUTF8!)


Saludos
" ExIsTo y A vEcEs PiEnSo "

NOTA:
===========================================================================================================================
Este foro es para ayudar, aprender, compartir... usenlo para eso,
NO SE RESUELVEN DUDAS POR MENSAJE PRIVADO Y MENOS POR CORREO
===========================================================================================================================

alexis17

  • Miembro MUY activo
  • ***
  • Mensajes: 378
    • Ver Perfil
    • http://www.codigobasico.net
Re: Datos
« Respuesta #2 en: Lunes 7 de Abril de 2008, 02:06 »
0
Buenos dias que tal,

estube intentado importar un archivo de exel a un data windows pero aun no logro hacerlo

intente con esto

Integer li_valor
string txtname, named
string defext = "XLS"
string Filter = "Archivo Excel (*.xls),*.xls"
integer fh, ret
blob asignar


li_valor = GetFileOpenName("Abrir", txtname, named, defext, Filter)

IF ret = 1 THEN

   fh = FileOpen(txtname, StreamMode!)

   
   IF fh <> -1 THEN

       FileRead(fh, asignar)

       FileClose(fh)
      
       dw_1 = asignar

    END IF

END IF

el exel tiene una columna que se llama nombre y otra apellido

les coloque dos nombes y apellidos para provar

el problema es que no se como asignarle al datawindows el valor que recojo cuendo abro el fileopen  ya que lo intente hacer como el de la foto pero me dice que dw intento colocarle un valor entero


intente con esto tambien
IF li_valor = 1 THEN
dw_exp(txtname, HTMLTable! , True)   


no veo que tiene una propiedad open
solo veo el saveopen
Cada dia aprendo algo nuevo

alexis17

  • Miembro MUY activo
  • ***
  • Mensajes: 378
    • Ver Perfil
    • http://www.codigobasico.net
Re: Datos
« Respuesta #3 en: Viernes 11 de Abril de 2008, 06:47 »
0
buenas noches que tal estaba intentando importar utilizando



 li_result = dw_exel.ImportFile(ls_path_name)


pero cuando es exel me manda en la variable li_result -8

asi que no carga el datawindows


encambio con ese mismo codigo si me importa los archivos txt
Cada dia aprendo algo nuevo