Closed Moyuyanli closed 3 months ago
org.apache.poi:poi
是 接口 + 简单实现
org.apache.poi:poi-ooxml
是 复杂实现
api("org.apache.poi:poi:5.3.0")
implementation("org.apache.poi:poi-ooxml:5.3.0")
我这样写是标准写法
implementation
依赖HuYanEconomy
-> mirai-economy-core
-> mirai-economy-core
-> mirai-hibernate-plugin
-> mirai-administrator
override fun onEnable() {
try {
org.apache.poi.xssf.usermodel.XSSFWorkbookFactory::class.toString()
} catch (_: NoClassDefFoundError) {
jvmPluginClasspath.downloadAndAddToPath(
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
listOf("org.apache.poi:poi-ooxml:5.3.0")
)
}
}
我在plugin-libraries里面找到了poi-ooxml,这是不是下载了
这是我插件报错的日志
2024-08-10 10:41:02 E/HuYanEconomy: cn.hutool.poi.exceptions.POIException: IOException: Your InputStream was neither an OLE2 stream, nor an OOXML stream or you haven't provide the poi-ooxml*.jar in the classpath/modulepath - FileMagic: OOXML, having providers: [org.apache.poi.hssf.usermodel.HSSFWorkbookFactory@610f8dd8]
cn.hutool.poi.exceptions.POIException: IOException: Your InputStream was neither an OLE2 stream, nor an OOXML stream or you haven't provide the poi-ooxml*.jar in the classpath/modulepath - FileMagic: OOXML, having providers: [org.apache.poi.hssf.usermodel.HSSFWorkbookFactory@610f8dd8]
at HuYanEconomy-0.1.19.mirai2.jar[private]//cn.hutool.poi.excel.WorkbookUtil.createBook(WorkbookUtil.java:148)
at HuYanEconomy-0.1.19.mirai2.jar[private]//cn.hutool.poi.excel.WorkbookUtil.createBook(WorkbookUtil.java:133)
at HuYanEconomy-0.1.19.mirai2.jar[private]//cn.hutool.poi.excel.ExcelReader.<init>(ExcelReader.java:93)
at HuYanEconomy-0.1.19.mirai2.jar[private]//cn.hutool.poi.excel.ExcelUtil.getReader(ExcelUtil.java:224)
at HuYanEconomy-0.1.19.mirai2.jar[private]//cn.hutool.poi.excel.ExcelUtil.getReader(ExcelUtil.java:211)
at HuYanEconomy-0.1.19.mirai2.jar//cn.chahuyun.economy.plugin.FishManager.reloadFish(FishManager.java:68)
at HuYanEconomy-0.1.19.mirai2.jar//cn.chahuyun.economy.plugin.FishManager.init(FishManager.java:36)
at HuYanEconomy-0.1.19.mirai2.jar//cn.chahuyun.economy.HuYanEconomy.onEnable(HuYanEconomy.java:72)
at net.mamoe.mirai.console.internal.plugin.JvmPluginInternal.internalOnEnable$mirai_console(JvmPluginInternal.kt:244)
at net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl.enable(BuiltInJvmPluginLoaderImpl.kt:393)
at net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl.enable(BuiltInJvmPluginLoaderImpl.kt:40)
at net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader$BuiltIn.enable(JvmPluginLoader.kt)
at net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader$BuiltIn.enable(JvmPluginLoader.kt:54)
at net.mamoe.mirai.console.plugin.PluginManager.enablePlugin(PluginManager.kt:173)
at net.mamoe.mirai.console.internal.plugin.PluginManagerImpl.enableAllLoadedPlugins$mirai_console(PluginManagerImpl.kt:193)
at net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge.doStart$mirai_console(MiraiConsoleImplementationBridge.kt:360)
at net.mamoe.mirai.console.MiraiConsoleImplementation$Companion.start(MiraiConsoleImplementation.kt:512)
at net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader.startAsDaemon(MiraiConsoleTerminalLoader.kt:182)
at net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader.startAsDaemon$default(MiraiConsoleTerminalLoader.kt:181)
at net.mamoe.mirai.console.terminal.MiraiConsoleTerminalLoader.main(MiraiConsoleTerminalLoader.kt:59)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.itxtech.mcl.Utility.bootJars(Utility.java:86)
at org.itxtech.mcl.Utility.bootJars(Utility.java:76)
at org.itxtech.mcl.Utility.bootMirai(Utility.java:98)
at org.itxtech.mcl.module.builtin.Boot.boot(Boot.java:113)
at org.itxtech.mcl.module.ModuleManager.phaseBoot(ModuleManager.java:123)
at org.itxtech.mcl.Loader.lambda$start$4(Loader.java:196)
at org.itxtech.mcl.Loader.tryCatching(Loader.java:151)
at org.itxtech.mcl.Loader.start(Loader.java:196)
at org.itxtech.mcl.Loader.main(Loader.java:84)
Caused by: java.io.IOException: Your InputStream was neither an OLE2 stream, nor an OOXML stream or you haven't provide the poi-ooxml*.jar in the classpath/modulepath - FileMagic: OOXML, having providers: [org.apache.poi.hssf.usermodel.HSSFWorkbookFactory@610f8dd8]
at mirai-administrator-1.4.3.mirai2.jar[shared]//org.apache.poi.ss.usermodel.WorkbookFactory.wp(WorkbookFactory.java:334)
at mirai-administrator-1.4.3.mirai2.jar[shared]//org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:224)
at HuYanEconomy-0.1.19.mirai2.jar[private]//cn.hutool.poi.excel.WorkbookUtil.createBook(WorkbookUtil.java:146)
... 32 more
改良了一下
try {
org.apache.poi.ss.usermodel.WorkbookFactory.create(true).close()
} catch (_: Exception) {
jvmPluginClasspath.downloadAndAddToPath(
jvmPluginClasspath.pluginIndependentLibrariesClassLoader,
listOf("org.apache.poi:poi-ooxml:5.3.0")
)
org.apache.poi.ss.usermodel.WorkbookFactory.addProvider(
org.apache.poi.xssf.usermodel.XSSFWorkbookFactory()
)
org.apache.poi.ss.usermodel.WorkbookFactory.create(true).close()
}
版本:v1.4.3 当这两个插件一起使用的时候,貌似是因为你强制指定poi的读取是
poi
,而不是poi-ooxml
,导致我插件无法读取xlsx。 经测试: 将你插件的build.gradle.kts即可正常运行,希望你能关注一下,或者给我一个解决方案。