user17792511
user17792511

Reputation:

Can't open .xlsx file from aspose cells if it wasn't created using aspose cells

So I'm working on an app for android and I've gotten it to work as long as it's been created using aspose cells. Here is my code:

class Home: Fragment(R.layout.fragment_home) {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view: View = inflater.inflate(R.layout.fragment_home, container, false)

        val load = view.findViewById<Button>(R.id.button3)
        val new = view.findViewById<Button>(R.id.button4)
        val editText = view.findViewById<EditText>(R.id.editTextTextPersonName)

        new.setOnClickListener(View.OnClickListener {
            Excel.name = "${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx"
            Excel.workbook = Workbook()
            Excel.workbook!!.save(Excel.name)
            println("Created: ${Excel.workbook}")
        })

        load.setOnClickListener(View.OnClickListener {
            Excel.workbook = Workbook("${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx")
            Excel.name = "${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx"
            Excel.workbook!!.save("${Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS)}/${editText.text.toString()}.xlsx")
            println("Loaded: ${Excel.workbook}")
        })
        return view
    }
}

the problem is when I try to download a .xlsx file and load it, it gives me this error:

Caused by: java.io.FileNotFoundException: /storage/emulated/0/Download/ECR.xlsx: open failed: EACCES (Permission denied)

I'm not sure why this is happening. Any help would be awesome! Thanks!

EDIT: Here's my AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application
        android:allowBackup="true"
        android:dataExtractionRules="@xml/data_extraction_rules"
        android:fullBackupContent="@xml/backup_rules"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.FRCScout22"
        tools:targetApi="31">
        <activity
            android:name=".DropDownActivity"
            android:exported="false">
            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.app.lib_name"
                android:value="" />
        </activity>
    </application>

</manifest>

Upvotes: 0

Views: 299

Answers (0)

Related Questions