I need to set the orizontal borders of table with 2.25pt width and the vertical borders with 0 pt like this sample https://docs.google.com/document/d/11jzzFgRL9BKiqEycnAkyIvNq726TV5EkdywkNB76X28/edit
The method setBorderWidth(width) set the same width to all borders
var doc = DocumentApp.getActiveDocument().getBody();
var cells = [
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
];
var tab = doc.insertTable(index, cells);
tab.setBorderColor('#ffffff');
setBorderWidth(2.25);
CodePudding user response:
Issue and workaround:
Unfortunately, it seems that the Google Document service (DocumentApp) cannot directly set the width of only the vertical border while the width of both the vertical and horizontal borders can be set. But, fortunately, when Google Docs API is used, your goal can be achieved.
In this answer, as a workaround, I would like to propose the method for using Docs API.
Sample script:
When your showing script is modified using Docs API, it becomes as follows.
Before you use this script, please enable Docs API at Advanced Google services.
function myFunction() {
var index = 1; // Please set the index you want to put the table.
// 1. Create a table using Document service.
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var cells = [
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
['Lorem ipsum dolor sit amet', 'Lorem ipsum dolor sit amet'],
];
var tab = body.insertTable(index, cells);
tab.setBorderColor('#ffffff').setBorderWidth(2.25);
doc.saveAndClose();
// 2. Set the width of vertical borders using Docs API.
var requests = [{ updateTableCellStyle: { tableCellStyle: { borderRight: { dashStyle: "SOLID", width: { magnitude: 0, unit: "PT" }, color: { color: { rgbColor: { red: 0 } } } }, borderLeft: { dashStyle: "SOLID", width: { magnitude: 0, unit: "PT" }, color: { color: { rgbColor: { red: 0 } } } } }, tableStartLocation: { index: index 1 }, fields: "borderRight,borderLeft" } }];
Docs.Documents.batchUpdate({ requests }, doc.getId());
}
- When this script is run, a table is put using the Document service. At that time, the width of borders is 2.25 pt. And, the width of the vertical borders is set to
0
using Docs API. By this, your goal can be achieved.