My problem with google spreadsheet conditional formatting is the border. I tried writing a script on this but I am stuck
In my first screenshot you can see the data, in row 7 and column A I have added a trigger that should tell the script whether it needs to do the formatting. where there is a 1 there should be borders when 0 or blank it should not. 
The Idea is that I get for the grid D12 to J32 borders however the rows 18,27 and 32 should have no borders due to the 0. Also the cells D12 to J32 cannot be hard coded as they are variable, 1 time it may be until row 32 the other till 55 same with the columns it can go from D untill L but also from D untill E. This might all change based on the template called on by change cell B9.
An Example how it looks like after border would be added
The script I have written so far take into account the onedit based on cell B9 and removes all borders from D12 untill the bottom and the side but it leave the border to the top and left intact. The problem I am unsure how to write a script that adds the borders with a variable range. I am guessing the most easy way to do it is to have it write first 1 larger table of borders and then remove the vertical borders on some rows again.
Would appreciate help with this.
function onEdit(e) { var sheet = e.source.getActiveSheet() if (sheet.getName() !== 'View' || e.range.getA1Notation() !== 'B9') return; var range = SpreadsheetApp.getActiveSheet().getRange(12,4,100,13); range.setBorder(false, false, false, false, false, false); }