ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
µÚÈýµç×ÓÊé ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ77²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡


that¡¡Figure¡¡11¡­2¡¡uses¡¡¡¡generics¡¡to¡¡define¡¡worksheets¡¡of¡¡specific¡¡types£»¡¡which¡¡means¡¡mixed¡¡¡¡

types¡¡that¡¡need¡¡to¡¡be¡¡addressed¡¡by¡¡the¡¡workbook¡£¡¡In¡¡other¡¡words£»¡¡a¡¡workbook¡¡can¡¡contain¡¡only¡¡¡¡

spreadsheets¡¡of¡¡a¡¡certain¡¡type£»¡¡as¡¡in¡¡this¡¡example£º¡¡



Workbook£¨Of¡¡String£©¡¡workbook1¡¡

Workbook£¨Of¡¡Double£©¡¡workbook2¡¡



¡¡¡¡¡¡¡¡¡¡It¡¡would¡¡seem¡¡that¡¡¡¡generics¡¡make¡¡everything¡¡more¡¡plicated¡£¡¡However£»¡¡there¡¯s¡¡¡¡

more¡¡to¡¡this¡¡than¡¡first¡¡appears¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡generics¡¡have¡¡not¡¡made¡¡things¡¡more¡¡plicated£»¡¡but¡¡rather¡¡have¡¡required¡¡us¡¡to¡¡be¡¡¡¡

more¡¡explicit¡¡about¡¡what¡¡we¡¡actually¡¡want¡¡to¡¡do¡£¡¡We¡¡want¡¡to¡¡be¡¡able¡¡to¡¡define¡¡specific¡¡work

sheet¡¡types£»¡¡which¡¡means¡¡we¡¡have¡¡a¡¡mixed¡¡list¡¡of¡¡types¡¡that¡¡the¡¡workbook¡¡must¡¡manage¡£¡¡As¡¡¡¡

explained¡¡in¡¡Chapter¡¡9£»¡¡non¡­¡¡generics¡¡list¡¡types¡¡cannot¡¡control¡¡whether¡¡or¡¡not¡¡a¡¡list¡¡contains¡¡¡¡

mixed¡¡types¡£¡¡

¡¡¡¡¡¡¡¡¡¡To¡¡solve¡¡the¡¡worksheet¡¡problem£»¡¡we¡¡need¡¡to¡¡put¡¡on¡¡our¡¡object¡­oriented¡¡thinking¡¡caps¡£¡¡¡¡

First£»¡¡what¡¡is¡¡a¡¡worksheet£¿¡¡It¡¯s¡¡a¡¡spreadsheet¡¡that¡¡fulfills¡¡the¡¡role¡¡of¡¡a¡¡two¡­dimensional¡¡thing£»¡¡¡¡

and¡¡it¡¡applies¡¡to¡¡all¡¡worksheets¡¡regardless¡¡of¡¡types¡£¡¡Therefore£»¡¡the¡¡first¡¡interface¡¡to¡¡define¡¡is¡¡a¡¡¡¡

base¡¡worksheet£»¡¡as¡¡follows¡¡£¨do¡¡this¡¡in¡¡the¡¡ServerSideSpreadsheet¡¡project£»¡¡as¡¡well¡¡as¡¡adding¡¡a¡¡¡¡

reference¡¡to¡¡the¡¡Devspace¡£Trader¡£mon¡¡project£©£º¡¡



Imports¡¡Devspace¡£Trader¡£mon¡¡



Public¡¡Interface¡¡IWorksheetBase¡¡

¡¡¡¡¡¡¡¡Inherits¡¡IDebug¡¡

¡¡¡¡¡¡¡¡Sub¡¡Dimension£¨ByVal¡¡rows¡¡As¡¡Integer£»¡¡ByVal¡¡cols¡¡As¡¡Integer£©¡¡

¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡MaxCols£¨£©¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡MaxRows£¨£©¡¡As¡¡Integer¡¡

End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡interface¡¡definition¡¡of¡¡IWorksheetBase¡¡has¡¡one¡¡method¡¡and¡¡two¡¡properties¡£¡¡The¡¡method¡¡¡¡

Dimension£¨£©¡¡is¡¡used¡¡to¡¡assign¡¡the¡¡maximum¡¡rows¡¡and¡¡columns¡¡of¡¡the¡¡individual¡¡spreadsheet¡£¡¡¡¡

The¡¡properties¡¡MaxRows¡¡and¡¡MaxCols¡¡return¡¡the¡¡maximum¡¡rows¡¡and¡¡columns¡£¡¡The¡¡properties¡¡¡¡

and¡¡method¡¡have¡¡nothing¡¡to¡¡do¡¡with¡¡the¡¡specific¡¡type¡¡managed¡¡by¡¡the¡¡worksheet£»¡¡but¡¡the¡¡inter

face¡¡manages¡¡to¡¡uniquely¡¡identify¡¡the¡¡instance¡¡as¡¡being¡¡a¡¡type¡¡of¡¡spreadsheet¡£¡¡

¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡workbook¡¡code£»¡¡the¡¡list¡¡of¡¡worksheets¡¡would¡¡be¡¡defined¡¡as¡¡follows£º¡¡



Private¡¡_worksheets¡¡As¡¡IDictionary£¨Of¡¡String£»¡¡IWorksheetBase£©¡¡=¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡New¡¡Dictionary£¨Of¡¡String£»¡¡IWorksheetBase£©¡¡



¡¡¡¡¡¡¡¡¡¡Now¡¡the¡¡workbook¡¡knows¡¡it¡¡has¡¡a¡¡series¡¡of¡¡worksheets£»¡¡but¡¡the¡¡workbook¡¡does¡¡not¡¡know¡¡¡¡

or¡¡care¡¡about¡¡the¡¡types¡¡of¡¡the¡¡worksheets¡£¡¡When¡¡users¡¡of¡¡the¡¡workbook¡¡want¡¡to¡¡manipulate¡¡an¡¡¡¡

individual¡¡worksheet£»¡¡they¡¡can¡¡retrieve¡¡the¡¡worksheet¡¡from¡¡the¡¡workbook£»¡¡but¡¡the¡¡users¡¡need¡¡¡¡

to¡¡know¡¡the¡¡worksheet¡¯s¡¡type¡£¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡spreadsheet¡¡is¡¡typically¡¡addressed¡¡using¡¡rows¡¡and¡¡columns£»¡¡but¡¡to¡¡simplify¡¡declara

tions£»¡¡there¡¡is¡¡also¡¡the¡¡ability¡¡to¡¡define¡¡something¡¡called¡¡the¡¡SheetCoordinate£»¡¡which¡¡is¡¡a¡¡type¡¡¡¡

that¡¡has¡¡a¡¡row¡¡and¡¡column¡£¡¡The¡¡SheetCoordinate¡¡is¡¡defined¡¡in¡¡ServerSideSpreadsheet¡¡as¡¡follows£º¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡318¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

296¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Structure¡¡SheetCoordinate¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Row¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Column¡¡As¡¡Integer¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Sub¡¡New£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡column¡¡As¡¡Integer£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡£¨row¡¡¡¶¡¡0£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Throw¡¡New¡¡ArgumentOutOfRangeException£¨¡¨Row¡¡is¡¡below¡¡zero¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡£¨column¡¡¡¶¡¡0£©¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Throw¡¡New¡¡ArgumentOutOfRangeException£¨¡¨Column¡¡is¡¡below¡¡zero¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Me¡£Row¡¡=¡¡row¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Me¡£Column¡¡=¡¡column¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Sub¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡OneUp£¨£©¡¡As¡¡SheetCoordinate¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡SheetCoordinate£¨£¨Me¡£Row¡¡1£©£»¡¡Me¡£Column£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡OneDown£¨£©¡¡As¡¡SheetCoordinate¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡SheetCoordinate£¨£¨Me¡£Row¡¡£«¡¡1£©£»¡¡Me¡£Column£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡OneLeft£¨£©¡¡As¡¡SheetCoordinate¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡SheetCoordinate£¨Me¡£Row£»¡¡£¨Me¡£Column¡¡1£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡ReadOnly¡¡Property¡¡OneRight£¨£©¡¡As¡¡SheetCoordinate¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡New¡¡SheetCoordinate£¨Me¡£Row£»¡¡£¨Me¡£Column¡¡£«¡¡1£©£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Get¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Property¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Structure¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡declaration¡¡of¡¡SheetCoordinate£»¡¡notice¡¡that¡¡Structure¡¡is¡¡used¡¡rather¡¡than¡¡Class¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡We¡¡could¡¡have¡¡used¡¡a¡¡class£»¡¡but¡¡SheetCoordinate¡¡serves¡¡the¡¡purpose¡¡of¡¡being¡¡a¡¡piece¡¡of¡¡data¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡SheetCoordinate¡¡is¡¡a¡¡type¡¡where¡¡you¡¡store¡¡information¡¡that¡¡is¡¡used¡¡by¡¡another¡¡type¡£¡¡A¡¡data¡¡type¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡might¡¡do¡¡some¡¡processing£»¡¡but¡¡only¡¡to¡¡make¡¡it¡¡easier¡¡to¡¡manipulate¡¡the¡¡data¡£¡¡For¡¡example£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡notice¡¡how¡¡SheetCoordinate¡¡has¡¡properties¡¡to¡¡generate¡¡a¡¡new¡¡instance¡¡of¡¡SheetCoordinate¡¡that¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡might¡¡be¡¡one¡¡row¡¡higher¡¡or¡¡lower£»¡¡or¡¡a¡¡column¡¡to¡¡the¡¡right¡¡or¡¡left¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡next¡¡step¡¡is¡¡to¡¡extend¡¡the¡¡worksheet¡¡definition¡¡and¡¡use¡¡¡¡generics¡¡to¡¡define¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡of¡¡worksheet¡£¡¡The¡¡following¡¡is¡¡the¡¡plete¡¡definition¡¡of¡¡the¡¡¡¡IWorksheet¡£¡¡These¡¡methods¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡319¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡297¡¡



are¡¡used¡¡to¡¡calculate¡¡the¡¡values¡¡of¡¡cells¡¡in¡¡the¡¡worksheet¡¡and¡¡work¡¡with¡¡the¡¡contents¡¡of¡¡individual¡¡¡¡

cells¡¡£¨the¡¡state¡¡of¡¡those¡¡cells£©¡£¡¡We¡¡can¡¡also¡¡assign¡¡the¡¡function¡¡that¡¡carries¡¡out¡¡the¡¡calculation¡¡of¡¡¡¡

a¡¡cell¡¯s¡¡contents£»¡¡using¡¡either¡¡a¡¡SheetCoordinate¡¡type¡¡or¡¡the¡¡row¡¡and¡¡column¡¡coordinates¡£¡¡



Public¡¡Interface¡¡IWorksheet£¨Of¡¡BaseType£©¡¡

¡¡¡¡¡¡¡¡Inherits¡¡IWorksheetBase¡¡



¡¡¡¡¡¡¡¡Sub¡¡AssignCellCalculation£¨ByVal¡¡coords¡¡As¡¡SheetCoordinate£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡cb¡¡As¡¡Func£¨Of¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡Integer£»¡¡Integer£»¡¡BaseType£©£©¡¡



¡¡¡¡¡¡¡¡Sub¡¡AssignCellCalculation£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡col¡¡As¡¡Integer£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡cb¡¡As¡¡Func£¨Of¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡Integer£»¡¡Integer£»¡¡BaseType£©£©¡¡



¡¡¡¡¡¡¡¡Sub¡¡AssignColCalculation£¨ByVal¡¡col¡¡As¡¡Integer£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡cb¡¡As¡¡Func£¨Of¡¡IWorksheet£¨Of¡¡BaseType£©£»¡¡_¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Integer£»¡¡Integer£»¡¡BaseType£©£©¡¡

¡¡¡¡¡¡¡¡Sub¡¡Calculate£¨£©¡¡



¡¡¡¡¡¡¡¡Function¡¡Calculate£¨ByVal¡¡coords¡¡As¡¡SheetCoordinate£©¡¡As¡¡BaseType¡¡

¡¡¡¡¡¡¡¡¡¡

¡¡¡¡¡¡¡¡Function¡¡Calculate£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡col¡¡As¡¡Integer£©¡¡As¡¡BaseType¡¡



¡¡¡¡¡¡¡¡Sub¡¡CalculateCol£¨ByVal¡¡col¡¡As¡¡Integer£©¡¡



¡¡¡¡¡¡¡¡Sub¡¡CalculateRow£¨ByVal¡¡row¡¡As¡¡Integer£©¡¡



¡¡¡¡¡¡¡¡Function¡¡GetCellState£¨ByVal¡¡coords¡¡As¡¡SheetCoordinate£©¡¡As¡¡BaseType¡¡



¡¡¡¡¡¡¡¡Function¡¡GetCellState£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡col¡¡As¡¡Integer£©¡¡As¡¡BaseType¡¡



¡¡¡¡¡¡¡¡Sub¡¡SetCellState£¨ByVal¡¡coords¡¡As¡¡SheetCoordinate£»¡¡ByVal¡¡val¡¡As¡¡BaseType£©¡¡



¡¡¡¡¡¡¡¡Sub¡¡SetCellState£¨ByVal¡¡row¡¡As¡¡Integer£»¡¡ByVal¡¡col¡¡As¡¡Integer£»¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ByVal¡¡val¡¡As¡¡BaseType£©¡¡



¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Data£¨£©¡¡As¡¡BaseType¡¡£¨£»£©¡¡

End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡declaration¡¡of¡¡IWorksheet¡¡is¡¡as¡¡a¡¡¡¡generics¡¡type£»¡¡where¡¡BaseType¡¡is¡¡a¡¡¡¡generics¡¡¡¡

parameter¡¡that¡¡represents¡¡the¡¡type¡¡of¡¡the¡¡spreadsheet¡£¡¡Since¡¡IWorksheet¡¡is¡¡a¡¡type¡¡of¡¡spreadsheet£»¡¡¡¡

it¡¡subclasses¡¡the¡¡IWorksheetBase¡¡interface£»¡¡allowing¡¡IWorksheet¡¡to¡¡be¡¡part¡¡of¡¡a¡¡mixed¡¡collection¡¡¡¡

of¡¡IWorksheet¡¡instances¡£¡¡The¡¡IWorksheet¡¡interface¡¡is¡¡fairly¡¡plex¡¡and¡¡contains¡¡many¡¡methods¡£¡¡¡¡

However£»¡¡here¡¡we¡¡are¡¡focusing¡¡on¡¡the¡¡interface¡¡concept£»¡¡rather¡¡than¡¡the¡¡individual¡¡methods¡£¡¡

¡¡¡¡¡¡¡¡¡¡Look¡¡at¡¡the¡¡bolded¡¡parts¡¡and¡¡notice¡¡how¡¡the¡¡interface¡¡is¡¡specific¡¡about¡¡the¡¡operations£»¡¡but¡¡¡¡

vague¡¡about¡¡the¡¡type¡¡used¡¡in¡¡the¡¡operations¡£¡¡This¡¡is¡¡what¡¡you¡¡want¡¡to¡¡achieve¡¡when¡¡using¡¡¡¡¡¡

generics¡£¡¡You¡¡want¡¡to¡¡take¡¡a¡¡high¡­level¡¡approach¡¡and¡¡indicate¡¡which¡¡operations¡¡are¡¡available£»¡¡¡¡

but¡¡leave¡¡out¡¡the¡¡types¡¡being¡¡manipulated¡¡in¡¡the¡¡operations¡£¡¡The¡¡types¡¡will¡¡be¡¡specified¡¡later¡¡by¡¡¡¡

another¡¡programmer¡£¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡320¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

298¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡1¡¡1¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡I¡¡N¡¡G¡¡¡¡¡¡A¡¡B¡¡OU¡¡T¡¡¡¡¡¡¡£¡¡N¡¡E¡¡T¡¡¡¡G¡¡E¡¡N¡¡E¡¡R¡¡I¡¡CS¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡technique¡¡of¡¡having¡¡a¡¡¡¡generics¡¡type¡¡£¨such¡¡as¡¡IWorksheet£©¡¡subclass¡¡a¡¡non¡­¡¡generics¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡type¡¡£¨such¡¡as¡¡¡¡IWorksheetBase£©¡¡allows¡¡you¡¡to¡¡identify¡¡the¡¡general¡¡type¡¡that¡¡you¡¡are¡¡trying¡¡to¡¡describe¡¡with¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡some¡¡specialization¡¡in¡¡the¡¡¡¡generics¡¡type¡¡declaration¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Defining¡¡the¡¡IWorkbook¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Now¡¡that¡¡we¡¯ve¡¡pleted¡¡the¡¡IWorksheet£¨Of¡¡BaseType£©¡¡and¡¡¡¡IWorksheetBase¡¡interfaces£»¡¡we¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡can¡¡define¡¡the¡¡workbook¡¡interface¡£¡¡The¡¡workbook¡¡interface¡¡will¡¡not¡¡be¡¡a¡¡¡¡generics¡¡type£»¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡since¡¡a¡¡workbook¡¡will¡¡contain¡¡multiple¡¡worksheet¡¡types¡£¡¡However£»¡¡as¡¡you¡¡will¡¡see£»¡¡we¡¡can¡¡optimize¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡this¡¡interface¡¡to¡¡make¡¡it¡¡easier¡¡to¡¡use¡¡the¡¡workbook¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡For¡¡the¡¡moment£»¡¡let¡¯s¡¡consider¡¡the¡¡plain¡­vanilla¡¡IWorkbook¡¡interface¡¡with¡¡no¡¡¡¡generics¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡types£»¡¡which¡¡is¡¡defined¡¡as¡¡follows¡¡in¡¡the¡¡ServerSideSpreadsheet£º¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡System¡£Reflection¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Imports¡¡Devspace¡£Trader¡£mon¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Interface¡¡IWorkbook¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Inherits¡¡IDebug¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ReadOnly¡¡Property¡¡Identifier£¨£©¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Default¡¡Property¡¡Item£¨ByVal¡¡identifier¡¡As¡¡String£©¡¡As¡¡IWorksheetBase¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Interface¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡IWorkbook¡¡interface¡¡defines¡¡an¡¡Identifier¡¡property¡¡and¡¡a¡¡default¡¡property¡¡Item¡£¡¡Notice¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡how¡¡the¡¡attribute¡¡DefaultMember¡¡is¡¡defined¡¡to¡¡indicate¡¡the¡¡default¡¡property¡¡identifier¡¡£¨it¡¡is¡¡from¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡System¡£Reflection¡¡namespace£©¡£¡¡Any¡¡class¡¡that¡¡implements¡¡IWorkbook¡¡is¡¡expected¡¡to¡¡contain¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡multiple¡¡references¡¡to¡¡IWorksheet£¨Of¡¡BaseType£©¡¡instances¡£¡¡How¡¡those¡¡references¡¡are¡¡managed¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡not¡¡the¡¡responsibility¡¡of¡¡the¡¡IWorkbook¡¡interface£»¡¡but¡¡of¡¡the¡¡IWorkbook¡¡interface¡¡implementation¡£¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡öNote¡¡¡¡The¡¡IWorkbook¡¡interface¡¡does¡¡not¡¡provide¡¡a¡¡Clear£¨£©¡¡method¡¡to¡¡reset¡¡the¡¡workbook¡¡and¡¡delete¡¡all¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡of¡¡the¡¡referenced¡¡worksheets¡£¡¡It¡¡would¡¡seem¡¡logical¡¡to¡¡have¡¡a¡¡Clear£¨£©¡¡method£»¡¡but¡¡in¡¡a¡¡garbage¡­collected¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡environment£»¡¡that¡¯s¡¡pletely¡¡unnecessary¡£¡¡If¡¡you¡¡don¡¯t¡¡want¡¡to¡¡use¡¡a¡¡workbook¡¡anymore£»¡¡just¡¡don¡¯t¡¡refer

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ence¡¡it£»¡¡and¡¡the¡¡garbage¡¡collector¡¡will¡¡take¡¡care¡¡of¡¡the¡¡rest¡£¡¡Think¡¡of¡¡it¡¡as¡¡having¡¡the¡¡option¡¡of¡¡serving¡¡dinner¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡to¡¡your¡¡guests¡¡on¡¡real¡¡plates¡¡or¡¡paper¡¡plates¡£¡¡Real¡¡plates¡¡might¡¡seem¡¡better£»¡¡but¡¡they¡¡break¡¡and¡¡you¡¡need¡¡to¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡wash¡¡them¡£¡¡Paper¡¡plates¡¡are¡¡used¡¡once¡¡and¡¡thrown¡¡away¡£¡¡Of¡¡course£»¡¡with¡¡paper¡¡plates¡¡you¡¡have¡¡recycling¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡issues¡¡that¡¡you¡¡don¡¯t¡¡have¡¡in¡¡£»¡¡because¡¡the¡¡memory¡¡is¡¡recycled¡¡for¡¡you¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡The¡¡property¡¡¡¡Identifier¡¡identifies¡¡the¡¡workbook¡¡represented¡¡by¡¡the¡¡current¡¡¡¡IWorkbook¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡object¡£¡¡The¡¡identifier¡¡might¡¡be¡¡a¡¡path¡¡or¡¡file¡¡name¡¡and¡¡is¡¡pletely¡¡dependent¡¡on¡¡the¡¡im
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨0£© ²È£¨0£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡