B4J Question JPOI SetRange

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
I attached a test file, a example written to learn the Jpoi library
Why SetRange does not work properly?
B4X:
SetNamedRange(wb, "sheet1", "Range_name", "$A$2:$A$" & 20) 'set the range
SetNamedRange(wb, "sheet1", "Range_pieces", "$B$2:$B$" & 20)

Thanks
 

Attachments

  • Test_JPOI.zip
    39.4 KB · Views: 161

micro

Well-Known Member
Licensed User
Longtime User
You should better describe what doesn't work for you.
The bar displayed are incorrect (see attached file in the first post)

B4X:
Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    Dim wb As PoiWorkbook
    wb.InitializeExisting(File.DirAssets, "template.xlsx", "")
    Dim s1 As PoiSheet = wb.GetSheet(0)    'unica sheet
    Dim i As Int
    For i = 1 To 20     ' bar displayed, but is not so
        Dim row As PoiRow = s1.CreateRow(i)
        row.CreateCellString(0, "Name" & i)
        row.CreateCellNumeric(1, Rnd(100, 1000))
    Next
    SetNamedRange(wb, "sheet1", "Range_name", "$A$2:$A$" & 20) 'set the range
    SetNamedRange(wb, "sheet1", "Range_pieces", "$B$2:$B$" & 20)
    wb.Save(File.DirApp, "Chart.xlsx")
    wb.Close
    fx.ShowExternalDocument(File.GetUri(File.DirApp, "Chart.xlsx"))
End Sub

Thanks
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I ran your code from post #1 and both ranges are being created, could it be the code you use to generate the graphics is where the problem lies?
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
After I edited the data range for the graph to Range_name;Range_pieces all the columns were visible.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
After I edited the data range for the graph to Range_name;Range_pieces all the columns were visible.
??
This is in my template.xlsx (after chart.xlsx)
upload_2018-4-8_12-19-30.png


but as you see not all bars are displayed.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
After I regenerated the template file it seems to work now.
(The template was generated inside the b4j app by drawing the graph to the spreadsheet, so is not exactly like your original)
image1.png
 

Attachments

  • template.zip
    13.7 KB · Views: 153
Last edited:
Upvote 0
Top