我尝试将.jpg文件上传到Dart中的Google云端硬盘:
Sub FindTableno()
Dim oTbl As Table
Dim oRow As Row
Dim oCell As Cell
Dim tblno As Integer
' Create a "FileDialog" object as a File Picker dialog box.
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim sfileName As String
With fd
.AllowMultiSelect = False
.Filters.Clear
.Title = "Select a PDF File"
.Filters.Add "All PDF Documents", "*.pdf?", 1
If .Show = True Then
sfileName = Dir(.SelectedItems(1)) ' Get the file.
End If
End With
Application.ScreenUpdating = True
Application.DisplayAlerts = True
If Trim(sfileName) <> "" Then
Dim objWord As Object ' Create a Word object.
Set objWord = CreateObject("Word.Application")
objWord.Visible = True ' Do not show the file.
' Create a Document object and open the Word file.
Dim objDoc As Word.Document
'Set objDoc = objWord.Documents.Open(Filename:=fd.InitialFileName & sfileName, Format:="PDF Files", ConfirmConversions:=False)
Set objDoc = objWord.Documents.Open(Filename:=fd.InitialFileName & sfileName, Format:="PDF Files", ConfirmConversions:=False)
' Search within tables in selected PDF file
If objDoc.Tables.count > 0 Then
tblno = 1
For Each oTbl In objDoc.Tables
For Each oRow In oTbl.Rows
For Each oCell In oRow.Cells
pos = InStr(oCell.Range.Text, "Nutrition Information ")
If pos <> 0 Then
GoTo line1
End If
'Else
'End If
Next
Next
tblno = tblno + 1
Next
End If
MsgBox ("Not Found, Total Tables Searched:" & objDoc.Tables.count)
'MsgBox (oCell.Range.Text)
End If
line1:
MsgBox (tblno)
End Sub
我收到状态码错误的请求:400 我看到了关于相同问题的帖子: Dart: http post upload to google Drive
我想念什么? 谢谢
答案 0 :(得分:0)
也许您可以使用googleapis
软件包。使用起来可能更简单。
在您的pubspec.yaml
dependencies:
googleapis:
googleapis_auth:
并使用googleapis
库:
import 'package:googleapis/drive/v3.dart';
import 'package:googleapis_auth/auth_io.dart';
import 'dart:io' as io;
main() async {
AuthClient client = await clientViaServiceAccount(
ServiceAccountCredentials.fromJson({/* here the credentials */}),
['https://www.googleapis.com/auth/drive']);
var driveApi = DriveApi(client);
var fileToUpload = io.File('my_file.png');
await driveApi.files.create(File()..name = 'my_file.png',
uploadMedia: Media(fileToUpload.openRead(), fileToUpload.lengthSync()));
}