Página 1 de 1

Como puedo hacer un contador en OpenOffice Calc?

Publicado: Mié Jul 29, 2015 9:01 pm
por Johan Manuel Ramos
Tengo un archivo en Open Office Calc con casos de prueba, pero quiero hacer un contador en los macros, pero no se como?
Podria alguien ayudarme para hacer el contador?
basicamente el contador tiene que contar cuantos registros tengo.
y en el codigo tengo esto:

Código: Seleccionar todo

Sub Main

 Dim oSheet : oSheet = ThisComponent.Sheets.getByName("TestCases") 
    Dim fs, f, i
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.CreateTextFile("C:\Temp\testfile.xml", True)
    
      
    f.WriteLine ("<sections>")
    f.WriteLine ("<sectiones>")
        
     
    for i = 2 To 10
 
     oCell = oSheet.getCellByPosition(1,i)
    f.WriteLine ("<case>" & oCell.getString & "")
     
     oCell = oSheet.getCellByPosition(2,i)
    f.WriteLine ("<Id>" & oCell.getString & "</Id>") 
          
      oCell = oSheet.getCellByPosition(3,i)
    f.WriteLine ("<Title>" & oCell.getString & "</Title>")     
              
       
     oCell = oSheet.getCellByPosition(4,i)
    f.WriteLine ("<Type>" & oCell.getString & "</Type>")
    
     oCell = oSheet.getCellByPosition(5,i)
    f.WriteLine ("<Priority>" & oCell.getString & "</Priority>")
    
     oCell = oSheet.getCellByPosition(6,i)
    f.WriteLine ("<Estimate>" & oCell.getString & "</Estimate>")
    
     oCell = oSheet.getCellByPosition(7,i)
    f.WriteLine ("<Milestone>" & oCell.getString & "</Milestone>")
    
     oCell = oSheet.getCellByPosition(8,i)
    f.WriteLine ("<References>" & oCell.getString & "</References>")
    
     oCell = oSheet.getCellByPosition(9,i)
    f.WriteLine ("" & oCell.getString & "</case>")
    
      Next i
    
    f.Close


End Sub
Que me hace falta para hacer que me cuente cuantos registros tengo?

Re: Como puedo hacer un contador en OpenOffice Calc?

Publicado: Jue Jul 30, 2015 4:38 pm
por SLV-es
Supongo que en realidad lo que buscas es saber cuantas filas tienes en la hoja, para poder exportarlas al documento xml ¿es así?
ultima-fila-utilizada.ods
(11.4 KiB) Descargado 253 veces
Aunque yo pondría un bucle do while true que empiece leyendo la primera fila y que vaya incrementando el contador de fila, y saldría del bucle cuando encuentre la primera celda vacía.

Código: Seleccionar todo

i=2
do while true

     oCell = oSheet.getCellByPosition(1,i)

    if oCell.getString = "" then exit do

    f.WriteLine ("<case>" & oCell.getString & "")
     
    ...

    i=i+1   

loop