B4J Question (solved)[JPOI] copyRows with Javaobject

Tayfur

Well-Known Member
Licensed User
Longtime User
Code: Copy
DosyaParca.InitializeExisting(DirApp,"tast.xlsx,"")
SayfaParca=DosyaParca.GetSheet(0)
Dim jo As JavaObject = SayfaParca
jo.RunMethod("copyRows", Array(3,4,5,1))

Waiting for debugger to connect...
Program started.
Satırda hata oluştu: 326
java.lang.RuntimeException: Method: copyRows not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
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.runVoidMethod(Shell.java:657)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
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:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)


https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFSheet.html#method.summary
void copyRows(int srcStartRow, int srcEndRow, int destStartRow, CellCopyPolicy cellCopyPolicy)
Copies rows between srcStartRow and srcEndRow to the same sheet, starting at destStartRow Convenience function for copyRows(List, int, CellCopyPolicy) Equivalent to copyRows(getRows(srcStartRow, srcEndRow, false), destStartRow, cellCopyPolicy)

How can I use correct way wit JavaObject.
Thanks.
 
Code: Copy
Dim builder As JavaObject
builder.InitializeNewInstance("org.apache.poi.ss.usermodel.CellCopyPolicy", Null)
jo.RunMethod("copyRows", Array(3,4,5,builder.RunMethod("build", Null)))
thank you boss..
I will try.
 
Last edited:
Upvote 0
Code: Copy
Dim builder As JavaObject
builder.InitializeNewInstance("org.apache.poi.ss.usermodel.CellCopyPolicy", Null)
jo.RunMethod("copyRows", Array(3,4,5,builder.RunMethod("build", Null)))

Code: Copy
SayfaFirma=DosyaFirma.GetSheet(0)
        Dim jo As JavaObject = SayfaFirma
        Dim builder As JavaObject
        builder.InitializeNewInstance("org.apache.poi.ss.usermodel.CellCopyPolicy", Null)
        jo.RunMethod("copyRows", Array(3,4,5,builder.RunMethod("build", Null)))
I recived an error

Waiting for debugger to connect...
Program started.
Satırda hata oluştu: 355
java.lang.RuntimeException: Method: build not found in: org.apache.poi.ss.usermodel.CellCopyPolicy
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:366)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:119)
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:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
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:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

Note: I use win 10 and Office2016
 
Upvote 0
Code: Copy
SayfaFirma=DosyaFirma.GetSheet(0)
        Dim jo As JavaObject = SayfaFirma
        Dim builder As JavaObject
        builder.InitializeNewInstance("org.apache.poi.ss.usermodel.CellCopyPolicy", Null)
        jo.RunMethod("copyRows", Array(3,4,5,builder.RunMethod("build", Null)))
I recived an error



Note: I use win 10 and Office2016

Hello @Erel

I changed buldier ==>> createBuldier (if is it ok?)

Code: Copy
Dim jo As JavaObject = SayfaFirma
        Dim builder As JavaObject
        builder.InitializeNewInstance("org.apache.poi.ss.usermodel.CellCopyPolicy", Null)
        jo.RunMethod("copyRows", Array(3,5,25,builder.RunMethod("createBuilder", Null)))

bu I recivede en error

Waiting for debugger to connect...
Program started.
Satırda hata oluştu: 355
java.lang.RuntimeException: Method: copyRows not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
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.runVoidMethod(Shell.java:657)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
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:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)

for helping example
Code: Copy
CellCopyPolicy policy = new CellCopyPolicy().createBuilder()
                                                  .cellFormula(false)
                                                  .cellStyle(true)
                                                  .cellValue(false)
                                                  .condenseRows(false)
                                                  .copyHyperlink(false)
                                                  .mergedRegions(false)
                                                  .mergeHyperlink(false)
                                                  .rowHeight(false)
                                                  .build();
 
Last edited:
Upvote 0
The correct code to create a CellCopyPolicy is
Code: Copy
Dim builder As JavaObject
builder.InitializeNewInstance("org.apache.poi.ss.usermodel.CellCopyPolicy.Builder", Null)
jo.RunMethod("copyRows", Array(3,4,5,builder.RunMethod("build", Null)))

However the problem is that the sheet you are using doesn't have a copyRows method: https://poi.apache.org/apidocs/org/apache/poi/xssf/streaming/SXSSFSheet.html
 
Upvote 0
The correct code to create a CellCopyPolicy is
Code: Copy
Dim builder As JavaObject
builder.InitializeNewInstance("org.apache.poi.ss.usermodel.CellCopyPolicy.Builder", Null)
jo.RunMethod("copyRows", Array(3,4,5,builder.RunMethod("build", Null)))

However the problem is that the sheet you are using doesn't have a copyRows method: https://poi.apache.org/apidocs/org/apache/poi/xssf/streaming/SXSSFSheet.html


I solved my way.
Look ti please; Maybe it is wrong way, but it works.
Code: Copy
#If JAVA
import org.apache.poi.ss.usermodel.CellCopyPolicy;
public static CellCopyPolicy Test() {
CellCopyPolicy policy = new CellCopyPolicy().createBuilder()
.build();
return policy;
}
#End If


Public Poicellpolicy As Object
    Public NativeMe As JavaObject
'//----------------------
     NativeMe = Me
    Poicellpolicy = NativeMe.RunMethod("Test", Null)
    Log(Poicellpolicy)
       SayfaFirma=DosyaFirma.GetSheet(0)
        Dim jo As JavaObject = SayfaFirma
        jo.RunMethod("copyRows", Array(3,5,25,Poicellpolicy))
            DosyaFirma.Save(file.dirapp,"myfile.xlsx")
 
Upvote 0
Upvote 0
Upvote 0
Back
Top