Viewing Excel files in my Android App through API

为君一笑 提交于 2020-01-02 07:27:11

问题


I want to view excel files in my own Android App.

Currently, using my App I can see all google docs. But after clicking on any one doc (for e.g Excel file 'myDemo.xls') , I want to open it in my own app (For Viewing purpose).

I have read about jxl but the problem with this is that it parses the xls file & the file should be stored in the SD Card.

In my case it is stored in the google drive. (not on SD card)

Here is similar question.

Is there any other way to view xls file through any other API.

Any help will be appreciated.

Thanks

I have used the WebView to achieve this.

But the problem is , by using webview I am not able to update the google docs.

I want user to update the google docs using my App through webview.

Below is my code that i've tried up till now,

MainActivity.java

public class MainActivity extends ActionBarActivity {

WebView wbView1;

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wbView1=(WebView)findViewById(R.id.webView1);
    wbView1.getSettings().setLoadsImagesAutomatically(true);
    wbView1.getSettings().setJavaScriptEnabled(true);
    wbView1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    wbView1.getSettings().setBuiltInZoomControls(true);
    wbView1.getSettings().setSupportZoom(true);
    wbView1.getSettings().setAllowContentAccess(true);
    wbView1.setWebViewClient(new MyBrowser());

    }

// Button on clicking on which I am loading google docs url in WebView.
public void onButtonClick(View v) {
    wbView1.loadUrl("https://docs.google.com/spreadsheets/d/15L4VenowOI0WPO52ASSjRgf90LcNxuJg8VF87_DtTp8/edit#gid=1311977634");

    return;
}


public class MyBrowser extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
       view.loadUrl(url);
       return true;
    }
    @Override
    public void onPageFinished(WebView view, String url) 
    {       
        view.loadUrl("javascript:document.forms[0].q.value='[android]'"); 
    }

 }

}

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.webviewdemo.MainActivity"
tools:ignore="MergeRootFrame" >

<WebView
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight=".4" 
    android:clickable="true"/>

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:onClick="onButtonClick"
    android:text="Button" />

</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.webviewdemo"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.webviewdemo.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

</manifest>

Can the google docs be edited inside WebView or Google Drive API is required for editing the docs?

I am really confused . Pls help.

来源:https://stackoverflow.com/questions/25526058/viewing-excel-files-in-my-android-app-through-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!