Function realization of Android operating excel file

The open source library JXL is mainly used when operating Excel files to export reports in Android. It was first used in Java, but it can also be used in Android. Similarly, POI can only be used in Java, not Android, because it has many dependent libraries.

To use JXL, you need to import the jxl.jar package into the Android project. JXL can complete the basic reading and writing operations of Excel. The supported and unsupported conditions are as follows:

1. JXL only supports Excel 2003 format, not Excel 2007 format. That is, xls files are supported, but xlsx files are not supported.

2. JXL does not support modifying Excel files directly, but it can be modified indirectly by copying a new file and overwriting the original file.

3. JXL can only recognize pictures in PNG format, not pictures in other formats.

As can be seen above, JXL does not support Excel 2007, which is very bad, especially when Excel 2007 has become the mainstream format of Excel. However, there is still a temporary way for Android to read the 2007 format. If we carefully analyze the file format of xlsx, we will find that xlsx file is actually a compressed package. There are various files in the compressed package, and the data is generally placed in "XL / sharedstrings. XML" and "XL / worksheets / Sheet1. XML". Therefore, when we judge that the excel file is in 2007 format, we can unzip it, extract sharedstrings.xml and sheet1.xml from it, and then use the XML parsing tool to parse the specific data.

The following is an example of Excel file reading and writing code, which supports reading and writing in 2003 format and reading in 2007 format:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

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