Hi there
MashPOI is a collection of some jPOI related methods that I have found from the forum and created a library. As much as there are a couple of functions in the modules, I also want to add functionality to easily add worksheets, add rows and style the various columns in Excel documents.
I started this as a means to achieve something else...
A working example of importing all excel sheet records to a database table is herein. I will link this to another app I'm finalising. It's an exciting one.
MashPOI is a collection of some jPOI related methods that I have found from the forum and created a library. As much as there are a couple of functions in the modules, I also want to add functionality to easily add worksheets, add rows and style the various columns in Excel documents.
I started this as a means to achieve something else...
A working example of importing all excel sheet records to a database table is herein. I will link this to another app I'm finalising. It's an exciting one.
B4X:
Sub btnB4XGoodies_Click
'select and parse the xls file with b4x goodies
Dim ext As List
ext.Initialize
ext.Add("*.xls")
ext.Add("*.xlsx")
Dim goodFile As String = OpenSaveFileDialog(MainForm,True,"Select Excel File",File.DirApp,ext)
If goodFile = "" Then Return
'test of the file meets the b4x structure
Dim wb As PoiWorkbook = MashPOI.PoiOpenFile("",goodFile,"")
Dim ws As PoiSheet = MashPOI.poigetworksheet(wb,"B4Xgoodies")
'define the record map to link excel columns to db record
Dim rmap As Map
rmap.Initialize
rmap.Put("a","product")
rmap.Put("b","atype")
rmap.Put("c","category")
rmap.Put("d","aname")
rmap.Put("e","author")
rmap.Put("f","latestversion")
rmap.Put("g","latestversiondate")
rmap.Put("h","license")
rmap.Put("i","description")
rmap.Put("j","url")
rmap.Put("k","tags")
'get all data from the excel sheet
Dim allRows As List = MashPOI.PoiGetRows(ws)
'close the workbook
wb.Close
' start the import by extracting only the relavant fields to import, starting at row 1
Dim records As List = MashPOI.Poi2Import(allRows,rmap,1)
'import the data and exclude the first row
DBUtils.TableClear(b4xgoodies,"b4xgoodies")
'reset the counters
DBUtils.SQLiteResetCounter(b4xgoodies,"b4xgoodies","id")
'add records to the database
DBUtils.InsertMaps(b4xgoodies,"b4xgoodies",records)
' how many records do we have
Dim recCount As Int = DBUtils.RecordCount(b4xgoodies,"b4xgoodies","id")
InformUser(MainForm,"B4X Goodies",recCount & " record(s) now exist in your records.")
'load the goodies
LoadAuthors
End Sub
Attachments
Last edited: