gpt4 book ai didi

Android 和 JXL : ArrayIndexOutOfBoundException when create WritableWorkbook

转载 作者:太空宇宙 更新时间:2023-11-03 12:59:00 24 4
gpt4 key购买 nike

我正在尝试使用 JXL 从我的 Android 设备修改一个 xls 文件。第一步,如果我已经很好地理解的话,就是复制工作簿。这是我在写入时抛出异常的代码:

java.io.File licencesFile = new java.io.File(LicencesService.getPath(mCtx) + "/" +   pFileName);
java.io.File licencesFiletmp = new java.io.File(LicencesService.getPath(mCtx) + "/" + pFileName + ".tmp");
is = new FileInputStream(licencesFiletmp);
os = new FileOutputStream(licencesFile);

Workbook workbookTmp = Workbook.getWorkbook(is);
WritableWorkbook workbookFinal = Workbook.createWorkbook(os, workbookTmp);

//TODO code will come here when it'll work.

workbookFinal.write(); // <= Here is thrown an Exception
workbookFinal.close();

我没有找到任何解决方案...有什么想法吗?

非常感谢

堆栈:

java.lang.ArrayIndexOutOfBoundsException: src.length=166 srcPos=0 dst.length=112 dstPos=0 length=166
at java.lang.System.arraycopy(Native Method)
at jxl.biff.StringHelper.getBytes(StringHelper.java:127)
at jxl.write.biff.WriteAccessRecord.<init>(WriteAccessRecord.java:59)
at jxl.write.biff.WritableWorkbookImpl.write(WritableWorkbookImpl.java:726)
at fr.xxx.xxx.tasks.DriveUpdaterAsyncTask.updateXls(DriveUpdaterAsyncTask.java:170)
at fr.xxx.xxx.tasks.DriveUpdaterAsyncTask.doInBackground(DriveUpdaterAsyncTask.java:71)
at fr.xxx.xxx.tasks.DriveUpdaterAsyncTask.doInBackground(DriveUpdaterAsyncTask.java:1)
...etc.

最佳答案

您需要指定写访问权限,如下所示:

WorkbookSettings settings = new WorkbookSettings();
settings.setWriteAccess("something");
WritableWorkbook workbook = Workbook.createWorkbook(out, Workbook.getWorkbook(getClass().getResourceAsStream("report.xls")),settings);

关于Android 和 JXL : ArrayIndexOutOfBoundException when create WritableWorkbook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14455540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com