Portal    Foro    Buscar    FAQ    Registrarse    Conectarse


Publicar nuevo tema  Responder al tema 
Página 1 de 1
 
 
Código: TableView O GridView A ODS
Autor Mensaje
Responder citando   Descargar mensaje  
Mensaje Código: TableView O GridView A ODS 
 
opendoc_gambas

He creado un modulo (que la neta no sé si sea una clase, un componente, una simple función, un objeto..... de POP no sé nada, jo!) que crea un documento ODS (una hoja de cálculo de Open Document) a partir de los datos de una TableView o un GridView. Dicho modulo es muy sencillo y sólo se limita a pasar la info, no conserva los formatos de fuente.

Para el que le interese, aquí les dejo mi código:

' gambas module file

PRIVATE pathOpendoc AS String = "/tmp/opendocgambas/"
PUBLIC FUNCTION saveODS(controlx AS Object, pathODS AS String)
  
  DIM writer AS XmlWriter
  DIM filex AS File
  DIM iCount AS Integer
  DIM jCount AS Integer
  
  IF Object.Type(controlx) = "GridView" OR IF Object.Type(controlx) = "TableView" THEN
  TRY MKDIR pathOpendoc
  TRY MKDIR pathOpendoc &/ "Configurations2"
  TRY MKDIR pathOpendoc &/ "META-INF"
  TRY MKDIR pathOpendoc &/ "Thumbnails"
  filex = OPEN pathOpendoc &/ "mimetype" FOR INPUT CREATE
    PRINT #filex, "application/vnd.oasis.opendocument.spreadsheet"; ' El ";" es para no insertar una terminación de línea
  CLOSE #filex
  writer = NEW XmlWriter
  WITH writer
  .Open(pathOpendoc &/ "META-INF/manifest.xml", TRUE, "UTF-8")
  .StartElement("manifest:manifest", ["xmlns:manifest", "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"])
    .StartElement("manifest:file-entry", ["manifest:media-type", "application/vnd.oasis.opendocument.spreadsheet", "manifest:version", "1.2", "manifest:full-path", "/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/statusbar/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/accelerator/current.xml"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/accelerator/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/floater/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/popupmenu/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/progressbar/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/menubar/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/toolbar/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/images/Bitmaps/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Configurations2/images/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", "application/vnd.sun.xml.ui.configuration", "manifest:full-path", "Configurations2/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", "text/xml", "manifest:full-path", "content.xml"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", "text/xml", "manifest:full-path", "styles.xml"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", "text/xml", "manifest:full-path", "meta.xml"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Thumbnails/thumbnail.png"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", " ", "manifest:full-path", "Thumbnails/"])
    .EndElement()
    .StartElement("manifest:file-entry", ["manifest:media-type", "text/xml", "manifest:full-path", "settings.xml"])
    .EndElement()
  .EndElement
  .EndDocument
  END WITH
  
  writer = NEW XmlWriter
  writer.Open(pathOpendoc &/ "content.xml", TRUE, "UTF-8")
  writer.StartElement("office:document-content")
   writer.Attribute("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0")
   writer.Attribute("xmlns:style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0")
   writer.Attribute("xmlns:text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0")
   writer.Attribute("xmlns:table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0")
   writer.Attribute("xmlns:number", "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0")
   writer.Attribute("xmlns:chart", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0")
   writer.Attribute("xmlns:form", "urn:oasis:names:tc:opendocument:xmlns:form:1.0")
   writer.Attribute("xmlns:oooc", "http://openoffice.org/2004/calc")
   writer.Attribute("xmlns:field", "urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0")
   writer.Attribute("xmlns:formx", "urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0")
   writer.Attribute("office:version", "1.2")
  
   writer.StartElement("office:body")
     writer.StartElement("office:spreadsheet")
     writer.StartElement("table:table", ["table:name", CStr(controlx.Name), "table:print", "false"])
     IF controlx.Header = GridView.Horizontal OR IF controlx.Header = GridView.Both THEN
       writer.StartElement("table:table-row")
       FOR jCount = 0 TO controlx.Columns.Count - 1
         writer.StartElement("table:table-cell", ["office:value-type", "string"])
         writer.Element("text:p", controlx.Columns[jCount].Text)
         writer.EndElement()
       NEXT
       writer.EndElement()
     ENDIF
     FOR iCount = 0 TO controlx.Rows.Count - 1
       writer.StartElement("table:table-row")
       FOR jCount = 0 TO controlx.Columns.Count - 1
         writer.StartElement("table:table-cell") ', ["office:value-type", "string"])
         IF Str$(Val(controlx[iCount, jCount].Text)) = controlx[iCount, jCount].Text THEN
           writer.Attribute("office:value-type", "float")
           writer.Attribute("office:value", controlx[iCount, jCount].Text)
         ELSE
           writer.Attribute("office:value-type", "string")
         ENDIF
         writer.Element("text:p", controlx[iCount, jCount].Text)
         writer.EndElement()
       NEXT
       writer.EndElement()
     NEXT
     writer.EndElement()
   writer.EndElement()

  writer.EndElement()
  writer.EndDocument()
  
  filex = OPEN pathOpendoc &/ "pckods" FOR INPUT CREATE
    PRINT #filex, "#!/bin/bash"
    PRINT #filex, "# Script creado con gambas, comprime ficheros para crear un documento ODS"
    PRINT #filex, "cd $(dirname $0)"
    PRINT #filex, "zip -r $1 Configurations2 META-INF Thumbnails content.xml mimetype"
  CLOSE #filex
  EXEC ["chmod", "+x", pathOpendoc &/ "pckods"] WAIT
  EXEC [pathOpendoc &/ "pckods", pathODS] WAIT
  ELSE
    ERROR "El control no es un GridView o TableView"
  ENDIF
  
END
 


Y un ejemplo sencillo que muestra la utilidad del anterior código:

' gambas class file

PUBLIC SUB Form_Open()

  WITH GridView1
    '.Header = GridView.Horizontal
    .Header = GridView.Both
    .Columns.Count = 3
    .Rows.Count = 3
  END WITH
  GridView1.Columns[0].Text = "Colunma0"
  GridView1[0, 0].Text = "hola"
  GridView1[0, 1].Text = "1 perro"
  GridView1[1, 1].Text = "10.5"
  GridView1[2, 2].Text = "123"
  opendoc.saveODS(GridView1, User.Home &/ "test.ods")

END

 


CLICK ¡¡¡Descarga las fuentes!!!! CLICK


Hilos relacionados:
Pastear Un Gridview A Una Hoja De Cálculo
Exportacion A Hoja De Calculo Con Formato

Saludos!

EDITO:

Se me olvidó mencionar que es necesario el componente gb.xml y el paquete zip
 



 
última edición por razaAztk el Lunes, 07 Febrero 2011, 04:47; editado 1 vez 
razaAztk - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuarioVer la galería personal del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Código: TableView O GridView A ODS 
 
Este codigo esta muy bien...   
 




===================
Blog personal
Web: SoloGambas seleccion de articulos dedicados a Gambas
Visita el Curso de Gambas3 ¡¡¡Gratuito!!!
 
jsbsan - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Código: TableView O GridView A ODS 
 
Conejudo, tron. Gracias por el aporte.
 




===================
No podemos regresar
 
shordi - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Código: TableView O GridView A ODS 
 
Gracias por este fantástico aporte
 



 
marcopc - Ver perfil del usuarioEnviar mensaje privado 
Volver arribaPágina inferior
Mostrar mensajes anteriores:    
 
OcultarTemas parecidos
Tema Autor Foro Respuestas último mensaje
No hay nuevos mensajes ColumView,TableView,GridView.Criterios Shell General 3 Sabado, 18 May 2013, 15:53 Ver último mensaje
shordi
No hay nuevos mensajes ¿Cómo Saber La Celda Clickeada En Un Gri... frajanic General 13 Martes, 07 Julio 2015, 23:54 Ver último mensaje
frajanic
No hay nuevos mensajes GridView Vs TableView calcena Controles/Librerías/Componentes 2 Viernes, 29 Julio 2016, 16:16 Ver último mensaje
calcena
No hay nuevos mensajes Ejemplo De Dos Maneras De Cómo Ordenar Un... shordi Aplicaciones/Fragmentos de Código 2 Jueves, 02 Marzo 2017, 13:14 Ver último mensaje
shordi
 

Publicar nuevo tema  Responder al tema  Página 1 de 1
 

Usuarios navegando en este tema: 0 registrados, 0 ocultos y 1 invitado
Usuarios registrados conectados: Ninguno


 
Lista de permisos
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas
No puede adjuntar archivos
Puede descargar archivos
No puede publicar eventos en el calendario



  

 

cron