Как применить свой AppsScript только к одной вкладке моей электронной таблицы?JAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Как применить свой AppsScript только к одной вкладке моей электронной таблицы?

Сообщение Anonymous »

У меня есть приложение, которое позволяет мне создавать пользовательские счета для моего бизнеса, но я не могу выяснить, как применить весь свой сценарий только к одной вкладке моей электронной таблицы. Как это, это относится ко всем вкладкам. Я не продвинутый писатель сценариев, так что я многое не знаю. Любая помощь будет очень оценена. Спасибо! < /P>

Код: Выделить всё

function onOpen() {
{const ui = SpreadsheetApp.getUi();
ui.createMenu('Custom')
.addItem('Generate Invoice', 'exportSelectedRowToPDF')
.addToUi();
}

function exportSelectedRowToPDF() {
const companyInfo = {
name: "Magic Dragon Customs",
address: "4730 West 2nd Street North",
website: "Wichita, KS 67212",
phone: "316-214-7980"
};

const checkRemittanceInfo = {
payableTo: "Magic Dragon Customs",
address: "4730 West 2nd St North, Wichita, KS 67212",
additionalInfo: "Please include the invoice number on your check."
};

const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const row = sheet.getActiveRange().getRow();
if (row  acc + curr.total, 0);
let discount = parseFloat(discountAmount) || 0;
let deposit = parseFloat(depositAmountInvoiced) || 0;
let tax = parseFloat(0.075*(subtotal - discount - deposit)) || 0;
let totalDue = subtotal - discount - deposit + tax;

const today = new Date();
const dueDate = new Date(today.getTime() + (30 * 24 * 60 * 60 * 1000));

const doc = DocumentApp.create(`Invoice-${jobID}`);
const body = doc.getBody();
body.setMarginTop(72); // 1 inch
body.setMarginBottom(72);
body.setMarginLeft(72);
body.setMarginRight(72);

// Document Header
body.appendParagraph(companyInfo.name)
.setFontSize(16)
.setBold(true)
.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.appendParagraph(companyInfo.address)
.setFontSize(10)
.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.appendParagraph(`${companyInfo.website}`)
.setFontSize(10)
.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.appendParagraph(`${companyInfo.phone}`)
.setFontSize(10)
.setAlignment(DocumentApp.HorizontalAlignment.CENTER);
body.appendParagraph("");

// Invoice Details
body.appendParagraph(`Invoice #: ${jobID}`).setFontSize(10).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
body.appendParagraph(`Invoice Date: ${today.toLocaleDateString()}`).setFontSize(10).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
body.appendParagraph(`Due Date: ${dueDate.toLocaleDateString()}`).setFontSize(10).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
body.appendParagraph("");

// Bill To Section
body.appendParagraph("BILL TO:").setFontSize(10).setBold(true);
body.appendParagraph(billingName).setFontSize(10);
body.appendParagraph(billingAddress).setFontSize(10);
body.appendParagraph("");

// Services Table
const table = body.appendTable();
const headerRow = table.appendTableRow();
headerRow.appendTableCell('SERVICE').setBackgroundColor('#f3f3f3').setBold(true).setFontSize(10);
headerRow.appendTableCell('RATE').setBackgroundColor('#f3f3f3').setBold(true).setFontSize(10);
headerRow.appendTableCell('QUANTITY').setBackgroundColor('#f3f3f3').setBold(true).setFontSize(10);
headerRow.appendTableCell('TOTAL').setBackgroundColor('#f3f3f3').setBold(true).setFontSize(10);
services.forEach(service => {
const row = table.appendTableRow();
row.appendTableCell(service.listed).setFontSize(10);
row.appendTableCell(`$${service.fee.toFixed(2)}`).setFontSize(10);
row.appendTableCell(`${service.quantity}`).setFontSize(10);
row.appendTableCell(`$${service.total.toFixed(2)}`).setFontSize(10);
});

// Financial Summary
body.appendParagraph(`Subtotal: $${subtotal.toFixed(2)}`).setFontSize(10).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
if (discount > 0) {
body.appendParagraph(`Discount: -$${discount.toFixed(2)}`).setFontSize(10).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}
if (deposit > 0) {
body.appendParagraph(`Payment Received: -$${deposit.toFixed(2)}`).setFontSize(10).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}
if (tax > 0) {
body.appendParagraph(`Tax: +$${tax.toFixed(2)}`).setFontSize(10).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}
body.appendParagraph(`Total Due: $${totalDue.toFixed(2)}`).setFontSize(10).setBold(true).setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
body.appendParagraph("");

// Physical Check Remittance Information
body.appendParagraph("NO WARRANTY ON RUST").setBold(true).setFontSize(14)
body.appendParagraph("To remit by physical check, please send to:").setBold(true).setFontSize(10);
body.appendParagraph(checkRemittanceInfo.payableTo).setFontSize(10);
body.appendParagraph(checkRemittanceInfo.address).setFontSize(10);
body.appendParagraph(checkRemittanceInfo.additionalInfo).setFontSize(10);

// PDF Generation and Sharing
doc.saveAndClose();
const pdfBlob = doc.getAs('application/pdf');
const folders = DriveApp.getFoldersByName("Invoices");
let folder = folders.hasNext() ? folders.next() : DriveApp.createFolder("Invoices");
let version = 1;
let pdfFileName = `Invoice-${jobID}_V${String(version).padStart(2, '0')}.pdf`;
while (folder.getFilesByName(pdfFileName).hasNext()) {
version++;
pdfFileName = `Invoice-${jobID}_V${String(version).padStart(2, '0')}.pdf`;
}
const pdfFile = folder.createFile(pdfBlob).setName(pdfFileName);
pdfFile.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
const pdfUrl = pdfFile.getUrl();

const htmlOutput = HtmlService.createHtmlOutput(`Invoice PDF generated successfully. Version: ${version}. [url=${pdfUrl}]Click here to view and download your Invoice PDF[/url].
`)
.setWidth(300)
.setHeight(100);
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Invoice PDF Download');
DriveApp.getFileById(doc.getId()).setTrashed(true);
}}



Подробнее здесь: https://stackoverflow.com/questions/797 ... preadsheet
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»