B4J Library jExcel library

A more powerful library is now available: https://www.b4x.com/android/forum/t...microsoft-excel-xls-and-xlsx-workbooks.57392/

This library allows you to read and write XLS files. It is similar to B4A Excel library: http://www.b4x.com/android/forum/threads/read-write-excel-files-on-android.25632/#content

You should follow the steps in the above link to download and copy the native library.

There are two new methods in this library:

ReadableWorkbook.InitializeAsync - Asynchronously opens the file. The Ready event is raised when the workbook is ready.

Sheet.GetAllAsync - Asynchronously gets all the cells from the sheet. The ValuesAvailable event is raised when the operation completee.

SS-2013-11-26_14.37.34.png


The attached example allows you to open a workbook file and browse its content.

It depends on jxl.jar: www.b4x.com/b4j/files/jxl.jar
 

Attachments

  • ExcelExample.zip
    2.4 KB · Views: 3,230
  • jExcel.zip
    15.9 KB · Views: 4,039
Last edited:

Tayfur

Well-Known Member
Licensed User
Longtime User
No. You can set an image with jPOI library.

I recived an error!

Waiting for debugger to connect...
Program started.
616
610
bok-1
bok-2:0
bok-z:0
bok-2:1
Warning: Cell A1 already contains data
jxl.common.AssertionFailed
at jxl.common.Assert.verify(Assert.java:37)
at jxl.biff.drawing.DrawingData.initialize(DrawingData.java:92)
at jxl.biff.drawing.DrawingData.getSpContainer(DrawingData.java:207)
at jxl.biff.drawing.ComboBox.initialize(ComboBox.java:209)
at jxl.biff.drawing.ComboBox.getObjectId(ComboBox.java:276)
at jxl.biff.drawing.DrawingGroup.addDrawing(DrawingGroup.java:212)
at jxl.biff.drawing.ComboBox.<init>(ComboBox.java:162)
at jxl.read.biff.SheetReader.handleObjectRecord(SheetReader.java:1680)
at jxl.read.biff.SheetReader.read(SheetReader.java:1059)
at jxl.read.biff.SheetImpl.readSheet(SheetImpl.java:716)
at jxl.read.biff.WorkbookParser.getSheet(WorkbookParser.java:257)
at anywheresoftware.b4a.objects.WorkbookWrapper.GetSheet(WorkbookWrapper.java:60)
at b4j.example.formkolietiket._book1_ready(formkolietiket.java:143)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$4.run(BA.java:196)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Error occurred on line: 92 (FormKoliEtiket)
jxl.common.AssertionFailed
at jxl.common.Assert.verify(Assert.java:37)
at jxl.biff.drawing.DrawingData.initialize(DrawingData.java:92)
at jxl.biff.drawing.DrawingData.getSpContainer(DrawingData.java:207)
at jxl.biff.drawing.ComboBox.initialize(ComboBox.java:209)
at jxl.biff.drawing.ComboBox.getObjectId(ComboBox.java:276)
at jxl.biff.drawing.DrawingGroup.addDrawing(DrawingGroup.java:212)
at jxl.biff.drawing.ComboBox.<init>(ComboBox.java:162)
at jxl.read.biff.SheetReader.handleObjectRecord(SheetReader.java:1680)
at jxl.read.biff.SheetReader.read(SheetReader.java:1059)
at jxl.read.biff.SheetImpl.readSheet(SheetImpl.java:716)
at jxl.read.biff.WorkbookParser.getSheet(WorkbookParser.java:257)
at anywheresoftware.b4a.objects.WorkbookWrapper.GetSheet(WorkbookWrapper.java:60)
at b4j.example.formkolietiket._book1_ready(formkolietiket.java:143)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$4.run(BA.java:196)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)

B4X:
Sub Class_Globals
    Private fx As JFX
    Private EtiketForm As Form
    Private ComboBox_firma As ComboBox
    Private ComboBox_Parca As ComboBox
    Private ComboBox_lotNo As ComboBox
   
    Private book1 As ReadableWorkbook
    Private book2 As ReadableWorkbook
    Private Woorkbook_Sheets As Map
    Private ExcelAdi1 As String
    Private ExcelAdi2 As String
    Private Button_test As Button
    Private TableView_Firma As TableView
    Private TableView_ParcaList As TableView
    Private TableView_ambar As TableView
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    ExcelAdi1 ="\\server\KALITE_RAPOR\-DATABASE-\DATABASE.xls"
    ExcelAdi2 ="\\server\DEPO\AMBAR.xls"
    EtiketForm.Initialize("FormEtiket",800,600)
    EtiketForm.RootPane.LoadLayout("Form_Koli_Etiket")
    EtiketForm.WindowHeight=768
    EtiketForm.WindowWidth=1024
    EtiketForm.Show
    EtiketForm.Title="KOLI / KASA ETIKET BASMA FORMU"
    Temizle
   
   
       
End Sub



Public Sub Show
    EtiketForm.Show
End Sub

private Sub ExcelYukle1(filename As String)
    If filename <> "" Then
        'progress1.Visible = True
        book1.InitializeAsync("book1", "", filename)
    End If
End Sub

private Sub ExcelYukle2(filename As String)
    If filename <> "" Then
        'progress1.Visible = True
        book2.InitializeAsync("book2", "", filename)
    End If
    If book2.IsInitialized =False Then
        fx.Msgbox(EtiketForm,"hata dosya açılmadı","")
    End If
End Sub
Sub Book2_Ready (Success As Boolean)
    ' hafızaya yüklene exceli sayfa sayfa MAP yükleniyor, daha sonra kullanmak için
    'progress1.Visible = False
    Log("bok-2")
    If Success Then
       
        Woorkbook_Sheets.Initialize
        For i = 0 To book2.NumberOfSheets - 1
            Dim sheet As ReadableSheet = book2.GetSheet(i)
            Log("book2 "&sheet.Name)
            If sheet.Name="AMBAR" Then
                sheet.GetAllAsync("Sheet_ambar")
                Exit
            End If
       
           
        Next
        fx.Msgbox( EtiketForm,"Sayfa adedi:"& Woorkbook_Sheets.Size,"")
    Else
        fx.Msgbox( EtiketForm,"Error loading file.","")
    End If
   
End Sub

Sub Book1_Ready (Success As Boolean)
    ' hafızaya yüklene exceli sayfa sayfa MAP yükleniyor, daha sonra kullanmak için
    'progress1.Visible = False
    Log("bok-1")
    If Success Then
        Dim z As Int
        z=0
        Woorkbook_Sheets.Initialize
        For i = 0 To book1.NumberOfSheets - 1
            Log("bok-2:"&i)
            Dim sheet As ReadableSheet = book1.GetSheet(i)
            If sheet.Name="PART_LIST" Then
                Log("bok-z:"&i)
                sheet.GetAllAsync("Sheet_database")
                z=z+1
            End If
            If sheet.Name="EPOSTA" Then
                Log("bok-zz:"&i)
                sheet.GetAllAsync("Sheet_eposta")
                z=z+1
            End If
            If z>1 Then Exit
        Next
        fx.Msgbox( EtiketForm,"Sayfa adedi:"& Woorkbook_Sheets.Size,"")
    Else
        fx.Msgbox( EtiketForm,"Error loading file.","")
    End If
   
End Sub

Sub Sheet_ambar_ValuesAvailable (Success As Boolean, Values As List)
   
    'progress1.Visible = False
    If Success Then
        For rowCounter = 0 To Values.Size - 1
           
            Dim row() As String = Values.Get(rowCounter)
            If rowCounter = 0 Then
                TableView_ambar.SetColumns(row)
            Else
                TableView_ambar.Items.Add(row)
            End If
        Next   
    Else
        Log(LastException)
    End If
End Sub


'-parca ad boy koli içi adet vs  bilgileri vs yuklendi tabloya
Sub Sheet_database_ValuesAvailable (Success As Boolean, Values As List)
    Log("databes-1 :")
    'progress1.Visible = False
    If Success Then
        For rowCounter = 0 To Values.Size - 1
            Log("databes-1 :"&rowCounter)
            Dim row() As String = Values.Get(rowCounter)
            If rowCounter = 0 Then
                TableView_ParcaList.SetColumns(row)
            Else
                TableView_ParcaList.Items.Add(row)
            End If
        Next   
    Else
        Log(LastException)
    End If
   
    If TableView_Firma.Items.Size>0 And TableView_ParcaList.Items.Size>0 Then
        ExcelYukle2(ExcelAdi2)
    End If
   
End Sub

Sub Sheet_eposta_ValuesAvailable (Success As Boolean, Values As List)
    Log("eposta :")
    'progress1.Visible = False
    If Success Then
        For rowCounter = 0 To Values.Size - 1
            Log("eposta :"&rowCounter)
            Dim row() As String = Values.Get(rowCounter)
            If rowCounter = 0 Then
                TableView_Firma.SetColumns(row)
            Else
                TableView_Firma.Items.Add(row)
            End If
        Next   
    Else
        Log(LastException)
    End If
    If TableView_Firma.Items.Size>0 And TableView_ParcaList.Items.Size>0 Then
        ExcelYukle2(ExcelAdi2)
    End If
   
End Sub



'comboya firma isimleri yükleni DATABASE>>eposta
Private Sub Firma_yukle
   
    Dim i As Int
    i = 1
    Do Until True 'Trim(Sayfa5.Cells(i + 1, 1) & "") = "0" Or Trim(Sayfa5.Cells(i + 1, 1) & "") = ""
        i = i + 1
        ComboBox_firma.Items.Add(i)
    Loop 'Trim(Sayfa5.Cells(i + 1, 1) & "") = "0" Or Trim(Sayfa5.Cells(i + 1, 1) & "") = ""
End Sub

Sub ComboBox_firma_SelectedIndexChanged(Index As Int, Value As Object)
fx.Msgbox(EtiketForm,"xxx","xxx")   
End Sub

Sub ComboBox_Parca_SelectedIndexChanged(Index As Int, Value As Object)
fx.Msgbox(EtiketForm,"xxx","xxx")   
End Sub

Sub ComboBox_lotNo_SelectedIndexChanged(Index As Int, Value As Object)
    fx.Msgbox(EtiketForm,"xxx","xxx")
End Sub



'Exc

Sub Button_test_MouseClicked (EventData As MouseEvent)
    'ExcelOpen_Action(ExcelAdi)
    TemizleTablo
   
    ExcelYukle1(ExcelAdi1)
   
End Sub

Private Sub TemizleTablo
    TableView_ambar.Items.Clear
    TableView_Firma.Items.Clear
    TableView_ParcaList.Items.Clear
End Sub
Private Sub Temizle
    ComboBox_Parca.Items.Clear
    ComboBox_firma.Items.Clear
    ComboBox_lotNo.Items.Clear
   
End Sub
 
Top