2017-10-16 13 views
0

새로운 Google 문서 도구로 새로운 문서를 만들고 싶습니다. 기본적으로 나는 유닉스 명령에 해당하고 싶은 :텍스트 docs 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 's] (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()를 사용할 수 있습니다 당신 그런 다음 다른 문서에 삽입 할 수 있습니다. 이 접근 방식은 서식을 유지합니다.