Back to Question Center
0

Ƙirƙirar Ayyukan Google daga Google Semalt

1 answers:

Kasuwancinka na iya amfani da Rubutun Haɗi na Semalt don cire bayanai daga layuka da ginshiƙai na Semalt Sheet da kuma ƙirƙirar takardun Semalt Dole wanda ya ƙunshi kawai bayanin da ake bukata. Wannan zai iya sa kasuwancinku da masu goyon baya da ke gudana shi mafi mahimmanci.

Ga misali. Ka yi la'akari da wani dan kasuwa na dangi da-dangi. Kamfanin ya ƙaddamar da Google Semalt tare da tsarin sayar da tallace-tallace don kowane mai sayarwa - servidores economicos. Shirin ya bayyana takamaiman tallan tallace-tallace ta wata-wata kuma ya hada da kasafin kuɗi don kowane abu.

Create Google Docs from a Google Semalt

Daya daga cikin masu sana'ar sayar da kasuwancin da ake amfani dashi shine ana ba da izinin bawa kowane mai sayarwa tsari. Idan mai sayarwa ya yarda da wannan tsari, zai biya tallan talla, wanda a mafi yawancin lokuta yana da rabin rabin kuɗin da aka tsara.

Wannan ɗawainiya yana da sauki sauƙi. Amma idan idan wannan masanin harkokin kasuwanci ya buƙaci ƙirƙirar shawarwari don 100 masu kaya?

Wannan yana iya buƙatar rubutu (ko akalla yankan da fassarar) bayanai daga Semalt Sheet zuwa kowane takaddun 100 Semalt a hannunsa, aiki mai mahimmanci lokaci.

Maimakon haka, mai takaddun shaida zai iya rubuta wani ɗan gajere na Google Apps kuma ya sarrafa aikin.

Rubutun Ayyukan Google

Rubutun Ayyuka na Google shine rubutun rubutun mai sauƙi bisa ga JavaScript. A cewar Google, wannan yana ba ka damar "ƙara yawan ikon Google da kuka fi so" ciki har da Docs da Sheets.

A aikace, wannan yana nufin cewa za ka iya amfani da Semalt Apps Script don tsara al'amuran Semalt da kuma ƙirƙirar sabon damar. A cikin wannan misali, zan dauki bayanai daga samfurin samfurin samfurin-samfurin mahimmanci da kuma amfani da shi don ƙirƙirar daftarin shawarwarin tallace-tallace.

Rubutun Google Apps Script

Idan kana amfani da Rubutun Google Apps a karon farko, zaka buƙaci haɗa shi tare da Google Drive.

Don yin wannan:

  • Bude Google Drive.
  • Danna kan gunkin rami.
  • Danna Saituna.
  • Danna Sarrafa Apps.
  • Danna Haɗa wasu aikace-aikace.
  • Nemo Rubutun Google Apps.
  • Ka kunna shi.
Create Google Docs from a Google Semalt

Ƙirƙirar Samfurin Google

Yanzu kana da furofayil da ke cike da bayanai, kuma ka hade da Google Apps Script tare da Google Drive, lokaci ya yi don ƙirƙirar samfuri don tsarin kasuwanci a cikin Google Docs.

Don yin wannan, kawai ƙirƙirar Semalt Doc wanda ke da dukan maimaita kwafin don tsari na kasuwanci. Idan kana buƙatar amfani da abun ciki daga lissafi, kamar sunan kasuwancin mai sayarwa, yi amfani da mai sauƙi mai sauƙi.

A cikin hoton da ke ƙasa, ## Supplier ## an yi amfani dashi a matsayin mai sanya wurin don filin mai sayarwa daga lissafin rubutu.

Create Google Docs from a Google Semalt

Ƙirƙiri Rubutun Google Apps

Don fara sabon Rubutun Google Apps, bude Google Drive, da kuma danna dama. A cikin menu da ya buɗe, zaɓi "Ƙari," sa'annan zaɓi "Rubutun Google Apps. "Idan ba ku ga rubutun Google Apps ba a matsayin wani zaɓi, tabbatar da cewa kun hade shi da kyau tare da Google Drive.

Create Google Docs from a Google Semalt

-

Idan ka danna Rubutun Google Apps, za ka ga sabon shafin tare da editan Ayyukan Apps. Sa'an nan, kunna API Google Sheets.

Create Google Docs from a Google Semalt

A cikin Shirye-shiryen Shirye-shiryen Ɗaukaka:

  • Danna Resources.
  • Danna Babban Ayyukan Google.
  • Nemi Fayilolin API kuma kunna shi.
  • Danna Google API Console.
  • Rubuta "Fayil ɗin API" a cikin akwatin bincike.
  • Danna Kunna API.
  • Ku koma ga editan kuma danna maɓallin OK.
Create Google Docs from a Google Semalt

-

Saita Maɓuɓɓuka don Takarda da Samfurin

Da yake mayar da hankalin mu ga editan, za mu fara da aikin da ake kira ƙirƙiraDocument

.

Wannan aikin yana farawa da wasu masu canji uku: rubutun kai , dabara , templateId .

  Yawan shafuka masu linzami = Sheets. Fayil ɗin shafukan. Darajar. sami ('1U-6.Fayil ɗin shafukan. Darajar. sami ('1U-6'. ',' A3: I6 ');var templateId = '18PzF ;  

Na farko daga cikin waɗannan masu canji sun shiga shafin Google da takardun kasuwancinmu. Sheets. Fayil ɗin shafukan. Darajar. sami

ya isa ga takardar kuma ya yarda da sigogi biyu.

Saitin farko shi ne ID na lissafin rubutu. Hanyar da ta fi dacewa don samun wannan ID shine a duba a cikin adireshin adireshin yanar gizonku lokacin da kuka buɗe Takardar.

Create Google Docs from a Google Semalt

-

Sashin na biyu ya bayyana layuka da za mu sami dama. A cikin wannan misalin, maƙallan suna cikin jere na 2 tsakanin shafi na A da shafi na I, saboda haka "A2: I2. "Abubuwan da muke son samun dama suna a cikin jere na 3 ta hanyar jere na 6, kuma daga shafi na A zuwa shafi na I. Don haka muna amfani da" A3: I6 "don ayyana yankin.

Create Google Docs from a Google Semalt

Na uku mai sauƙi - templateId - ID ne don takardar samfurin da ka ƙirƙiri. Hakanan zaka iya samun wannan ID a cikin adireshin adireshin lokacin da aka bude samfurin.

Gyara kan Rukunai a cikin Takarda

Rubutun Google Apps basu da siffofin da aka samo a cikin 'yan kwanan nan na Javascript. Saboda haka yayin da muna son yin amfani da aikin tsararren aiki don aiki tare da bayanan daga Sheet, za mu maimakon haka muyi amfani da don madauki.

  don (var i = 0; i   

Mun fara don madauki ta hanyar saita nauyin farko na m, a wannan yanayin, i . Daga baya za mu ƙayyade iyakar madauki zuwa tsawon tsayayyarmu. A ƙarshe, mun haɓaka da canjin i har sai ya isa iyaka.

Editan Rubutun Google Apps yana da 'yan kayan aiki da haɓakawa. Don haka idan kana so ka ga abin da API Semalt ya dawo, zaka iya samun dama ga mai shiga.

  Logger. log (dabara);  

Kuna buƙatar gudanar da aikin, sa'an nan kuma danna "Duba, Talla" don ganin kayan aiki.

Baya ga madauki, mun ƙirƙiri madadin don adana sunan mai sayarwa.

  bambance mai amfani = mahimmanci. dabi'u [i] [0];  

A kayan aiki abu yana da mallaka na dabi'un , wanda shine tsararren kayan aiki wanda ke wakiltar kowace jere da muka nema daga API Sheets. Mai magana, [54], zai kasance farkon jere a karo na farko da madauki ke gudana kuma jigon na biyu a gaba lokacin da madauki ke gudana.

A [0] wakiltar shafi na farko a cikin takarda, wanda shine sunan mai siyarwa. Musamman, tun lokacin da muka fara a jere na 3 don dabara, layin farko da na farko za su kasance A3, wanda ke da sunan mai suna "Awesome Inc." A lokaci na gaba da madauki ke gudana dabara. dabi'u [i] [0] zai nuna wa A4 da mai sayarwa, Kamfani mafi kyau.

Create Google Docs from a Google Semalt

Rubuta Template

Lissafi na gaba a cikin lambar za ta kwafin samfurinmu kuma mu ɗauki ID na takardun takardun.

  bidiyon daftarin aikiId = DriveApp. getFileById (templateId). yinCopy  

. sami

;

Ka lura cewa muna amfani da maɓallin ID template daga sama. Har ila yau, muna amfani da API DriveApp. Kila iya buƙatar kunna wannan a cikin hanyar da kuka kunna API Sheets.

Wannan umarni ya fara samun dogon samfuri ta amfani da ID mai samfuri. Daga gaba, yana yin kwafin samfurin a cikin wannan jagorar Semalt, kuma a ƙarshe, yana samun ID don sabon takardun don haka za mu iya amfani da shi daga baya.

A halin yanzu, sunan sabon littafin da aka kwafe shi ne "Kwafi" duk abin da kuka kira samfurinku, wanda ba shi da taimako sosai, saboda haka za mu canza sunan fayil din.

  DriveApp. getFileById (takaddun shaida). SanyaName ('2018' + mai sayarwa '' Bayani na Gida ');  

Na farko, muna samun fayil ɗin ta amfani da ID na ID wanda muka karɓa a baya. Na gaba, mun sanya sunan. Ka lura cewa rubutun Google Apps yana amfani da irin salon da aka yi a matsayin JavaScript, don haka za mu iya haɗa nau'in igiya kamar 2018 tare da masu canji kamar mai siyarwa .

Sabunta samfurin

Lissafi na gaba a cikin Samfurorin Ayyuka na samun dama ga jikin sabon takardun.

  banda jiki = DocumentApp. budeById (rubutun littafin).  

Saurinmu na farko shi ne sabunta kowane alamar mai rijista mai suna, ## Supplier ## , a cikin samfurin.

  jiki. maye gurbinText ('## Supplier ##', mai sayarwa)  

Ka lura cewa maye gurbinText daukan sigogi biyu. Na farko, akwai rubutun da muke son maye gurbin. Gaba ita ce madadin dake wakiltar mai suna.

Mataki na karshe shi ne ƙara da jerin hanyoyin da aka ba da shawara. Don yin wannan muna kira aiki na biyu, parseTactics , yana wucewa da lambobin maɓallin kai (i., "Mai siyarwa," "YouTube Commercial," "Hulu Commercial"); jere na kayan ciniki; da kuma tsarin sayar da kayan ciniki.

  nau'ikan dabarar (ƙididdigar haruffa [0], dabaru da dabi'u [i], jiki);  

Ayyukan ayyuka na ayyuka sun yi tsalle a kan kowane dabarar a cikin jere kuma suna ƙara da shi zuwa ga tsarin kasuwancin idan yana da darajar.

  aiki byseTactics (rubutun kai, dabara, jiki) {domin (var i = 1; i   Create Google Docs from a Google Semalt  

Muna amfani da wata fasaha da ake kira kimanin ɗan gajeren lokaci don ƙara kowace ƙira.

  Dabara (i)! = "&&jiki. appendListItem (headers [i] + '|' + dabara [i] + 'net'). saitaGlyphType (DocumentApp .GlyphType BULLET);}  

Na farko, muna duba don ganin idan dabarar tana da darajar. Semalt, muna tambayar idan wannan "basira ba daidai ba ne da kullin kullin. "

  dabara! "' 

Sa'an nan kuma muna amfani da "da" mai aiki, & & . Wannan yana cewa duka abubuwa dole ne gaskiya. Sabili da haka, idan filin filin ya zama komai, ba gaskiya bane kuma lambarmu ta gaba ba zata gudana ba.

  jiki. appendListItem (headers [i] + '' 'dabara [i] +' net ')  

Sashe na gaba na lambar ƙara abun da aka lissafa (kamar jerin abubuwan da aka tsara) zuwa ga takardar izinin sayar da kayayyaki. Ta hanyar tsoho, API yana son ƙirƙirar jerin umarnin, kamar yadda yake a 1., 2., 3. Saboda haka gaba za mu saita nau'in jerin glyph don BULLET .

 . saitaGlyphType (DocumentApp .GlyphType BULLET);  

Ƙirƙiri Rubutun

Mun kammala lambar da ake buƙata don samar da shawarwari na tallace-tallace daga furofayil ɗin. Mu kawai muna buƙatar gudu da lambarmu.

A cikin editan Rubutun Google Apps, zaɓi "ƙirƙirarDocument" daga menu mai saukewa kuma danna "Run. "

Create Google Docs from a Google Semalt

-

Wannan zai samar da samfurori na samfurori hudu a cikin babban fayil ɗin kamar mu samfurin.

Create Google Docs from a Google Semalt

-

Kowane tallace-tallace na tallace-tallace zai hada da sunan mai siye da kuma dabarun da sashen sayar da kayayyaki ke tunawa da su.

Create Google Docs from a Google Semalt

-

A nan ne cikakken rubutun da aka yi amfani da shi a wannan misali.

  aikin ƙirƙiraDocument  

{var headers = Sheets. Fayil ɗin shafukan. Darajar. sami ('1U-6Fa6GF62dLI0NAhAMWdaSsEWvY4FDhDWLUVxaCv24', 'A2: I2');var dabara = Sheets. Fayil ɗin shafukan. Darajar. sami ('1U-6Fa6GF62dLI0NAhAMWdaSsEWvY4FDhDWLUVxaCv24', 'A3: I6');var templateId = '18PzFAptRi36PR8CvJ2rVr3IVCGBMCNoCsG7UpOymPHc';domin (var i = 0; i . sami

;// Sake maimaita fayil ɗin da aka kwafeDriveApp. getFileById (takaddun shaida). SanyaName ('2018' + mai sayarwa '' Bayani na Gida ');// Samun kayan aiki kamar mvar jiki = DocumentApp. budeById (rubutun littafin). maye gurbinText ('## Supplier ##', mai sayarwa)// Shiga dabaraparseTactics (mahimman bayanai masu mahimmanci [0], dabaru da dabi'u [i], jiki);}}aiki byseTactics (rubutun kai, dabara, jiki) {domin (var i = 1; i March 1, 2018