SlideShare une entreprise Scribd logo
1  sur  10
Some common Excel functions
translated to Google Apps Script
Quick start to migration – part 1 Excel Liberation
Excel Liberation for details
Google Apps Script migration
Many people are either migrating to Google Docs or
using them alongside Microsoft Office Products
One inhibitor is where VBA automation has been
implemented in Excel workbooks. Google Apps
Script is essentially javaScript and has some
conceptual differences that provide a steep learning
curve when coming from Microsoft land.
A strategy for easing and speeding the transition is to
mimic common VBA functions in Google Apps
Script to minimize code conversion
Excel Liberation for details
Approach
javaScript differs considerably from VBA. This deck
does not cover learning javaScript, but rather
shows how some common VBA function might be
written in javaScript.
In order to minimize changes, we need to break
various javaScript conventions (like case
conventions for names)
A more detailed javaScript conversion primer and
some example project conversions can be found
here.
The functions discussed here are a subset of those
already available in a Google Apps Script
shareable library which you can include in your
project.
Excel Liberation for details
String functions - 1
VBA javaScript
RTrim(s) function RTrim(s) {
return CStr(s).replace(/ss*$/, "");
}
LTrim(s) function LTrim(s) {
return CStr(s).replace(/ss*$/, "");
}
Trim(s) function Trim(v) {
return LTrim(RTrim(v));
}
Len(v) function Len(v) {
return CStr(v).length ;
}
CStr(v) function CStr(v) {
return v===null || IsMissing(v) ? '' : v.toString() ;
}
Excel Liberation for details
String functions - 2
VBA javaScript
Left
(str,optLen
)
function Left(str,optLen) {
return Mid( str, 1 , optLen);
}
Right
(str,optLen
)
function Right(str,optLen) {
return Mid( str, 1 + Len(str) - fixOptional ( optLen, Len(str) ) );
}
Mid
(str,optSta
rt,optLen)
function Mid (str,optStart,optLen) {
var s = CStr(str);
var start = IsMissing (optStart) ? 0 : optStart - 1;
start = start < 0 ? 0 : start;
var length = IsMissing (optLen) ? Len(s) - start + 1 : optLen ;
return s.slice ( start, start + length);
}
Excel Liberation for details
String functions - 3
VBA javaScript
Split
(s,optDelim,
optLimit)
function Split(s,optDelim,optLimit) {
return CStr(s).split(fixOptional(optDelim,","),fixOptional(optLimit,-1));
};
LCase(s) function LCase(s) {
return CStr(s).toLowerCase();
}
function
UCase(s)
function UCase(s) {
return CStr(s).toUpperCase();
}
function
Chr(n)
function Chr(n) {
return String.fromCharCode(n);
}
function
Asc(s)
function Asc(s) {
return s.charCodeAt(0);
}
Excel Liberation for details
String functions - 4
VBA javaScript
InStr
(optStart,
inThisString
, lookFor,
optCompar
e)
function InStr(optStart,inThisString,lookFor,optCompare) {
// TODO optCompare
var start = fixOptional (optStart, 1);
var s = Mid (inThisString, start);
var p = s.indexOf(lookFor);
return (s && lookFor) ? (p == -1 ? 0 : p+start ): 0;
}
InStrRev
(inThisStrin
g,lookFor,
optStart,
optCompar
e)
function InStrRev(inThisString,lookFor,optStart,optCompare) {
// TODO optCompare
var start = fixOptional (optStart, -1);
var s = CStr(inThisString);
start = start == -1 ? Len(s) : start ;
return (s && lookFor) ? s.lastIndexOf(lookFor,start-1)+1 : 0;
}
Excel Liberation for details
Conversions
VBA javaScript
DateSerial
(y,m,d)
function DateSerial(y,m,d) {
return new Date(y,m,d);
}
Year (dt) function Year(dt) {
return dt.getFullYear();
}
CLng(v) function CLng(v) {
return isTypeNumber(v) ? Math.round(v) : parseInt(v) ;
}
CDbl(v) function CDbl(v) {
return parseFloat(v) ;
}
Excel Liberation for details
Tests
VBA javaScript
IsEmpty
(v)
function IsEmpty(v) {
return typeof(v) == "string" && v == Empty();
}
IsDate
(sDate)
function IsDate (sDate) {
var tryDate = new Date(sDate);
return (tryDate.toString() != "NaN" && tryDate != "Invalid
Date") ;
}
IsNumeric
(s)
function IsNumeric(s) {
return !isNaN(parseFloat(s)) && isFinite(s);
}
IsObject
(x)
function IsObject (x) {
return VarType(x) == 'object';
}
Excel Liberation for details
Part 2
That’s a brief introduction to some GAS
equivalents (almost) for VBA functions.
Part 2 will look at some of the more workbook
specific translations.
A more detailed javaScript conversion primer and
some example project conversions can be
found here.
The functions discussed here are a subset of
those already available in a Google Apps
Script shareable library which you can include
in your project.

Contenu connexe

En vedette

Using Groovy with Jenkins
Using Groovy with JenkinsUsing Groovy with Jenkins
Using Groovy with Jenkinssascha_klein
 
Belajar macro excel 2007
Belajar macro excel 2007Belajar macro excel 2007
Belajar macro excel 2007doni sandra
 
Belajar Excel Tingkat Mahir
Belajar Excel Tingkat MahirBelajar Excel Tingkat Mahir
Belajar Excel Tingkat MahirAYU LESTARI
 
Ebook Lengkap Microsoft Excel 2007
Ebook Lengkap Microsoft Excel 2007Ebook Lengkap Microsoft Excel 2007
Ebook Lengkap Microsoft Excel 2007Puguh Nugroho
 
17 Excel shortcuts to learn in 2017
17 Excel shortcuts to learn in 201717 Excel shortcuts to learn in 2017
17 Excel shortcuts to learn in 2017Excel Strategies LLC
 
Business Analysis Techniques
Business Analysis TechniquesBusiness Analysis Techniques
Business Analysis TechniquesIIBA UK Chapter
 
INTRODUCTION A GOOGLE SCRIPT [SLI]
INTRODUCTION A GOOGLE SCRIPT [SLI]INTRODUCTION A GOOGLE SCRIPT [SLI]
INTRODUCTION A GOOGLE SCRIPT [SLI]Johan Claeys
 
Working With Big Data
Working With Big DataWorking With Big Data
Working With Big DataSeth Familian
 

En vedette (8)

Using Groovy with Jenkins
Using Groovy with JenkinsUsing Groovy with Jenkins
Using Groovy with Jenkins
 
Belajar macro excel 2007
Belajar macro excel 2007Belajar macro excel 2007
Belajar macro excel 2007
 
Belajar Excel Tingkat Mahir
Belajar Excel Tingkat MahirBelajar Excel Tingkat Mahir
Belajar Excel Tingkat Mahir
 
Ebook Lengkap Microsoft Excel 2007
Ebook Lengkap Microsoft Excel 2007Ebook Lengkap Microsoft Excel 2007
Ebook Lengkap Microsoft Excel 2007
 
17 Excel shortcuts to learn in 2017
17 Excel shortcuts to learn in 201717 Excel shortcuts to learn in 2017
17 Excel shortcuts to learn in 2017
 
Business Analysis Techniques
Business Analysis TechniquesBusiness Analysis Techniques
Business Analysis Techniques
 
INTRODUCTION A GOOGLE SCRIPT [SLI]
INTRODUCTION A GOOGLE SCRIPT [SLI]INTRODUCTION A GOOGLE SCRIPT [SLI]
INTRODUCTION A GOOGLE SCRIPT [SLI]
 
Working With Big Data
Working With Big DataWorking With Big Data
Working With Big Data
 

Plus de Bruce McPherson

Do something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databasesDo something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databasesBruce McPherson
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Bruce McPherson
 
Do something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilterDo something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilterBruce McPherson
 
Do something in 5 with gas 7-email log
Do something in 5 with gas 7-email logDo something in 5 with gas 7-email log
Do something in 5 with gas 7-email logBruce McPherson
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Bruce McPherson
 
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetDo something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetBruce McPherson
 
Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appBruce McPherson
 
Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseDo something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseBruce McPherson
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseBruce McPherson
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionBruce McPherson
 
Using script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelUsing script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelBruce McPherson
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerBruce McPherson
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primerBruce McPherson
 

Plus de Bruce McPherson (15)

Do something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databasesDo something in 5 with gas 8-copy between databases
Do something in 5 with gas 8-copy between databases
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2
 
Goa tutorial
Goa tutorialGoa tutorial
Goa tutorial
 
Do something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilterDo something in 5 with apps scripts number 6 - fusion crossfilter
Do something in 5 with apps scripts number 6 - fusion crossfilter
 
Do something in 5 with gas 7-email log
Do something in 5 with gas 7-email logDo something in 5 with gas 7-email log
Do something in 5 with gas 7-email log
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
 
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetDo something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
 
Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing app
 
Do something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a databaseDo something in 5 with gas 2-graduate to a database
Do something in 5 with gas 2-graduate to a database
 
Do something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as databaseDo something in 5 minutes with gas 1-use spreadsheet as database
Do something in 5 minutes with gas 1-use spreadsheet as database
 
Google cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstractionGoogle cloud datastore driver for Google Apps Script DB abstraction
Google cloud datastore driver for Google Apps Script DB abstraction
 
Dbabstraction
DbabstractionDbabstraction
Dbabstraction
 
Using script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and ExcelUsing script db as a deaddrop to pass data between GAS, JS and Excel
Using script db as a deaddrop to pass data between GAS, JS and Excel
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 

Dernier

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Some common VBA functions translated to Google Apps Script

  • 1. Some common Excel functions translated to Google Apps Script Quick start to migration – part 1 Excel Liberation
  • 2. Excel Liberation for details Google Apps Script migration Many people are either migrating to Google Docs or using them alongside Microsoft Office Products One inhibitor is where VBA automation has been implemented in Excel workbooks. Google Apps Script is essentially javaScript and has some conceptual differences that provide a steep learning curve when coming from Microsoft land. A strategy for easing and speeding the transition is to mimic common VBA functions in Google Apps Script to minimize code conversion
  • 3. Excel Liberation for details Approach javaScript differs considerably from VBA. This deck does not cover learning javaScript, but rather shows how some common VBA function might be written in javaScript. In order to minimize changes, we need to break various javaScript conventions (like case conventions for names) A more detailed javaScript conversion primer and some example project conversions can be found here. The functions discussed here are a subset of those already available in a Google Apps Script shareable library which you can include in your project.
  • 4. Excel Liberation for details String functions - 1 VBA javaScript RTrim(s) function RTrim(s) { return CStr(s).replace(/ss*$/, ""); } LTrim(s) function LTrim(s) { return CStr(s).replace(/ss*$/, ""); } Trim(s) function Trim(v) { return LTrim(RTrim(v)); } Len(v) function Len(v) { return CStr(v).length ; } CStr(v) function CStr(v) { return v===null || IsMissing(v) ? '' : v.toString() ; }
  • 5. Excel Liberation for details String functions - 2 VBA javaScript Left (str,optLen ) function Left(str,optLen) { return Mid( str, 1 , optLen); } Right (str,optLen ) function Right(str,optLen) { return Mid( str, 1 + Len(str) - fixOptional ( optLen, Len(str) ) ); } Mid (str,optSta rt,optLen) function Mid (str,optStart,optLen) { var s = CStr(str); var start = IsMissing (optStart) ? 0 : optStart - 1; start = start < 0 ? 0 : start; var length = IsMissing (optLen) ? Len(s) - start + 1 : optLen ; return s.slice ( start, start + length); }
  • 6. Excel Liberation for details String functions - 3 VBA javaScript Split (s,optDelim, optLimit) function Split(s,optDelim,optLimit) { return CStr(s).split(fixOptional(optDelim,","),fixOptional(optLimit,-1)); }; LCase(s) function LCase(s) { return CStr(s).toLowerCase(); } function UCase(s) function UCase(s) { return CStr(s).toUpperCase(); } function Chr(n) function Chr(n) { return String.fromCharCode(n); } function Asc(s) function Asc(s) { return s.charCodeAt(0); }
  • 7. Excel Liberation for details String functions - 4 VBA javaScript InStr (optStart, inThisString , lookFor, optCompar e) function InStr(optStart,inThisString,lookFor,optCompare) { // TODO optCompare var start = fixOptional (optStart, 1); var s = Mid (inThisString, start); var p = s.indexOf(lookFor); return (s && lookFor) ? (p == -1 ? 0 : p+start ): 0; } InStrRev (inThisStrin g,lookFor, optStart, optCompar e) function InStrRev(inThisString,lookFor,optStart,optCompare) { // TODO optCompare var start = fixOptional (optStart, -1); var s = CStr(inThisString); start = start == -1 ? Len(s) : start ; return (s && lookFor) ? s.lastIndexOf(lookFor,start-1)+1 : 0; }
  • 8. Excel Liberation for details Conversions VBA javaScript DateSerial (y,m,d) function DateSerial(y,m,d) { return new Date(y,m,d); } Year (dt) function Year(dt) { return dt.getFullYear(); } CLng(v) function CLng(v) { return isTypeNumber(v) ? Math.round(v) : parseInt(v) ; } CDbl(v) function CDbl(v) { return parseFloat(v) ; }
  • 9. Excel Liberation for details Tests VBA javaScript IsEmpty (v) function IsEmpty(v) { return typeof(v) == "string" && v == Empty(); } IsDate (sDate) function IsDate (sDate) { var tryDate = new Date(sDate); return (tryDate.toString() != "NaN" && tryDate != "Invalid Date") ; } IsNumeric (s) function IsNumeric(s) { return !isNaN(parseFloat(s)) && isFinite(s); } IsObject (x) function IsObject (x) { return VarType(x) == 'object'; }
  • 10. Excel Liberation for details Part 2 That’s a brief introduction to some GAS equivalents (almost) for VBA functions. Part 2 will look at some of the more workbook specific translations. A more detailed javaScript conversion primer and some example project conversions can be found here. The functions discussed here are a subset of those already available in a Google Apps Script shareable library which you can include in your project.