我正在尝试使用Google Drive API读取.xlsx文件,但是在我成功打开文件并决定阅读内容后,它会显示垃圾值。我能够读取元数据并验证是否已打开正确的文件。这是成功读取文件后调用的内容。它适用于.txt文件,但我使用任何.word,.xlsx文件接收垃圾值。
private ResultCallback<DriveApi.DriveContentsResult> driveContentsCallback =
new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (!result.getStatus().isSuccess()) {
Log.i(TAG, "Error while opening the file contents");
return;
}
Log.i(TAG, "File contents opened");
mProgressBar.setProgress(100);
DriveContents contents = result.getDriveContents();
BufferedReader reader = new BufferedReader(new InputStreamReader(contents.getInputStream()));
StringBuilder builder = new StringBuilder();
String line;
try {
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} catch (Exception e) {
}
String contentsAsString = builder.toString();
mTextViewContent.setText(contentsAsString);
}
};
答案 0 :(得分:0)
使用Google Drive API,downloading Google documents是通过将您的文件导出为受支持的MIME类型来完成的。
但是,如果您使用的是Google Drive Android API,请opening the file contents
为了能够阅读文件,您必须首先以
DriveContents
或DriveFile.MODE_READ_ONLY
模式打开DriveFile.MODE_READ_WRITE
资源,具体取决于您是否愿意使用{{ 1}}或InputStream
类。
您可能需要查看给定的文档以获取更详细的信息以及GitHub post。