The following piece of code will create a Google Document and will insert a dynamic text, as a paragraph, into the newly created document. All is done from within a Google Spreadsheet.
Code
// global
var ss = SpreadsheetApp.getActive();
function onOpen() {
var menu = [{name: "Create Document", functionName: "createDoc"}];
ss.addMenu("Extra", menu);
}
function createDoc() {
var sh = ss.getActiveSheet(), aRow = sh.getActiveCell().getRowIndex();
var title = sh.getRange(aRow, 1).getValue(), docDate = new Date();
var docTitle = title + "-" + docDate, doc = DocumentApp.create(docTitle);
// create text in document
var body = doc.getBody();
body.appendParagraph("A paragraph " + docTitle);
// create app and panel
var app = UiApp.createApplication().setTitle("Open Google Document")
.setHeight(50).setWidth(400);
var vPanel = app.createVerticalPanel()
.add(app.createAnchor(docTitle, doc.getUrl()));
// add to app
app.add(vPanel);
ss.show(app);
}
Add
The code in your Google Spreadsheet, under Tools>Script editor. Press the bug button to authenticate the code and all is set to go.
Example
I've created an example file for you: create Google Document with text