Created
January 29, 2015 05:38
-
-
Save walkergv/d343852b2a4069268431 to your computer and use it in GitHub Desktop.
Create and Format a Google Doc from Google Sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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