Jeg prøver å lese excel-fil til android auto, men det viser ENOENT (Ingen slik fil eller katalog)

stemmer
0

Jeg prøver å lese Excel-fil fra SD-kortet eller telefon Lagring i android programmatisk, men det viser fil ikke funnet noe unntak. kan du hjelpe meg. Her er hva jeg har prøvd.



    package com.example.readexcel;
    import androidx.appcompat.app.AppCompatActivity;
    import android.app.Activity;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;

    import org.apache.poi.hssf.usermodel.HSSFDateUtil;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.CellValue;
    import org.apache.poi.ss.usermodel.FormulaEvaluator;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.xssf.usermodel.XSSFSheet;
    import org.apache.poi.xssf.usermodel.XSSFWorkbook;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.text.SimpleDateFormat;
    public class ExcelTryTwo extends Activity {
        EditText output;
        Button btn_p;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_excel_try_two);
            output = findViewById(R.id.textOut);

            btn_p = findViewById(R.id.btn_p);

            btn_p.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType(application/vnd.openxmlformats-officedocument.spreadsheetml.sheet);
                    startActivityForResult(intent, 7);
                }
            });
        }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub

            // super.onActivityResult(requestCode, resultCode, data);
            switch (requestCode) {

                case 7:

                    if (resultCode == RESULT_OK) {
                        Uri PathHolder = data.getData();
                        //String PathHolder = data.getData().getPath();

                        //Toast.makeText(ExcelTryTwo.this, PathHolder , Toast.LENGTH_LONG).show();

                        onReadClick(PathHolder);

                    }
                    break;

            }
        }

        public void onReadClick(Uri filepath) {
            printlnToUser(reading XLSX file from resources);

            File inputfile = new File(String.valueOf(filepath));/*line to be commented*/

            //below line should uncomment
            //InputStream stream = getResources().openRawResource(R.raw.test);

            try {
                InputStream stream = getContentResolver().openInputStream(Uri.fromFile(inputfile));
                XSSFWorkbook workbook = new XSSFWorkbook(stream);
    /*
                InputStream stream=new FileInputStream(inputfile);*//*line to be commented*//*

               XSSFWorkbook workbook = new XSSFWorkbook(stream);*/

                XSSFSheet sheet = workbook.getSheetAt(0);
                int rowsCount = sheet.getPhysicalNumberOfRows();
                FormulaEvaluator formulaEvaluator = workbook.getCreationHelper().createFormulaEvaluator();
                for (int r = 0; r  8000) {
                CharSequence fullOutput = output.getText();
                fullOutput = fullOutput.subSequence(5000, fullOutput.length());
                output.setText(fullOutput);
                output.setSelection(fullOutput.length());
            }
            output.append(string + \n);
        }
    }

generelt det jeg ønsker er å lese Excel-fil fra telefonen lagring eller SD-kort og vise det til android auto. kan du hjelpe meg med et utvalg av kode, jeg er en beginer. her er feilen vises: java.io.FileNotFoundException: / innhold: / com.android.externalstorage.documents / dokument / primær% 3AmyExcelfile.xlsx: open failed: ENOENT (Ingen slik fil eller katalog) noen som vet om lesing excel fil, kan du hjelpe meg. Jeg er i behov av det som jeg gjør min graduate prosjekt ..

men excel-filen har innholdet.

Publisert på 19/03/2020 klokken 21:51
kilden bruker
På andre språk...                            

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more