Google Apps Scriptã§å·®ã蟌ã¿å°å·çãªäœããGASã
Google ããã¥ã¡ã³ãã¯ãæ£çŽãªæãä»ã®ã¯ãŒãããœããã«æ¯èŒãããšãããªãæ©èœçã«ã¯è²§åŒ±ã§ãããŸããã¹ãã¬ããã·ãŒããšæ¯èŒãããšãã¹ã¯ãªãããé£è§£ãªæ§é ã«ãªã£ãŠããããµã³ãã«ãå°ãªãã§ãããããªGoogleããã¥ã¡ã³ãã§ãããæšæºæèŒãããŠããªãæ©èœã§èŠæãé«ãã®ããå·®ã蟌ã¿å°å·ã§ããæšæºã§æèŒãããŠããŠãè¯ãã®ã«ãšæãã®ã§ããã
ããããGoogleããã¥ã¡ã³ãé¡ã¯å°å·ã«é¢ããã¡ãœããããªãã®ã§ãã¹ã¯ãªããããå°å·ã¯ã§ããŸããããã£ãŠãå°å·ã®äžæ©æåãŸã§ããªããšãåºæ¥ãªãã ãããïŒãŸããåæ§ã®ãã¯ããã¯ã䜿ã£ãŠããããŸã§ã¹ãã¬ããã·ãŒãã§ãã³ãã¬ãŒããäœããæžé¡ãäœã£ãŠããã®ããGoogleããã¥ã¡ã³ãã§åºæ¥ãªãã ãããïŒãšèããçµæããããã圢ã«ãªããŸãããä»åã¯ãã€ã¢ãã°ã§ã¯ãªãããµã€ãããŒã§å®è£ ããŠããŸãã
ã¡ãªã¿ã«æ¢ã«ã¢ããªã³åœ¢åŒã§ã¯ãDocumentMerge by PandaDocãšãããã®ããããŸããããè±èªUIãªäžã«ç»åé¡ãªã©ã¯ã©ãããã³ãã¬ãŒãããã³ããŒããŠãããªãã¿ãããªã®ã§ãè¥å¹²äžäŸ¿ã§ããäœããããŒã¿å ã§ããã¹ãã¬ããã·ãŒãã®ã·ãŒãã®æå®ãšã«ã©ã ã®æå®ãæè»ã§ãšãŠãè¯ãåºæ¥ãŠããã¢ããªã³ã§ãã
ç®æ¬¡
ä»åããããããã¡ã€ã«ç
- å·®ã蟌ã¿å°å·ãã¹ãããã¥ã¡ã³ã
- å·®ã蟌ã¿å°å·çšã¹ãã¬ããã·ãŒãããŒã¿
ãµã³ãã«ã³ãŒãã®Picker APIã¯å€ãã³ãŒããšãªã£ãŠããã®ã§ä»¥äžã®ãšã³ããªãŒã®ææ°ã®ã³ãŒãããæ¹é ãå ããŠäžããã
Pickerã§ãã¡ã€ã«ããã©ã«ããéžæããç»é¢ãè£ åãã
ãœãŒã¹ã³ãŒã
æ£çŽèšã£ãŠãçµæ§ãªéã®ã³ãŒãã«ãªã£ãŠããã®ã§ããããæé©åããªããšãããªããªãšæãã€ã€ãæãä»ããããã«ããã®ã§ãäž»èŠãªéšåã®ã³ãŒãã ããæ®ãã¯äžèšã®ãã¡ã€ã«ããã³ããŒããŠé€ããŠã¿ãŠäžããããªãããªãã¶ã€ã³ãšãŠãŒã¶ããªãã£ãã¡ããã£ãšèæ ®ããŠãã®ã§ãå®éã«ã¯ãã£ãšå°ãªãã³ãŒãã§æžãããšæããŸãã倧åç¡é§ã«ã¡ãœããåŒã³åºããŠãé¢ããããŸããã
GASåŽã³ãŒã
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
//眮æçšã³ã³ãœãŒã«ãsidebarã§è¡šç€ºãã function openSidebar() { var ui = DocumentApp.getUi(); var html = HtmlService.createHtmlOutputFromFile('index').setTitle('差蟌å°å·').setSandboxMode(HtmlService.SandboxMode.IFRAME); ui.showSidebar(html); } //差蟌ããŒã¿ãããã¥ã¡ã³ãã®ã«ãŒãœã«äœçœ®ã«æ¿å
¥ãã function insertPara(num){ var Properties = PropertiesService.getScriptProperties(); var spfile = Properties.getProperty("sheet"); var sheet = SpreadsheetApp.openById(spfile); var lastcolumn = sheet.getLastColumn(); var range = sheet.getActiveSheet().getRange(1,1,1,lastcolumn).getValues(); var temp = 1; //ã€ã³ãµãŒãããæååãååŸããŠãã var inserttext = range[0][num]; //documentæ
å ±ãååŸããŠãã var doc = DocumentApp.getActiveDocument(); var body = DocumentApp.getActiveDocument().getBody(); var ui = DocumentApp.getUi() //ã«ãŒãœã«ç¶æ
ãéžæç¶æ
ãã«ãã£ãŠãäœæ¥ãããã try{ var selection = doc.getSelection(); var selectedElements = selection.getSelectedElements(); //var selectedElement = selectedElements[0]; }catch(e){ temp = 0; } if(temp != 0){ ui.alert("éžæç¶æ
ã§ã¯ãæ¿å
¥ãåºæ¥ãŸãã"); } try{ //ã«ãŒãœã«ç¶æ
æã®äœæ¥ var body = doc.getCursor(); body.insertText("§" + inserttext + "§"); }catch(e){ ui.alert("éžæç¶æ
ã§ã¯ãæ¿å
¥ãåºæ¥ãŸãã"); } } //ãã³ãã¬ãŒããã¡ã€ã«ãæå®ã®ãã©ã«ãã«ã³ããŒãã function copyme(){ var Properties = PropertiesService.getScriptProperties(); var targetfolder = Properties.getProperty("folder"); docname = DocumentApp.getActiveDocument().getName() + "_" + getDate(); var docs = DocumentApp.getActiveDocument().getId(); var ui = DocumentApp.getUi(); if(targetfolder == undefined){ ui.alert("ãã©ã«ãæ ŒçŽå
ãæå®ãããŠããŸãããã"); } var folder = DriveApp.getFolderById(targetfolder); var file = DriveApp.getFileById(docs); var id = file.makeCopy(docname,folder).getId(); return id; } //çŸåšã®ãã³ãã¬å
容ãã¹ãã¬ããã·ãŒãã®æå®ã¬ã³ãŒãæ°åãããŒãžã³ããŒãã差蟌ããŒã¿ã眮ãæããã function copyDoc(id,data,datalength) { //ããŒãžè€è£œçšããŒã¿ãååŸ var sourceDoc = DocumentApp.openById(id).getBody(); var totalElements = sourceDoc.getNumChildren(); var copydocs = sourceDoc.copy(); //ããŒãžè€è£œãšçœ®æçšã®å€æ°ååŸ var Properties = PropertiesService.getScriptProperties(); var spfile = Properties.getProperty("sheet"); var sheet = SpreadsheetApp.openById(spfile); var lastcolumn = sheet.getLastColumn(); var range = sheet.getActiveSheet().getRange(1,1,1,lastcolumn).getValues(); var ui = DocumentApp.getUi(); var targetdocs = sourceDoc; //ãšããããæ¹è¡ã³ãŒããå
¥ããŠãã targetdocs.appendPageBreak(); for(var z = 1;z<datalength;z++){ //ããŒãžè€è£œã«ãŒãã³ if(z != 1){ for( var j = 0; j < totalElements; ++j ) { var element = copydocs.getChild(j).copy(); var type = element.getType(); if( type == "PARAGRAPH" ){ targetdocs.appendParagraph(element); } else if( type == "TABLE"){ targetdocs.appendTable(element); } else if( type == "LIST_ITEM"){ targetdocs.appendListItem(element); } } targetdocs.appendPageBreak(); } //ã¯ãŒã眮æã«ãŒãã³ for(var p = 0;p<lastcolumn;p++){ var choicecol =ãString("§" + range[0][p] + "§"); var tempdata = data[z][p]; targetdocs.replaceText(choicecol, tempdata); } } } |
HTMLåŽã³ãŒã
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css"> <link rel="stylesheet" type="text/css" href="https://officeforest.org/wp/library/cssman/insert.css"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script> google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(test); function test(){ google.script.run.withSuccessHandler(onSuccess).waitid(); google.script.run.withSuccessHandler(onSuccess2).waitid2(); google.script.run.withSuccessHandler(onSuccess3).columnget(); } $(function(){ $('#btnOK').click(function(){ google.script.run.fileman(); }); }); $(function(){ $('#btnOK2').click(function(){ google.script.run.folderman(); }); }); $(function(){ $('#btnOK3').click(function(){ google.script.run.insertdoc(); }); }); function onSuccess(data){ document.getElementById("test").innerHTML = "ããŒã¿ãã¡ã€ã«ïŒ" + data; } function onSuccess2(data){ document.getElementById("test2").innerHTML = "æ ŒçŽå
ïŒ" + data; } function onSuccess3(data){ var tempstr = JSON.parse(data); document.getElementById("htmler").innerHTML = tempstr; } function clickfunc(obj) { var num = Number(obj.title); google.script.run.insertPara(num); return false; } </script> <style> div.wasabi{ padding:3px 5px; border-color:#0B0099; border-width:0 0 1px 7px; border-style:solid; background:#F8F8F8; } div.kousin { overflow-y: auto; width:95%; height:200px; padding:3px; border:1px solid #000; color:#000000; background-color:#ffffff; line-height:1.0em; margin-left: auto; margin-right: auto; } div.boxContainer { overflow: hidden; width:100%; } .box { float: left; width: 100%; margin-right:5px; } #linkArea{ position: relative; width: 100%; height: 100%; border-color: #999999; border-style: none; } #linkArea a{ display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; } </style> <div class="wasabi">䜿çšãã差蟌ããŒã¿</div> <p><button id="btnOK" class="action">ããŒã¿éžæ</button></p> <div id="test"></div><p> <div class="wasabi">ãã¡ã€ã«æ ŒçŽå Žæ</div><p> <p><button id="btnOK2" class="action">ãã©ã«ãéžæ</button></p> <div id="test2"></div><p> <div class="wasabi">差蟌æååã®æ¿å
¥</div><p> <div class="kousin"><p><div id="htmler"></div></div><p> <div class="wasabi">差蟌ã®å®è¡</div><p> <p><button id="btnOK3" class="create">RUN</button></p> |
å®è¡ãšçµæ
äœ¿ãæ¹
ãã®ã¹ã¯ãªããã¯å°å·ã¯ã§ããŸããããå°å·äžæ©æåã®æžé¡ãäœãçºã®ãã®ã§ã(Cloud Printãããã°ãå°å·ãŸã§å®è¡ã§ããŸã)ããã£ãŠããŠãŒã¶ãã¹ã¯ãªããã§æžé¡ãçæããããããããšã¯å°å·ã ãã§ãã差蟌å°å·ãè¡ãçºã«ã¯ã以äžã®æé ãèžã¿ãŸãã
- ãµã³ãã«ããã¥ã¡ã³ãããã³ãã¬ãŒããšãªããŸããã¡ãã¥ãŒãããâ¶å·®èŸŒå°å·ãããã差蟌ã¡ãã¥ãŒããå®è¡ãããµã€ãããŒã衚瀺ããŸãã
- 䜿çšãã差蟌çšã®ããŒã¿ïŒã¹ãã¬ããã·ãŒãïŒãæå®ããŸããGoogle Pickerãèµ·åããã®ã§ã䜿çšããã¹ãã¬ããã·ãŒããæå®ããŸãã
- 次ã«çæããããã¥ã¡ã³ããæ ŒçŽãããã©ã€ãã®å Žæãæå®ããŸããåããGoogle Pickerãèµ·åããã®ã§ããã©ã«ããæå®ããŸãã
- 差蟌æååã®æ¿å ¥ã¯2.ã§æå®ããã¹ãã¬ããã·ãŒãïŒãŸã ã·ãŒãåã®æå®ã¯åºæ¥ãŸããïŒã®ïŒæç®ã®ã«ã©ã ãèªåã§èªã¿åã£ãŠè¡šç€ºããŠãããŸãããã£ãŠãã«ã©ã ãïŒè¡ã«ããã ãšãããªã«ã·ãæŽåœ¢ããããšèªããªããªããŸãã
- å·®ã蟌ã¿ããäœçœ®ã«ã«ãŒãœã«ãç§»åãã4.ã§è¡šç€ºãããã«ã©ã ãªã¹ããã¯ãªãã¯ãããšããã®å Žæã«ç¹å¥ãªæååãæ¿å ¥ãããŸããããã¯åé€ãããå€åœ¢ãããŠã¯ãããŸããã
- æåŸã«ãRUNãã¿ã³ãæŒããšããã³ãã¬ãŒããè€è£œãã¹ãã¬ããã·ãŒãããŒã¿ã®ã¬ã³ãŒãæ°åããŒãžãäœããæååã眮æããŸãã
- æåŸã«çæããããã¥ã¡ã³ããžã®ãªã³ã¯ã衚瀺ããããã€ã¢ãã°ãåºãŠããã®ã§ããªã³ã¯ãã¯ãªãã¯ããŠå°å·ããã ãã
- 䜿çšãã差蟌ããŒã¿ã®ã¹ãã¬ããã·ãŒãã¯ãäºãæžåŒããæžåŒãªãããã¹ããã«ããŠãããšè¯ãã§ããç¹ã«æ¥ä»ãªã©ã®ããŒã¿ã¯ãã®ãŸãŸã ãšã衚瀺ããŠã圢åŒã§ã¯ãªã圢åŒã§ããŒã¿ãååŸãããŠããŸããŸããæžåŒãªãããã¹ããªããèŠãç®ã®ãŸãŸã®ããŒã¿ã§å·®ã蟌ãã§ãããŸãã
- Google Picker APIãå©çšããŠããŸãã®ã§ãã¯ã©ãŠãã³ã³ãœãŒã«ã§ããããããŒããŒãçæããPicker APIãæå¹ã«ããå¿ èŠæ§ããããŸãã
å®è¡çµæ
ãã€ã³ã
å°å·ã¡ãœããããªãåããã³ãã¬ãŒããäžæ·ãã«ãïŒã€ã®ããã¥ã¡ã³ãå ã«ããŒãžãšãã圢ã§ãå°å·ç©ã®å ãäœãã®ãå³åã§ãããã³ãã¬ãŒãã®äžèº«ãç»åããæååãŸã§å«ããŠãããã¥ã¡ã³ããè€è£œãããã®åŸãreplacetextã«ãŠæåãã¹ãã¬ããã·ãŒãã®ã«ã©ã ã«å¯Ÿå¿ãããã®ããã£ãŠçœ®æãããããã§ããå®éã«ã¯ããã³ãã¬ãŒãããŒã¿ã®å¡ãè€è£œããŠã¯ã眮æããè€è£œããŠã¯çœ®æããäœæ¥ãç¹°ãè¿ããŠããŸãã
ããŒãžã¯ã¹ãã¬ããã·ãŒãã®ã¬ã³ãŒãåã ãçšæããŸãããæ¿å ¥ããã«ã©ã æåã«ã€ããŠããèªåçã«æ¿å ¥ããã¹ã¯ãªãããä»èŸŒãŸããŠããã®ã§ããŠãŒã¶ã¯ããŠã¹ã ãã§æäœãå®çµããããšãã§ããŸãããŸãããµã€ãããŒãçšããŠãã®ã§ããã€ã¢ãã°ãšéããåžžã«äœæ¥ããªããè¡ããã®ã§äŸ¿å©ã§ããããããããŠãŒãã£ãªãã£çãªã·ãŒã³ã§ã¯ãµã€ãããŒã¯ãªã¹ã¹ã¡ã§ãã
ã¡ãœããé¡ã§ãããæ£çŽãŸã å šäœåãææ¡ããŠããŸããããã£ãšè¯ãããæ¹ãããã®ãããããŸãããå®çšã«ã¯ååã ãšã¯æããŸããä»åã¯Â§èšå·ã代çšããŠãå®å šäžèŽã§çœ®ãæããããã«ããŠããŸãã
ãã®åŸãreplaceTextã®æ£èŠè¡šçŸã¯ãéåžžã®Javascriptã§çšããããŠãæ£èŠè¡šçŸãšã¯ç°ãªããREæ§æãšåŒã°ãããã®ã§æžããªããšãããªãã¿ããã§ãã[ãã¹ã]â眮ãæãæåãšãããå Žåã«ã¯ãsourceDoc.replaceText(â(\\[)(ãã¹ã)(\\])â,â眮ãæãæåâ);ãšããªããã°ãªããªãããã§ãã
ãã©ã°ã©ãã®ã³ããŒå ã§ããããã³ãã¬ãŒãã®Bodyãã³ããŒãããã®ããè€è£œããŠããŸããã§ãªããšãæ°ãã«ã³ããŒã远å ãããŠçœ®æãè¡ã£ããã®ãè€è£œããŠããŸãçºã§ãããªãªãžãã«ãããŒãããŠããããã§ãããŸããæ°ãã«Documentãäœãããã¡ã€ã«ã®è€è£œãè¡ãããŠãçç±ã¯ããã£ãšæŸçœ®ãããŠããã°ãªã®ã§ããããã®ãŸãŸãªãªãžãã«ãã¡ã€ã«ããã®ãã©ã°ã©ãã³ããŒã ãšç»åãåºãŸããããã¡ã€ã«ã®è€è£œãªãåé¡ãªãã®ã§ãè€è£œãBodyãã³ããŒãããããã¬ã³ãŒãæ°åå·®ã蟌ã¿ã€ã€çœ®æããŠããŸããDocument.Element.Typeãç»åãäœããããParagraphã§è¿ã£ãŠæ¥ãã®ã§å€å¥ãã§ããªãã®ããããçç±ã§ããtableãªã©ã¯éã«ã¡ãããšåž°ã£ãŠããã®ã§ãä»åã®ãããªåå¥ã®appendãå¿ èŠãšããã¡ãã¯ãå ·åããªããšãèšããŸããã
é¢é£ãªã³ã¯
- Google Apps Scriptã§ãå¿æž©ãŸã幎è³ç¶ãäœããïŒ
- How to delete the selected lines with Apps Script in Google Docs?
- Google app script copy document page
- Google App script Document App get selected lines or words?
- Can I color certain words in google document using google script?
- Duplicating a page of a document and replacing text on each page
- Google script IDçªå·ãé åãå©çšããŠäžçºå ¥å 差蟌å°å·
- Google Apps Script- Appending Paragraph at specific location
- How to copy the content of a google docs text file to another Google text document? ?
- How to copy one or more existing pages of a document using google apps script
- Word: Replace and reformat text inside square brackets using wildcards
- re2 â Google reguler expression
- How to Merge Multiple Google Documents
質åã§ãã
GoogleSpreadSheetãGoogleDocumentãè¶ åå¿è ã§ãã
äŒç€Ÿã§GoogleWorkSpaceã䜿çšããŠããŸãã
å®è¡ããããšãããšã䜿çšãã差蟌ããŒã¿ãã¯ãããŒã¿éžæãã
ããã¡ã€ã«æ ŒçŽå Žæãã¯ããã©ã«ãéžæãã衚瀺ãããŠããŸãã
ã©ã¡ãããå¥ãŠã£ã³ããŠã§ååºŠéžæãããã¿ã³ã衚瀺ãããŸããã
å¥ãŠã£ã³ããŠå ã§ã¯ãªãã¯ããŠãããã¡ã€ã«ããã©ã«ããéžæããç»é¢ã
衚瀺ãããŸããã
ããŸãã«åå¿è ããšæããŸããäœåãæå°è³ããŸããã
ãããããé¡ãç³ãäžããŸãã
æ³¢å€éæ§
ãã®èšäºã®äžã«ããããŸãããå¥éPicker APIã®API Keyãã³ãŒãå ã«èšè¿°ããªããšéžæç»é¢ãåºãŠããŸããã
ãŸããçŸåšãPicker APIã®èšè¿°æ¹æ³ãç°ãªã£ãŠãã®ã§ã以äžã®ãšã³ããªãŒããææ°ã®è¡šç€ºæ¹æ³ã«è£ åã倿ŽããŠã¿ãŠãã ããã
https://officeforest.org/wp/2018/05/20/picker%e3%81%a7%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%84%e3%83%95%e3%82%a9%e3%83%ab%e3%83%80%e3%82%92%e9%81%b8%e6%8a%9e%e3%81%99%e3%82%8b%e7%94%bb%e9%9d%a2%e3%82%92%e8%a3%85%e5%82%99%e3%81%99/