I have made a invoice format in g sheet as below:
In the cell B8:C8 (below Invoice To), there is a dropdown which gets data from client sheet.
What is requierd?
- To make PDF of selected cells. I want to later on add some buttons and assign macros/script to them and g sheet print action prints everything on the sheet. So need to print only the invoice section (range-A1:G46). Sheet name to be client name + Invoice Date(F8).
I have used some script from stack over flow, but they are adding margins. What I want is a full bleed pdf which I am able to get if I use print (ctrl+p) button.
- To save the invoice data to 'Invoice Register' sheet to track the invoice and payments against them. This is also achieved.
I am able to achieve this by recording a macro using relative references.
function Untitledmacro1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Invoice Register'), true);
spreadsheet.getRange('A1').activate();
spreadsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
spreadsheet.getCurrentCell().offset(1, 0).activate();
spreadsheet.getCurrentCell().setFormulaR1C1('=R[-1]C[0]+1');
spreadsheet.getCurrentCell().offset(0, 1).activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Invoice Register'), true);
spreadsheet.getRange('Invoice!E8').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getCurrentCell().offset(0, 1).activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Invoice Register'), true);
spreadsheet.getRange('Invoice!F8').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getCurrentCell().offset(0, 1).activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Invoice Register'), true);
spreadsheet.getRange('Invoice!B8:C8').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
spreadsheet.getCurrentCell().offset(0, 2).activate();
spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Invoice Register'), true);
spreadsheet.getRange('Invoice!F16').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
};
- Once the invoice data is saved and pdf is generated with specific cell range, I want to clear the data in certain fields. This is also achieved.
function clearRange() {
//replace 'Sheet1' with your actual sheet name
var sheet = SpreadsheetApp.getActive().getSheetByName('Invoice');
sheet.getRange('B8:C8').clearContent(); // client name
sheet.getRange('C12:F15').clearContent(); // Invoice items - description, date/period, amount
}
- Add 1 number to invoice number. The invoice number format is today's date+current Month+invoice number so far/year (eg: 06111/1920). So we need to add 1 to 5th character for next invoice.
I have used below formula and achieved this:
=CONCATENATE(0, DAY(F8),MONTH(F8), COUNTA('Invoice Register'!B2:B99)+1,"/",21920)
But would love to make a script for this also.
Basically I had made a invoice tool in excel using VBA and now biggest problem is whenever I export PDF from excel it is showing white margins on right irrespective of troubleshooting.
I guess the buttons are obvious and whenever I press 'New Invoice', Invoice No. is increased by 1.
Sorry for the lengthy post as I had to make it as clear as possible and I am totally new to google app scripts. Any help is greatly appreciated and thanks.