B4J Question Write Text to file excel only replace

supriono

Member
Licensed User
Longtime User
hello
i want to make tutorial about b4j for my university
but for tutorial 16 (write data to excel) i have same trouble
aplication only save last data..and when i want write another data value..last value otomatic my be erase like replace data.

this is my code :

B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private inputtext As TextArea
    Private VCOL As TextArea
    Private VROW As TextArea
    Dim newWorkbook As WritableWorkbook
    Dim sheet1 As WritableSheet
    Private DV As Label
    Private VCOL1 As TextArea
    Private VROW1 As TextArea
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("1")
    MainForm.Show
   
End Sub
Sub WR_Action
    newWorkbook.Initialize("C:\", "gas.xls")
    sheet1 = newWorkbook.AddSheet("Sheet1", 0)
    Log("START")
    Dim cell As WritableCell
    cell.InitializeText(VCOL.Text,VROW.Text, inputtext.Text)
    sheet1.AddCell(cell)
    newWorkbook.Write
    newWorkbook.Close
    Log("FINIS")
End Sub
Sub Finis_Action
   
End Sub
Sub RD_Action
   
End Sub

and this is GUI aplication:
B4j.png


can same body help my how to fixe this trouble
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Do you want to write multiple values to the sheet? Why are you creating and closing the workbook each time?
Keep it open and add a new cell each time.

If you want to open an existing workbook and modify it then you need to initialize a ReadableWorkbook and then initialize the WritableWorkbook with Initialize2.

Tip: Check that the values are actually numbers with IsNumber.
 
Upvote 0

supriono

Member
Licensed User
Longtime User
Do you want to write multiple values to the sheet? Why are you creating and closing the workbook each time?
Keep it open and add a new cell each time.

If you want to open an existing workbook and modify it then you need to initialize a ReadableWorkbook and then initialize the WritableWorkbook with Initialize2.

Tip: Check that the values are actually numbers with IsNumber.

thanks for your respone erel.
i will try.

when i must closing workbook ? in tutorial 18 i want to make data log from arduino (use serial com) save to excel file...
 
Upvote 0

supriono

Member
Licensed User
Longtime User
Do you any sample code how to write value to cell and read again with out replace last data file excel.
i am very confused..

sory when i distrub your actifity erel
 
Upvote 0
Top