私はC#で生成できる2000語のドキュメントを持っていますが、それらをネイティブのGoogleドキュメント形式でGoogleドキュメントにアップロードする必要があります。ワードドキュメントからネイティブgoogleドキュメントへの変換
私はThis guideを見て変換しようとしましたが、コードは最後の2行目で失敗します。
(以下マイコード)
function myFunction() {
var folder = DriveApp.getFoldersByName("test").next();
var contents = folder.getFiles();
while (contents.hasNext()){
var file = contents.next();
var fileName = file.getName();
var officeFile = DriveApp.getFilesByName(fileName).next();
// Use the Advanced Drive API to upload the Excel file to Drive
// convert = true will convert the file to the corresponding Google Docs format
var uploadFile = JSON.parse(UrlFetchApp.fetch(
"https://www.googleapis.com/upload/drive/v2/files?uploadType=media&convert=true",
{
method: "POST",
contentType: officeFile.getMimeType(),
payload: officeFile.getBlob().getBytes(),
headers: {
"Authorization" : "Bearer " + ScriptApp.getOAuthToken()
},
muteHttpExceptions: true
}
).getContentText());
// Remove the file extension from the original file name
var fileName2 = officeFile.getName();
fileName2 = fileName2.substr(0, fileName2.lastIndexOf("."));
// Update the name of the Google Sheet created from the Excel sheet
DriveApp.getFileById(uploadFile.getID()).setName(fileName2); // FAILS HERE
//Logger.log(uploadFile.alternateLink);
}}
はTypeError:オブジェクトの[オブジェクトのオブジェクト]関数のgetIdを見つけることができません。 (行33、ファイル "コード")
これはどのような種類のエラーであるかを理解していますが、解決方法は必ずしもわかりません。
可能性があり、IdはuploadFile.id' 'として得られる - それは財産ですアップロードAPIによって返されるオブジェクトの – FTP
@ azq私はそれを試みたが、同じエラーが発生していた。私はもう一度やり直します。 –
オブジェクトuploadFileをログに記録して、どのプロパティがあるかを確認してください。 'Logger.log(JSON.stringify(uploadFile))'などです。 – FTP