使用 Apache poi 的 android studio 中的 xlsx 文件出错

Error with xlsx file in android studio using Apache poi

提问人:aDragon 提问时间:2/2/2022 最后编辑:RaBaKa 78aDragon 更新时间:9/19/2023 访问量:1272

问:

该错误可以与什么联系起来:?org.apache.poi.ooxml.POIXMLException: error: The 'namespace-prefix' feature is not supported while the 'namespaces' feature is enabled.

我只是想了解如何使用 Excel 文件,而这个错误让我非常困惑。 在我的 Excel 工作表中,我有一行和 2 列,第一列 - 一些数字,第二列 - 一些文本。

我的 MainActivity 和实现的代码如下。

主活动:

public class MainActivity extends AppCompatActivity{
    TextView TextView;
    private static final String TAG = "myLogs";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView = findViewById(R.id.textView3);
        TextView.setText("SomeText");

        try {

            AssetManager am=getAssets();
            InputStream is=am.open("MyTest.xlsx");
            XSSFWorkbook book = new XSSFWorkbook(is);
            XSSFSheet mySheet = book.getSheet("0");
            XSSFRow row = mySheet.getRow(0);

            if(row.getCell(0).getCellType() == CellType.STRING){
                String name = row.getCell(0).getStringCellValue();
                Log.d(TAG,"/////////////////////////////////////////////////////////////////////////////////////name : " + name);
            }
            if(row.getCell(0).getCellType() == CellType.NUMERIC){
                double date = row.getCell(0).getNumericCellValue();
                Log.d(TAG,"/////////////////////////////////////////////////////////////////////////////////////date : : " + date);
            }

            book.close();
            TextView.setText("SomeText after all");

        } catch(Exception ex) {
            Log.d(TAG, "Loooooooooooooooooooooooooooooooooooooooooooooooooooooolg "+String.valueOf(ex));
            return;
        }
    }
}

实现的:

implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation files('libs\\commons-codec-1.15.jar')
implementation files('libs\\commons-compress-1.21.jar')
implementation files('libs\\commons-logging-1.2.jar')
implementation files('libs\\curvesapi-1.06.jar')
implementation files('libs\\poi-5.1.0.jar')
implementation files('libs\\poi-ooxml-5.1.0.jar')

implementation files('libs\\slf4j-api-1.7.32.jar')
implementation files('libs\\xmlbeans-5.0.2.jar')
implementation files('libs\\log4j-api-2.14.1.jar')
implementation files('libs\\commons-io-2.11.0.jar')
implementation files('libs\\commons-math3-3.6.1.jar')
implementation files('libs\\poi-ooxml-lite-5.1.0.jar')

testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Java Android 命名空间 apache-poi

评论

0赞 anestv 2/5/2022
这个问题有帮助吗?

答:

-2赞 Drex 7/30/2022 #1

下载并集成到您的项目 https://github.com/centic9/poi-on-android/releases

评论

1赞 jmoerdyk 7/30/2022
请用英文写下您的答案,因为 Stack Overflow 是一个纯英文网站
0赞 Saurav Singh 9/15/2023 #2

确保您使用的是模块级别 Gradle 中的最新版本。

dependencies {
  implementation 'org.apache.poi:poi:5.2.3'<br>
  implementation 'org.apache.poi:poi-ooxml:5.2.3'
}