/ / Google Apps स्क्रिप्ट - Google पत्रक से Google कैलेंडर में ईवेंट निर्यात करना - मैं अपने स्प्रेडशीट फ़ार्मुलों को निकालने से कैसे रोक सकता हूं? - एक्सेल, गूगल-ऐप्स-स्क्रिप्ट

Google Apps स्क्रिप्ट - Google पत्रक से Google कैलेंडर में ईवेंट निर्यात करना - मैं अपने स्प्रेडशीट फ़ार्मुलों को निकालने से कैसे रोक सकता हूं? - एक्सेल, गूगल-ऐप्स-स्क्रिप्ट

मैं एक ऐसा कोड बनाने की कोशिश कर रहा हूं जो Google स्प्रेडशीट से जानकारी लेता है, और Google कैलेंडर ईवेंट बनाता है। मैं इसके लिए नया हूं, इसलिए मेरी इन-कोडिंग ज्ञान की कमी है!

मैंने शुरू में एक कोड बनाने के लिए इस पोस्ट का उपयोग किया था: स्प्रेडशीट से Google कैलेंडर ईवेंट बनाएं लेकिन डुप्लिकेट को रोकें

फिर मैंने काम किया कि स्प्रेडशीट पर पंक्तियों की संख्या के कारण इसका समय समाप्त हो रहा था, और डुप्लिकेट से बचने के लिए ईवेंट बनाने के लिए मुझे नहीं मिला। मुझे इस बात का जवाब मिल गया कि बाहर काम करना है! Google स्क्रिप्ट, जो Google स्प्रेडशीट से Google कैलेंडर ईवेंट बनाता है - "अधिक से अधिक निष्पादन समय"

और अब मुझे एहसास हुआ कि यह सूत्रों को ओवर-राइटिंग कर रहा है, मेरे पास स्प्रैडशीट में प्रत्येक पंक्ति में ऑटो-पूर्ति इस प्रकार है:

Row 12 - =if(E4="","",E4+1) // Row 13 - =if(C4="","",C4+1) // Row 18 - =if(B4="","","WHC - "&B4) // Row 19 - =if(B4="","","Docs - "&B4)

क्या किसी के पास कोई विचार है कि मैं इसे करने से कैसे रोक सकता हूं?

/**
* Adds a custom menu to the active spreadsheet, containing a single menu item
* for invoking the exportEvents() function.
* The onOpen() function, when defined, is automatically invoked whenever the
* spreadsheet is opened.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function onOpen() {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Export WHCs",
functionName : "exportWHCs"
},
{
name : "Export Docs",
functionName : "exportDocs"
}];
sheet.addMenu("Calendar Actions", entries);
};

/**
* Export events from spreadsheet to calendar
*/
function exportWHCs() {
// check if the script runs for the first time or not,
// if so, create the trigger and PropertiesService.getScriptProperties() the script will use
// a start index and a total counter for processed items
// else continue the task
if(PropertiesService.getScriptProperties().getKeys().length==0){
PropertiesService.getScriptProperties().setProperties({"itemsprocessed":0});
ScriptApp.newTrigger("exportWHCs").timeBased().everyMinutes(5).create();
}
// initialize all variables when we start a new task, "notFinished" is the main loop condition
var itemsProcessed = Number(PropertiesService.getScriptProperties().getProperty("itemsprocessed"));
var startTime = new Date().getTime();
var sheet = SpreadsheetApp.getActiveSheet();
var headerRows = 4;  // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var data = range.getValues();
var calId = "flightcentre.com.au_pma5g2rd5cft4lird345j7pke8@group.calendar.google.com";
var cal = CalendarApp.getCalendarById(calId);
for (i in data) {
if (i < headerRows) continue; // Skip header row(s)
var row = data[i];
var date = new Date(row[12]);  // First column
var title = row[18];           // Second column
var tstart = new Date(row[15]);
tstart.setDate(date.getDate());
tstart.setMonth(date.getMonth());
tstart.setYear(date.getYear());
var tstop = new Date(row[16]);
tstop.setDate(date.getDate());
tstop.setMonth(date.getMonth());
tstop.setYear(date.getYear());
var id = row[17];              // Sixth column == eventId
// Check if event already exists, update it if it does
try {
var event = cal.getEventSeriesById(id);
}
catch (e) {
// do nothing - we just want to avoid the exception when event doesn"t exist
}
if (!event) {
//cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"));
var newEvent = cal.createEvent(title, tstart, tstop).addEmailReminder(5).getId();
row[17] = newEvent;  // Update the data array with event ID
}
else {
event.setTitle(title);
}
if(new Date().getTime()-startTime > 240000){ // if > 4 minutes
var processed = i+1;// save usefull variable
PropertiesService.getScriptProperties().setProperties({"itemsprocessed":processed});
range.setValues(data);
MailApp.sendEmail(Session.getEffectiveUser().getEmail(),"progress sheet to cal","item processed : "+processed);
return;
}
debugger;
}
// Record all event IDs to spreadsheet
range.setValues(data);
}



/**
* Export events from spreadsheet to calendar
*/
function exportDocs() {
// check if the script runs for the first time or not,
// if so, create the trigger and PropertiesService.getScriptProperties() the script will use
// a start index and a total counter for processed items
// else continue the task
if(PropertiesService.getScriptProperties().getKeys().length==0){
PropertiesService.getScriptProperties().setProperties({"itemsprocessed":0});
ScriptApp.newTrigger("exportDocs").timeBased().everyMinutes(5).create();
}
// initialize all variables when we start a new task, "notFinished" is the main loop condition
var itemsProcessed = Number(PropertiesService.getScriptProperties().getProperty("itemsprocessed"));
var startTime = new Date().getTime();
var sheet = SpreadsheetApp.getActiveSheet();
var headerRows = 4;  // Number of rows of header info (to skip)
var range = sheet.getDataRange();
var data = range.getValues();
var calId = "flightcentre.com.au_pma5g2rd5cft4lird345j7pke8@group.calendar.google.com";
var cal = CalendarApp.getCalendarById(calId);
for (i in data) {
if (i < headerRows) continue; // Skip header row(s)
var row = data[i];
var date = new Date(row[13]);  // First column
var title = row[19];           // Second column
var tstart = new Date(row[15]);
tstart.setDate(date.getDate());
tstart.setMonth(date.getMonth());
tstart.setYear(date.getYear());
var tstop = new Date(row[16]);
tstop.setDate(date.getDate());
tstop.setMonth(date.getMonth());
tstop.setYear(date.getYear());
var id = row[20];              // Sixth column == eventId
// Check if event already exists, update it if it does
try {
var event = cal.getEventSeriesById(id);
}
catch (e) {
// do nothing - we just want to avoid the exception when event doesn"t exist
}
if (!event) {
//cal.createEvent(title, new Date("March 3, 2010 08:00:00"), new Date("March 3, 2010 09:00:00"));
var newEvent = cal.createEvent(title, tstart, tstop).addEmailReminder(5).getId();
row[20] = newEvent;  // Update the data array with event ID
}
else {
event.setTitle(title);
}
if(new Date().getTime()-startTime > 240000){ // if > 4 minutes
var processed = i+1;// save usefull variable
PropertiesService.getScriptProperties().setProperties({"itemsprocessed":processed});
range.setValues(data);
MailApp.sendEmail(Session.getEffectiveUser().getEmail(),"progress sheet to cal","item processed : "+processed);
return;
}
debugger;
}
// Record all event IDs to spreadsheet
range.setValues(data);
}

उत्तर:

जवाब के लिए 0 № 1

आपको उस समस्या को हल करने के तरीके अपनाने होंगे।

पहली संभावना: सरणी डेटा के साथ अपनी शीट को अपडेट करें केवल स्तंभों पर कोई सूत्र नहींके रूप में आगे बढ़ रहा है इस अन्य पोस्ट में लेकिन आपके मामले में (छोड़ने के लिए कई कॉलम के साथ) यह तेजी से मुश्किल हो जाएगा

दूसरी संभावना: (एक जिसे मैं व्यक्तिगत रूप से चुनूंगा क्योंकि मैं "सूत्र प्रशंसक नहीं हूं") वह करना है जो आपके सूत्र स्क्रिप्ट में स्वयं करते हैं, अर्थात सूत्र स्तर ऑपरेशन में सूत्रों का अनुवाद करें।

अपने उदाहरण के बाद =if(E4="","",E4+1) कुछ ऐसा बन जाता data[n][4]=data[n][4]==""?"":data[n+1][4]; अगर मुझे तर्क समझ में आया (लेकिन मुझे यकीन नहीं है ...)।


संपादित करें

वास्तव में एक है तीसरा समाधान जो और भी सरल है (जाने का आंकड़ा कि मैंने पहली बार में इसके बारे में क्यों नहीं सोचा ...) आप उन फ़ॉर्म्स को सहेज सकते हैं जिनके फॉर्मूले हैं, उदाहरण के लिए यदि कोल एम के फ़ार्मुले हैं जिनका आप उपयोग करना चाहते हैं:

var formulM = sheet.getRange("G1:G").getFormulas();

और फिर, समारोह के अंत में (वैश्विक के बाद) setValues()) सूत्रों का उपयोग करके फिर से लिखें:

sheet.getRange("G1:G").setFormulas(formulM);

पिछले सभी फ़ार्मुलों को पुनर्स्थापित करने के लिए ... उतना ही सरल, हर उस कॉलम के लिए दोहराएं जहाँ आपको फ़ार्मुलों को रखने की आवश्यकता है।