Android development data visualization – import data into Excel

Now it's 2021-03-12 00:: 39

A small part of the software has just been completed. Now the problems are summarized as follows:

website: https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl/2.6.12

Add the jar package to the project library

Then you need to configure the permission information to access the SD card in the manifest file

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

android:requestLegacyExternalStorage="true"

这里我出现了一个问题
这个版本的jxl只可以支持解析后缀名为:.xls的文件,而且有一点要特别注意,文件格式的修改最好通过文件另存为的方式修改
而不要直接在文件名上修改后缀名

这样看起来是对的,其实文件内部结构已经被打乱。那么在调用方法

in=new File(fileName);
Workbook workbook = Workbook.getWorkbook(in);  的时候就会出现文件解析异常,这个错误不会在控制台输出,是很隐蔽的错误

二、软件错误调试

当出现那种运行不报错,数据没有NULL异常的情况时,
可以使用一条语句进行分析,
使用Log.v()方法在控制台输出一句话。
这样就可以知道程序究竟在运行到哪一步出现了问题,导致结果

不是自己想要的。

三、清单文件
清单文件尽量少乱改动,注释也尽量少加,因为一旦出现哪个地方多了个什么符号是很难发现的,而且软件不会飘红报错。

四、获取权限可以有代码来体现
  前提是已经导入jar包并且在清单文件完成引用注册

Because what I want to get is the storage location of my mobile phone, it may not be as clear as the computer. My mobile phone is glory.

First of all, let's be clear that

File file =
new File(Environment.getExternalStoragePublicDirectory(Environment.
DIRECTORY_DOWNLOADS),"success_0.xls");//参数2是文件名称

Several methods to obtain the path are given below

Tips: generally, the SD card path is / storage / emulated / 0

① Get / storage / emulated / 0

② Get / storage / emulated / 0 (similar to the above)

③ Get the specified directory of the mobile phone (also the one I use)

The above code comes from script home https://www.jb51.net/article/144850.htm

Tomorrow the birds will sing.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>