2013-07-08 2 views
0

Google 스크립트를 통해 문서를 만들고 미리 지정된 공유 파일 폴더에 자동으로 넣어 다른 사람이 열 수 있도록 할 수있는 방법이 있습니까? 이 문서를 만들기 위해 양식 스프레드 시트의 결과를 사용하고 있지만 Google 스크립트의 한 측면에 문제가 있습니다.이메일 보내기를위한 Google 스크립트

답변

0

당신은 파일을 편집하기 위해 이메일 권한의 수신자를 제공 할 수 있습니다 :

file.addEditor(emailtogoto); 

을 ... 아니면 그냥 볼 다음 이름이 공유 폴더의 인 경우

file.addViewer(emailtogoto); 

'우리 파일 폴더'는 아마도 DocsList.getFolderById()을 의미하지는 않습니다.

var sharedFolder = DocsList.getFolder('OUR FILE FOLDER'); 

당신은 직접 구글 문서를 첨부 할 수 없습니다,하지만 당신은 PDF 버전을 첨부 할 수 있습니다 : 대신 DocsList.getFolder(path)를 사용한다.

var pdf = file.getAs("application/pdf"); 
MailApp.sendEmail(emailtogoto, 'Thank you for your using this form! Here is your file', file.getName()+'\n'+file.getUrl(), {attachments: pdf}); 
0

내가 DocumentAppDocsList 서비스에서 사용할 수있는 모든 기능을 보여주기 위해 얼마 전이 샘플 스크립트를 작성, 난 당신이

(코드에 주석을 참조)이 설명하는 유스 케이스에 필요한 모든 것을 포함하고 생각
function testDocCreate(){ 
    try{ 
    var folder = DocsList.getFolder("testFolder"); // check if shared folder already exist, if not just do it ! 
    }catch(err){ 
    folder = DocsList.createFolder("testFolder").addEditor('editorEmailAdress');// or addViewer ... 
    } 
    // now that our shared testfolder exists we van create files in it that will inherit all sharing properties 
    var fileId = DocumentApp.create('testFileName').getId();// create as a text document 
    var fileUrl = DocsList.getFileById(fileId).getUrl(); 
    var file = DocsList.getFileById(fileId); 

    file.addToFolder(folder); // share it by moving into the right folder 
    file.removeFromFolder(DocsList.getRootFolder());// remove the newly created file from your root folder so it won't appear twice 

    Logger.log(fileUrl); // send this url to your user and eventually add a pdf copy to your email like below 

    var pdf = DocsList.getFileById(fileId).getAs('application/pdf').getBytes(); // this is the pdf file 

    var attach_to_send = {fileName: 'testFileName.pdf',content:pdf, mimeType:'application/pdf'}; // create an attachment object 

    MailApp.sendEmail('editorEmailAdress', "here is the document I've shared with you (url & pdf copy)", 'Your doc available here : '+fileUrl, {attachments:[attach_to_send]}); 
}