2017-10-16 1 views
0

新しく新しい文書に連結したいGoogle Docsがたくさんあります。基本的に私は、Unixコマンドと同等のものをやりたい:テキスト文書1,2,3を4に連結する必要があります。どのようにですか?

猫1.TXT 2.txt 3.txt>

4.txt私はからこれを行うための最善の方法を見つけ出すように見えることはできませんAppsスクリプトのドキュメント誰か知っているだろうか?

私は次のことを試してみました:

// ... code omitted 
var entries = []; 
while (files.hasNext()) { 
    var file = files.next(); 
    var name = file.getName(); 
    if (file.getOwner().getName() != 'My Name') continue 

    var re = /Pattern I am looking for - \d\d/g; 
    if (name.match(re) == null) continue; 

    entries.push({"Name" : name, "File" : file}); 
} 
entries.sort(function(a,b) { return a.Name.localeCompare(b.Name); }); 

// Open the Full.txt file and add each file into it in sequence. 
var fullDoc = DocumentApp.create('Full.txt'); 
entries.forEach(function(e) { 
    var contents = e.File.getAs('text/plain'); 
    // Haven't yet gotten to sticking contents into the target file 
    // because content retrieval itself fails with the message: 
    // "Converting from application/vnd.google-apps.document to text/plain 
    // is not supported. (line 51, file "DocMerge")" 
    return; 
    }); 

感謝。

-av

+0

あなたの検索/研究活動の詳細を追加してください。参照[ask]。 –

+0

私は[DocumentApp](https://developers.google.com/apps-script/reference/document/document-app)[Body Class](https://developers.google.com/apps-script/)を試してみます[https://developers.google.com/apps-script/reference/document/body#getText())を[DriveApp's](https:// developers)と一緒に使用してください。 google.com/apps-script/reference/drive/drive-app)ファイル[setContent()](https://developers.google.com/apps-script/reference/drive/file#setContent(String)) –

+0

ありがとうございますボディからファイルを取得する方法ではないようです。私が持っているのはFileオブジェクトのリストです。 –

答えて

0

DocumentAppを使用してファイルを開く必要があるため、ドキュメントの内容を取得できます。あなたが見ているように、プレーンテキストへの直接変換はサポートされていません(便利かもしれませんが)。

var source_doc = DocumentApp.openById(e.File.getId()); 
var contents = source_doc.getBody().getText(); 

は、あなたのユースケースに応じて、あなたはまた、ヘッダー/フッターのセクションを取得したいこと、そしてあなたものgetTextを(使用してスキップ)とbody要素のコピーを作成するためにBody.copy()を使用することができます他のドキュメントに挿入することができます。この方法は、書式設定を保持します。

関連する問題