Tải bản đầy đủ - 0 (trang)
Chapter 14. Sharing Data Using Lists

Chapter 14. Sharing Data Using Lists

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

XMLdatacanbeimporteddirectlyintoalist.

Excelautomaticallychecksthedatatypeoflistentriesas

theyaremade.

Listscanbesharedandsynchronizedwithteammatesvia

MicrosoftSharePointServices.

Thatlastitemisthekeyadvantageoflistsreally,listsarejusta

waytoshareinformationthatfitsintocolumnsandrows.

Thischaptercontainsreferenceinformationforthefollowing

objectsandtheirrelatedcollections:ListObject,ListRow,

ListColumn,ListDataFormat,andtheSharePointListsWebService.



Codeusedinthischapterandadditionalsamplesareavailablein

ch14.xls.



14.1.UseLists

Listsreflectarangeofcellswithinaworkbook,ratherthanthe

entireworkbookfileitself.Bysharingonlythegermanerangeof

cells,youavoidpublishingtheunderlyingdataandmacros,

whichprotectstheoriginal.Thesharedlistcanthenbeincluded

indifferentworkbooksusedbyothers.

Themainlimitationoflistsisthattheycanbesharedonly

throughWindowsServer2003runningSharePointServices.

That'sbecausethesharingandmaintenanceoflistsisprovided

throughtheASP.NETActiveServerPagesandWebServicesthat

SharePointprovides.Othertypesofnetworksharesaresimply

notsupported.Anotherlessimportanthitchisthatyoucan't

includeasharedlistinasharedworkbook.Ifyouwanttoadda

listtoasharedworkbook,youfirstneedtoconvertthe

workbooktosingle-user.

Ifyoudon'thaveaWindows2003serveratyoursite,youcan

tryoutSharePointServicesthroughahostingprovider,suchas

ApptixorVerio.Checkouthttp://www.sharepointtrial.comfora

freetrial.

Whenalistispublished,SharePointServicescreatesanActive

ServerPagethatteammatescanusetoviewormodifythelist's

data,asshowninFigure14-2.

SharePointServicesstoreslistsasXMLfiles.Eachlisthastwo

differentsortsofXML:XMLthatdescribesthelistandprovides

itsuserinterfaceandXMLthatcontainsthelistdata.Youcan

editorlinktoalistthroughitsASPXpage,oryoucanusethe

SharePointListsWebServicetoaccessthelistdirectlythrough

code.



14.1.1.SupportedDataTypes



Excellistscancontainonlydatathatcanbeeasilyrepresented

asXML.Objectssuchascharts,diagrams,andOLEobjects

cannotbeincludedinlists.Excelformulasareevaluatedand

convertedtoanumericvaluewhenalistissynchronized.

Fornumericdata,leadingandtrailingzerosareomittedand

positivevaluesaredisplayedwithoutaplussign(+)regardless

ofwhetherornotitwasentered.Excelprovidesupto15

significantdigitsofprecision.



Figure14-2.SharePointServicesprovidesan

ASPXpagetoviewandmanagealist



Finally,thefollowingExceldate/timeformatsarenotdirectly

supportedandareconvertedtotextoncealistissynchronized:



hh:mm:ssZ

Hh:mm:ss.f-f

yyyy-mm-ddThh:mm:ssZ

yyyy-mm-ddThh:mm:ss+/-hh:mm

yyyy-mm-ddThh:mm:ss.f-f

yyyy-mm-ddZ

yyyy-mm-dd+/-hh:mm

yyyy+/-hh:mm

yyyy-mm+/-hh:mm



14.1.2.ResolveConflicts

Sincelistscan'tincludeformulasorobjects,theyarebest

suitedtosharingtwoclassesofinformationfromExcel:

Resultsofcalculatedorsummarizedinformation

Detailinformationforsummaryorcalculationonclients

Inthefirstcase,anauthormaycollectinformation,generate

someresults,thensharethoseresultsforreviewbyothers.

Alternately,alistmayconsistofrawdatawithoneormore

authorscontributingitems.Thoseauthorsandadditionalusers

mayreadthelistandsummarizeorfilterthelistinmany

differentworkbooks.

Inamany-to-manyrelationship,morethanoneauthormay

changeaparticularcell.Whenthisoccurs,thesecondauthorto

synchronizeherlistseestheResolveConflictsandErrorsdialog,

showninFigure14-3.



Figure14-3.Whentwoauthorschangethesame

cell,thesecondauthortosynchronizemust

decidewhattodo



14.1.3.AuthorizationandAuthenticationin

SharedLists

InordertosharealistthroughSharePointServices,anauthor

musthaveprivilegesontheSharePointserver.SharePoint

providesaneasy-to-useinterfaceforaddingusersand

maintainingtheirpasswords,showninFigure14-4.

WhenausersharesalistfromExcel,SharePointauthenticates

theuserwiththeConnectdialogbox,showninFigure14-5.

Oncetheuserisauthenticated,Excelmaintainsasessionfor

theuserforaperiodoftimedeterminedbytheSharePoint

settingssothattheuserdoesn'thavetosigninagainevery

timeheaccessesasharedlist.WhentheuserclosesExcel,his

SharePointsessionisendedandhewillbereauthenticatedifhe

startsExcelandaccessesasharedlistagain.

Thesesamerulesapplywhethertheuserisaccessingashared

listthroughtheExceluserinterfaceorthroughVisualBasic



code.



Figure14-4.UsetheSharePointAddUserspage

toaddnewuseraccountsandsetuserprivileges



Figure14-5.SharePointauthenticatesusers

beforeconnectingtoasharedlist



14.1.4.CreateaListinCode

UsetheAddmethodoftheListObjectscollectiontocreatealistin

code.TheListObjectscollectionisexposedasapropertyofthe

Worksheetobject.Thefollowingcodecreatesanewlistforallthe

contiguousdatastartingwiththeactivecell:

ActiveWorksheet.ListObjects.Add



UsetheAddmethod'sargumentstocreatealistoutofaspecific

rangeofcells.Forexample,thefollowingcodecreatesalistout

oftherangeA2:D5:

SubCreateList1()

DimwsAsWorksheet,rngAsRange

Setws=ActiveSheet

Setrng=ws.Range("A2:D5")

ws.ListObjects.AddxlSrcRange,rng

EndSub



WhenExcelcreatestheprecedinglist,itautomaticallyadds

columnheadingstothelisteitherbyconvertingthefirstrow

intocolumnheadingsorbyaddinganewrowandshiftingthe

subsequentdatarowsdown.It'shardtoknowexactlywhatwill

happenbecauseExcelevaluateshowthefirstrowisintended.

YoucanavoidthisassumptionbysupplyingtheHasHeaders

argument,asshownhere:

ws.ListObjects.AddxlSrcRange,rng,,xlNo



Now,theprecedingcodeaddsheaderstorow2andshiftsthe

rangedownonerow.

Listsalwaysincludecolumnheaders.Toavoidshiftingtherange

downoneroweachtimeyoucreatealist,includeablankrow

atthetopofthesourcerangeandspecifyxlYesforHasHeadersas

shownhere:

SubCreateList2()

DimwsAsWorksheet,rngAsRange

Setws=ActiveSheet

Setrng=ws.Range("A1:D5")

'Usefirstrowasheaders.

ws.ListObjects.AddxlSrcRange,rng,,xlYes

EndSub



Sincecolumnheadersandnewrowsaddedtoalistcausethe

subsequentrowstoshiftdown,itisagoodideatoavoidplacing

dataorotheritemsintherowsbelowalist.Ifyoudoplace

itemsthere,youreceiveawarninganytimethelistexpands.



Whencreatinglistsincode,itisalsoagoodideatonamethe

listsothatsubsequentreferencestothelistcanuseitsname

ratherthanitsindexontheworksheet.Tonamealist,setthe

NamepropertyoftheListObject:

SubCreateList3()

DimwsAsWorksheet,rngAsRange,lstAsListObject

Setws=ActiveSheet

Setrng=ws.Range("A1:D5")

'Usefirstrowasheaders.

Setlst=ws.ListObjects.Add(xlSrcRange,rng,,xlYes)

'Namelist

lst.Name="TestList"

EndSub



Now,youcangetareferencetothenamedlistusingthe

Worksheetobject'sListObjectsproperty:

SubToggleTotals()

DimwsAsWorksheet,lstAsListObject

Setws=ActiveSheet

'Getnamedlist.

Setlst=ws.ListObjects("TestList")

'Turntotalson/off.

lst.ShowTotals=Notlst.ShowTotals

EndSub



14.1.5.ShareaList

Oncealistexistsonaworksheet,youcansharethatlistusing

thePublishmethod.ThefirstargumentofthePublishmethodisa

three-elementstringarraycontainingtheaddressofthe



SharePointserver,auniquenameforthelist,andanoptional

descriptionofthelist.Forexample,thefollowingcodepublishes

thelistcreatedintheprecedingsection:



SubShareList()

DimwsAsWorksheet,lstAsListObject

DimstrAsString,dest(2)AsVariant

Setws=ActiveSheet

Setlst=ws.ListObjects("TestList")

dest(0)="http://www.excelworkshop.com"

dest(1)="TestList"

dest(2)="Adescriptiongoeshere..."

str=lst.Publish(dest,True)

MsgBox"Yourlisthasbeenshared.Youcanviewitat:"&

EndSub



ThePublishmethodreturnsastringcontainingtheaddressof

thepublishedlist.Theprecedingcodedisplaysthataddressina

messagebox,butyoumaywanttonavigatetothataddressor

includealinktoitsomewhereonthesheet.Toaddahyperlink

tothelistontheSharePointserver,addahyperlinktoarange

asshownhere:

'Addlinkinsteadofshowingmessagebox.

DimlnkAsHyperlink

Setlnk=ws.Hyperlinks.Add([F1],str)



Afteraddingthehyperlink,youcandisplaythewebpageforthe

listbyusingtheFollowmethodasshownhere:

'Displaythesharedlistinthebrowser.

lnk.Follow



Tonavigatetothelistwithoutaddingahyperlink,usethe

Workbookobject'sFollowHyperlinkmethod:

'OrusetheFollowHyperlinkmethod.

ThisWorkbook.FollowHyperlinkstr



TheListObject'sSharePointURLpropertyreturnstheaddressofthe

list,soitiseasytogettheaddressofthesharedlistafterithas

beencreated,asshownhere:

SubAddLink()

DimwsAsWorksheet,strAsString,lnkAsHyperlink

Setws=ActiveSheet

str=ws.ListObjects("TestList").SharePointURL

Setlnk=ws.Hyperlinks.Add([F1],str,,_

"Clicktodisplaylistsite.","View")

EndSub



14.1.6.InsertaSharedList

OncealistispublishedonaSharePointsite,youcaninsertthat

listintootherworksheetsusingtheListObject'sAddmethodand

theSourceTypeargumentxlSrcExternal:

SubInsertSharedList()

DimwsAsWorksheet,src(1)AsVariant

Setws=ThisWorkbook.Worksheets.Add(,ActiveSheet)

ws.Name="InsertList"

src(0)="http://www.excelworkshop.com/_vti_bin"

src(1)="TestList"



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

Chapter 14. Sharing Data Using Lists

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

×