#Region Project Attributes
#ApplicationLabel: RegAnt Print
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
Dim rp As RuntimePermissions
Dim fp As FilePickerDialog
Dim sql As SQL
Dim dbpath As String
dbpath=File.DirRootExternal & "/smartlauncher/.project/Regant/"
Dim r As Int=0
Dim rr As Int =0
Dim riga As Int=0
Dim colonna As Int =0
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
Dim props As DialogProperties
Dim ext() As String
ext=Array As String ("csv")
props.Initialize("",File.DirRootExternal&"/Download",0,0,ext) 'Array As String(".jpg",".png",".pdf"))
fp.Initialize("FilePicker")
fp.Properties = props
rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
File.Copy(dbpath,"DEV_DB",File.DirRootExternal & "/Download","DEV_DB")
fp.show
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub FilePicker_onSelectedFilePaths(selected() As String)
If selected.Length =1 Then
Log($"FilePicker_onSelectedFilePaths(${selected.Length})"$)
fp.dismiss
Dim parser As CSVParser
parser.Initialize
Dim table As List = parser.Parse(File.ReadString("", selected(selected.Length-1)), ",", True)
sql.Initialize(File.DirRootExternal & "/Download","DEV_DB",False)
Dim workbook1 As ReadableWorkbook
Dim Sheet As ReadableSheet
Dim tr As Int=0
For Each row() As String In table
tr=row.Length
Next
If tr=12 Then 'addetti
End If
If tr=10 Then 'attrezzature
End If
If tr=14 Then 'controlli
workbook1.Initialize(File.DirAssets,"rptcontrolli.xls")
Sheet = workbook1.GetSheet(0)
Dim newWorkbook As WritableWorkbook
newWorkbook.Initialize2(File.DirRootExternal,"Download/rptcontrolli.xls",workbook1)
Dim sheet1 As WritableSheet
sheet1 = newWorkbook.GetSheet(0)
Dim cell As WritableCell
For Each row() As String In table
For r = 0 To 13
riga=rr+5
colonna=r
Dim value As String =row(r)
SetCellString(sheet1, colonna,riga ,value)
'cell.InitializeText(colonna, riga, row(r))
'sheet1.AddCell(cell)
'AddImage(sheet1, File.OpenInput(File.DirAssets, "addetti.png"), 12,7, 2, 1)
Next
rr=rr+1
Next
End If
newWorkbook.Write
newWorkbook.Close
Else
fp.show
End If
End Sub
Sub SetCellString(wb As WritableSheet, Col As Int, Row As Int, Text As String)
Dim jo As JavaObject = wb
jo.RunMethodJO("getCell", Array(Col, Row)).RunMethod("setString", Array(Text))
End Sub
Sub SetCellNumber(wb As WritableSheet, Col As Int, Row As Int, Value As Double) 'ignore
Dim jo As JavaObject = wb
jo.RunMethodJO("getCell", Array(Col, Row)).RunMethod("setValue", Array(Value))
End Sub
Sub AddImage(wb As WritableSheet, bmp As InputStream, col As Double, row As Double, _
width As Double, height As Double)
Dim wi As JavaObject
wi.InitializeNewInstance("jxl.write.WritableImage", Array(col, row, width, height, Bit.InputStreamToBytes(bmp)))
Dim jo As JavaObject = wb
jo.RunMethod("addImage", Array(wi))
End Sub