Apache POI - .xlsx中的xml:space =“preserve”正在崩溃GUI,格式错误的单元格

时间:2015-10-20 19:53:57

标签: java android xml excel apache-poi

我有以下文件:supl_zak.xlsx。我对G6的输出是:

10-20 12:55:38.521 30921-30921/tona_kriz.kriziksupl I/System.out: Row: 8 - Column: 7 =  

(是的,什么都没有),GUI将消失(崩溃?)但整个应用程序仍在运行。它读取的所有其他单行字符串都不是以空格结尾。

我探索了.xlsx文件并找到了该单元格的字符串:

<t xml:space="preserve">Tv/Jk=0 ------- </t>

如何使其不会崩溃并使用this?

之类的输出

(是的,我使用Gimp使它看起来像这样:P,但透明度失败.PS:文字颜色没关系,我使用了错误的颜色。)

我的来源是:

MainActivity

import android.app.Activity;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class MainActivity extends Activity {

    int wbs;
    XSSFWorkbook wb = null;
    XSSFSheet sheet = null;
    XSSFCell cell;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        //1. Open the file
        new Thread(loadWorkbook).start();
    }


    public Runnable loadWorkbook = new Runnable() {
        @Override
        public void run() {
            try {
                AssetManager assManager = getApplicationContext().getAssets();
                InputStream is = null;
                try {
                    is = assManager.open("supl_zak.xlsx");
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                InputStream caInput = new BufferedInputStream(is);
                wb = new XSSFWorkbook(caInput);
                wbs = wb.getNumberOfSheets();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            runOnUiThread(new Runnable() {
                public void run() {
                    workWithWB();
                }
            });
        }


    };

    void workWithWB() {
        //3. Get each cell by row & column number
        Toast.makeText(getApplicationContext(), "number of sheets: " + wbs, Toast.LENGTH_SHORT).show();
        sheet = wb.getSheetAt(0);
        cell = sheet.getRow(7).getCell(5);
        String stringVal = cell.getStringCellValue();
        TextView test = (TextView)findViewById(R.id.textView);
        test.setText(stringVal);
        try {
            wb.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

文库 https://github.com/andruhon/AndroidReadXLSX

的build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    dexOptions {
        preDexLibraries false
        //incremental true
        javaMaxHeapSize "4g"
    }

    afterEvaluate {
        tasks.matching {
            it.name.startsWith('dex')
        }.each { dx ->
            if (dx.additionalParameters == null) {
                dx.additionalParameters = ['--multi-dex']
            } else {
                dx.additionalParameters += '--multi-dex'
           }
        }
    }


    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
    }

    defaultConfig {
        applicationId "awesomeapp.whichreadsexcell"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "0.0.0.0.0.1 closed pre alpha"

        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    project.tasks.withType(com.android.build.gradle.tasks.Dex) {
        additionalParameters=['--core-library'] // --core-library option needed for now, will fix it soon
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:multidex:1.0.1'
    compile files('libs/poi-3.12-android.jar')
    compile files('libs/poi-ooxml-schemas-3.12-20150511.jar')
}

对我来说有什么解决方案吗?我可以录制(bandicam,fraps,..)模拟器和logcat看起来如何?

logcat 已添加

10-22 20:14:26.435 31444-31444 I/art: Late-enabling -Xcheck:jni
10-22 20:14:26.525 31444-31444 W/ActivityThread: Application tona_kriz.kriziksupl can be debugged on port 8100...
10-22 20:14:26.555 31444-31444 I/MultiDex: VM with version 2.1.0 has multidex support
10-22 20:14:26.555 31444-31444 I/MultiDex: install
10-22 20:14:26.555 31444-31444 I/MultiDex: VM has multidex support, MultiDex support library is disabled.
10-22 20:14:26.555 31444-31444 V/Monotype: SetAppTypeFace- try to flip, app = tona_kriz.kriziksupl
10-22 20:14:26.555 31444-31444 V/Monotype:     Typeface getFontPathFlipFont - systemFont = default
10-22 20:14:26.565 31444-31444 V/Monotype: SetAppTypeFace- try to flip, app = tona_kriz.kriziksupl
10-22 20:14:26.565 31444-31444 V/Monotype:     Typeface getFontPathFlipFont - systemFont = default
10-22 20:14:26.575 31444-31444 I/System.out: Sending WAIT chunk

0 个答案:

没有答案