在flutter中集成Excel导入和导出

flutter中集成Excel导入和导出功能

1、需要的依赖

在pubspec.yaml

  #excel导出
  syncfusion_flutter_xlsio: ^24.1.45
  open_file: ^3.0.1
  #导入excel
  flutter_excel: ^1.0.1
  #选择文件的依赖
  file_picker: ^6.1.1

(1)依赖说明

在测试时,我们在使用导出发现只有syncfusion_flutter_xlsio没问题,其他的或多或少会出现问题

在测试时,我们开发导出Excel时,发现只有syncfusion_flutter_xlsio可以使用,其他的库会出现一些Duplicate class错误如下:

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class kotlin.collections.jdk8.CollectionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.internal.jdk7.JDK7PlatformImplementations$ReflectSdkVersion found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.internal.jdk8.JDK8PlatformImplementations found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.io.path.DirectoryEntriesReader found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.ExperimentalPathApi found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.FileVisitorBuilder found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.FileVisitorBuilderImpl found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.FileVisitorImpl found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.LinkFollowing found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathNode found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathRelativizer found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathTreeWalk found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathTreeWalk$bfsIterator$1 found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathTreeWalk$dfsIterator$1 found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathTreeWalkKt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathWalkOption found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathsKt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathsKt__PathReadWriteKt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.io.path.PathsKt__PathUtilsKt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.jdk7.AutoCloseableKt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk7-1.7.22 (org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.22)
     Duplicate class kotlin.random.jdk8.PlatformThreadLocalRandom found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.streams.jdk8.StreamsKt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$1 found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$2 found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$3 found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.streams.jdk8.StreamsKt$asSequence$$inlined$Sequence$4 found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.text.jdk8.RegexExtensionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)
     Duplicate class kotlin.time.jdk8.DurationConversionsJDK8Kt found in modules jetified-kotlin-stdlib-1.8.22 (org.jetbrains.kotlin:kotlin-stdlib:1.8.22) and jetified-kotlin-stdlib-jdk8-1.5.30 (org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30)

但是使用该库的时候还是会出现一个问题,如下:

workbook.dispose();

就是在释放workbook的时候会出现报错,报错如下

Unsupported operation: Cannot clear an unmodifiable list

介于篇幅的圆心,咱们现阶段先把这句话注释掉,表面上解决该问题,等再来一篇文章分析这个问题和解决这个问题。

因为这个库只有导出功能,没有导入功能所以我们有引入了另一个导入excel的库flutter_excel,这个库有个要求就是导入的excel的后缀必须时xsls的,为了打开本地的文件目录我们还需要一个库file_picker

打开手机的文件权限

在flutter中集成Excel导入和导出_第1张图片

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

存储的读写权限打开
示例代码摘抄库中相应的示例代码即可

你可能感兴趣的:(flutter,flutter,excel,javascript)