我想在我自己的 Android 应用程序中查看 Excel 文件。
目前,使用我的应用程序我可以看到所有谷歌文档。但是在单击任何一个文档(例如 Excel 文件“myDemo.xls”)后,我想在我自己的应用程序中打开它(用于查看目的)。
我读过关于jxl http://www.vogella.com/tutorials/JavaExcel/article.html但问题是它解析 xls 文件并且该文件应该存储在 SD 卡中。
就我而言,它存储在谷歌驱动器中。 (不在 SD 卡上)
Here https://stackoverflow.com/questions/7170180/viewing-excel-files-in-my-android-app是类似的问题。
有没有其他方法可以通过任何其他 API 查看 xls 文件。
任何帮助将不胜感激。
Thanks
我已经用过WebView http://developer.android.com/reference/android/webkit/WebView.html为了达成这个。
但问题是,通过使用 webview 我无法更新谷歌文档。
我希望用户通过 webview 使用我的应用程序更新谷歌文档。
下面是我迄今为止尝试过的代码,
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]'");
}
}
}
活动_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>
是否可以在 WebView 中编辑 google 文档,或者编辑文档需要 Google Drive API?
我真的很困惑。请帮忙。