首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Apache poi在android studio中使用xlsx文件时出错

使用Apache poi在android studio中使用xlsx文件时出错
EN

Stack Overflow用户
提问于 2022-02-02 12:19:01
回答 1查看 651关注 0票数 1

用什么来连接这个错误:org.apache.poi.ooxml.POIXMLException: error: The 'namespace-prefix' feature is not supported while the 'namespaces' feature is enabled.

我只是想弄清楚如何处理Excel文件,而这个错误让我很难理解。在我的Excel工作表中,我有一行和两列,在第一列--一些数字,在第二列--一些文本。

下面是我的MainActivity和实现代码。

MainActivity:

代码语言:javascript
复制
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;
        }
    }
}

执行情况:

代码语言:javascript
复制
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'
EN

回答 1

Stack Overflow用户

发布于 2022-07-29 22:00:24

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70955510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档