Tải bản đầy đủ - 0 (trang)
Hack 28. Format Cells According to Their Values

Hack 28. Format Cells According to Their Values

Tải bản đầy đủ - 0trang

Conditionalformattingcanhelpyouvisualizerangesofnumbers

inlongerlistings.Let'screateanewcolumntotherighttitled

"Yearlyincomein荤"andaddvaluesforaverageincometothe

newslettersubscriberlist.Supposethatyouwanttocolorlower

incomesinredandhigherincomesingreen—andeveryincome

figureinbetweenusingsomeothercolor.

TheGoogleSpreadsheetscontextmenuofferstoletyou

changethecellformattingbasedoncustomrules





Addingaspecialformattingruleforyoungernewsletter

subscribers



Asampleimageservesascolorreference



Tohelpmepicktherightin-betweencolors,Icreateda

referencecolorgradientbetweenredandgreenusingapaint

programthatIreferredtoasIsetuptheformattingrules.You

canusemanydifferentimageeditorsforthispurpose,like

Photoshop,PhotoPaint,GIMP,orPaintShopPro(whichyousee

inFigure3-31).Youcan,ofcourse,simplywingitandnot

generateagradientatall.

Nowyoucanselectyourincomedatacellsandaddalltherules

youneed.GoogleSpreadsheetswillapplythefirstruleitfinds

tobetrue,ignoringsubsequentonesdownthelist,soyoucan

simplydefinetherulesinthefollowingorder,foraresultas

showninFigure3-32:

Greaterthan120,000:uselightgreen

Greaterthan60,000:usegreen

Greaterthan30,000:useyellow/lightorange

Greaterthan10,000:useorange

Greaterthan-1:usered

Creatingacolorgradientforyourspreadsheet



Hack29.ConvertCurrenciesWithinYour

Spreadsheet

Usealittlescreenscrapingmagictoconvertonecurrencyinto

anyother.

GoogleSpreadsheets'importXmlfunctionpullsexternalweb

sitedataintoyourspreadsheet[Hack#27].Youcanusethis

featureforcurrencyconversion,too.

Supposethatyouhaveatablewithpaymentsmadetoyoufrom

avarietyofcompanies,justlikethesampletableshownin

Figure3-33.Therearethreecolumns:Company,USD,and

EUR.ThesamplepaymentsareprovidedinUSD;Universal

Exports,forinstance,paid$200.Itwouldbetediousifyouhad

toconvertthevaluesintoEurosmanuallyforeveryrow,but

there'sawaytoautomatethis.

First,youneedtofindagoodonlinecurrencyconvertertouse

fortheimportXmlfunction.Torecap,theGoogleSpreadsheets

importXmlformulausestwoparameters:

=importXml(URL,XPath)

There'savarietyofcurrencyconverters,butyoumustpickone

thatcanbeaccessedusingURLparameters(sothatyoucan

provideaURLcontainingthedollaramountandthe"from"and

"to"currenciestotheimportXmlfunction),andthatalsoreturns

HTMLthatiseasytoparse(becauseyouwillneedtowritea

littleXPathquerytoretrievetheresult).Google,toohas

currencyconversioninsearchresults,buttheyarenotalways

formattedplainlyenough.However,aservicefromYahoo!

Financefitsyourneedsperfectly.AURLlikethefollowingone:



http://finance.yahoo.com/currency/convert?amt=750&from=USD&to=E



returnsaresultasshowninFigure3-34.Theconversionresults



areembeddedinanHTMLtableoftheclass

"yfnc_datamodoutline1."ThiscontainstheEurovalueinthe

secondrow,thirdcolumn(508.5435inFigure3-34).Hence,the

XPathtoqueryforthisnumberis:

//table[@class='yfnc_datamodoutline1']//tr[2]//td[5]



ThecompleteimportXmlfunctioncallis(thisshouldallbekept

ononeline):

CodeView:



=importXml("http://finance.yahoo.com/currency/convert?amt=750&f

"//table[@class='yfnc_datamodoutline1']//tr[2]//td[5]")

























Tomaketheformulamoreflexible,youneedtoreplacethe

values750,USD,andEURwiththeirrespectivecellnames,as

shownhereforthe"AcmeInc"row:

CodeView:



=importXml("http://finance.yahoo.com/currency/convert?amt="&

&"&to="&C1,"//table[@class='yfnc_datamodoutline1']//tr[2]//

























Repeatthisformulaforalltheothercellsinyourspreadsheet,

usingthecorrectcellnames.

Theoriginaltabledoesnotinclude荤valuesyet



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 28. Format Cells According to Their Values

Tải bản đầy đủ ngay(0 tr)

×