Skip to content

Instantly share code, notes, and snippets.

@walkergv
Created January 29, 2015 05:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walkergv/d343852b2a4069268431 to your computer and use it in GitHub Desktop.
Save walkergv/d343852b2a4069268431 to your computer and use it in GitHub Desktop.
Create and Format a Google Doc from Google Sheet
function createDoc() {
//
// Get The Current Spreadsheet
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
//
// Get data in spreadsheet
var range = sheet.getDataRange();
var rowsData = range.getValues();
//
// Create a New Document
var doc = DocumentApp.create('Test Document 38');
var body = doc.getBody();
//
// Set Styles foir table
var style = {};
style[DocumentApp.Attribute.FONT_FAMILY] =
DocumentApp.FontFamily.CALIBRI;
style[DocumentApp.Attribute.FONT_SIZE] = 9;
var highlightStyle = {};
highlightStyle[DocumentApp.Attribute.BACKGROUND_COLOR] = '#FFFF00';
highlightStyle[DocumentApp.Attribute.BOLD] = true;
body.insertParagraph(0, doc.getName())
.setHeading(DocumentApp.ParagraphHeading.HEADING1);
//
//Add the datga to the table and set the style
table = body.appendTable(rowsData).setAttributes(style);
//
// Format the header row
for (var i = 0; i < table.getRow(0).getNumChildren(); i++) {
table.getRow(0).getCell(i).setAttributes(highlightStyle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment