'============================================
La clase Javascript
'============================================
Option Public
Option Declare
UseLSX "*javacon" '<-- Importante
Use "class:baseObject" '<--- Clase javascript
Use "java:POI" '<--- Clase Java
Public Class POI As baseObject
oClass As JavaClass
oSession As JavaSession
oObj As Variant
'=========================================================
Sub New(), baseObject()
On Error GoTo Control_Error
classname="POI"
Set me.oSession = New JavaSession()
Set me.oClass = me.oSession.GetClass("POI")
Set me.oObj = me.oClass.CreateObject()
Exit Sub
'=====================================================================
Control_Error: Call AddToStackTraceObj( Me )
'====================================================================
Error Err , Error
Exit Sub
End Sub
%REM
Function getDestino
Description: Comments for Function
%END REM
Function getWorkBook( sFileName As String ) As Variant
On Error GoTo Control_Error
Set getWorkBook = me.oObj.getWorkBook(sFileName)
Exit Function
'=====================================================================
Control_Error: Call AddToStackTraceObj( Me )
'====================================================================
Error Err , Error
Exit Function
End Function
Function getLibro( sFileName As String ) As Variant
On Error GoTo Control_Error
Set getLibro = me.oObj.getLibro(sFileName)
Exit Function
'=====================================================================
Control_Error: Call AddToStackTraceObj( Me )
'====================================================================
Error Err , Error
Exit Function
End Function
%REM
Function CellToString
Description: Comments for Function
%END REM
Function CellToString( oCell As Variant ) As String
If IsNull( oCell ) Then
CellToString = ""
Else
CellToString = me.oObj.cellToString(oCell)
End If
End Function
%REM
Function toJSON
Description: Comments for Function
%END REM
Function toJSON( sFileName As String , sSheetName As String ) As Variant
Dim oWorkBook As Variant,oSheet As Variant
Dim nRows As Integer , nCols As Integer, nCol As Integer , nRow As Integer
Dim oRow As Variant , oCell As Variant
Dim oJSON As Variant , oJSONArray As Variant
Set oWorkBook = me.getWorkBook( sFileName )
Set oSheet = oWorkBook.getSheet(sSheetName)
nRows = oSheet.getLastRowNum()
nCols = oSheet.getRow(0).getLastCellNum() -1
Set oJSON = NewObj("JSONObject")
Set oJSONArray = newObj("JSONArray")
For nRow=0 To nRows
Set oRow = oSheet.getRow(nRow)
With NewObj("JSONObject")
Call .AddItem( "row" , nRow )
For nCol=0 To nCols
If isVacio(oRow ) Then
Call .AddItem( "col" & nCol, "" )
Else
If IsObject(oRow.getCell(nCol)) Then
Set oCell = oRow.getCell(nCol)
If isVacio(oCell) Then
Call .AddItem( "col" & nCol, "" )
Else
Call .AddItem( "col" & nCol, me.cellToString(oCell) )
End If
Else
Call .AddItem( "col" & nCol, oRow.getCell(nCol) )
End If
End If
Next
Call oJSONArray.AddItem( .this() )
End With
Next
Call oJSON.addItem( "total" , nRows+1)
Call oJSON.addItem( "success" , True )
Call oJSON.addItem( "rows" , oJSONArray )
Call oJSON.addItem( "path" , sFileName )
Call oJSON.addItem( "sheet" , sSheetName )
Set toJSON = oJSON
End Function
%REM
Sub saveTo
Description: Comments for Sub
%END REM
Sub saveTo( oWorkbook as Variant , sFullPath As String )
Call me.oObj.saveTo( oWorkbook , sFullPath )
End Sub
End Class