Create Google Doc from Google Sheets - Using Google Apps Script

Поділитися
Вставка
  • Опубліковано 24 лис 2024

КОМЕНТАРІ • 17

  • @CodeWithCurt
    @CodeWithCurt  4 роки тому +6

    Google Apps Script Code in Video Below:
    function createDocument() {

    var ui = SpreadsheetApp.getUi();
    var fileName = ui.prompt("File Name");
    var reportHeader = ui.prompt("Report Header");

    var ss= SpreadsheetApp.getActiveSpreadsheet();
    var dataSheet = ss.getSheetByName('Data');
    var dataRange = dataSheet.getDataRange();
    var dataValues = dataRange.getValues();

    var destination_id = ''; // ID OF GOOGLE DRIVE DIRECTORY;
    var destination = DriveApp.getFolderById(destination_id);

    var doc = DocumentApp.create(fileName.getResponseText());
    var docID = doc.getId();
    var file = DriveApp.getFileById(docID);
    file.moveTo(destination);

    var body = doc.getBody();
    body.insertParagraph(0, reportHeader.getResponseText())
    .setHeading(DocumentApp.ParagraphHeading.HEADING1);
    table = body.appendTable(dataValues);


    var tableHeader = table.getRow(0);
    tableHeader.editAsText().setBold(true).setForegroundColor('#ffffff');
    var getCells = tableHeader.getNumCells();

    for(var i = 0; i < getCells; i++)
    {
    tableHeader.getCell(i).setBackgroundColor('#BBB9B9');
    }
    }
    function addMenu()
    {
    var menu = SpreadsheetApp.getUi().createMenu('Custom');
    menu.addItem('Create Doc', 'createDocument');
    menu.addToUi();
    }
    function onOpen(e)
    {
    addMenu();
    }

  • @conhecimentoativo
    @conhecimentoativo 2 роки тому +3

    What I want to know is If you have knowledge of how to insert a table (or part of it) in a specific location of the ready-made docs document (Ex: in the middle of a ready-made mail merge template)... ..... Just like we do with the function ...replaceText("{NAME}", name)..... but instead of the variable "name", be a table........ your example is nice, but it just inserts the table at the end of the document and doesn't capture values from the worksheet. You can do it? thank you for your attention to my proposed challenge

  • @GerzaynFuentesKoltekmx
    @GerzaynFuentesKoltekmx 3 роки тому +1

    I want to create tables on a google doc, from a sheet filled from a form, but I need new tables at the beginning of the doc, so last an old tables move down. Do you have a video like this?
    Thank you for you videos and the code! Help me a lot.

  • @RahulSharma-uj7cr
    @RahulSharma-uj7cr 3 роки тому +1

    Your videos is great. When can we expect more videos of app script with basic to advance and bases on real life project. which we can use in our work (office, school) etc. hoping to hear from soon.

  • @ilgaralizada7206
    @ilgaralizada7206 2 роки тому

    Very nice ! Thank you so much!
    I want to combine Google Form, Sheets and Docs into a single Google app script Web app

  • @kamilsobieraj8385
    @kamilsobieraj8385 Рік тому

    Hi, is it possible to format text in created google doc in table for example in first column align text to right ?

  • @Jfresh55
    @Jfresh55 3 роки тому

    How do you do this but as a pdf and add a link to the pdf in the Google sheet itself. Essentially, how do you create an a script that acts like the add on autocrat

  • @jayasri-ft8040
    @jayasri-ft8040 4 роки тому

    Superb

  • @aditikumar6786
    @aditikumar6786 3 роки тому

    what if i only want to print cell no.2 and 4?? what will be the modification?

  • @ALWALEEDALWABEL
    @ALWALEEDALWABEL 4 роки тому +1

    Can you explain how to get data from Google sheet and display it in table as html page?
    with out any buttons just table with all the data from Google sheet and if I update by adding more column or rows it will update and get data with every time you refresh the page

    • @CodeWithCurt
      @CodeWithCurt  4 роки тому +1

      Here is the closest video I got that does pretty close of what your asking.
      ua-cam.com/video/17A2jTkeMkU/v-deo.html

    • @ALWALEEDALWABEL
      @ALWALEEDALWABEL 4 роки тому +1

      @@CodeWithCurt I have seen this before and the result I want did not appear, as I explained earlier. I would like you to explain your method much better and your way of communicating the information is excellent.

    • @ត្រូលកំពង់ធំ-រ4ណ
  • @SHRIMPRSES
    @SHRIMPRSES Рік тому

    Curt, how would you code to immediately open the created document in a new browser tab rather than having to navigate to it? I'm thinking DocumentApp.openById(), but not sure how to provide the string of the docID.

  • @mariaponcardas9526
    @mariaponcardas9526 Рік тому

    Is it possible to add hyperlink from google sheet to google doc?

  • @raihannewaz4728
    @raihannewaz4728 4 роки тому +1

    Awesome video.

  • @dinhtamnguyen1984
    @dinhtamnguyen1984 2 роки тому

    Thanks