Detailed explanation of reading Excel files in Android

Detailed explanation of reading Excel files in Android

Recently, there was a need to build data in the app. The new product threw me two excel tables (the formats of the two tables are not unified...), so I found a way to read excel table files in Android through Du Niang and other methods, and recorded it.

Gossip about the difference between workbook and worksheet in Excel:

The workbook contains worksheets. A workbook can be composed of one or more worksheets. A workbook is an excel table file.

All right, let's start reading the table file.

premise

First, let's assume that the name of the table file to be read is test.xls, which is located in the root directory of assets.

Required jar package

Here, in order to read the excel table file, we need to add a third-party jar package JXL.

There is something to note here: because there are many table file formats, the old version of JXL only supports Excel 2003. Therefore, if the obtained table file format is xlsm or xlsn, we must first save the file as XLS format.

Start reading

1. Initialization variables:

2. Read the table file built in the assets directory in the form of stream

3. Read the input stream of the previous step into a file for subsequent use

4. After obtaining the excel file object, you can use various methods provided in JXL package to operate the table file. JXL provides many methods. Here are some of the methods used in the project.

summary

If the table file is built in the assets directory, you can read it according to the above process. If it is on an SD card, the steps are basically the same. We first get our table file, and then get the workbook object and operate it.

Thank you for reading, hope to help you, thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>