重慶諾懷軟件有限公司 軟件開發(fā), app開發(fā), 微信開發(fā), 小程序開發(fā) - 開口協(xié)議 http://www.redheartclinic.com/blogtag/%E5%BC%80%E5%8F%A3%E5%8D%8F%E8%AE%AE zh-hans 固定總價(jià)合同 vs 工料合同 http://www.redheartclinic.com/blog/%E5%9B%BA%E5%AE%9A%E6%80%BB%E4%BB%B7%E5%90%88%E5%90%8C-vs-%E5%B7%A5%E6%96%99%E5%90%88%E5%90%8C <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>??? 今天下午公司幾個(gè)同事一起討論了下如何跟客戶的合作模式以及如何選用合同類型的問題,我也有不少思考,就借機(jī)整理下自己在這方面的看法,希望能拋磚引玉。</p> <p>??? 在項(xiàng)目實(shí)踐中,我們跟客戶有很多種不同的合作方式,這些不同的合作方式通常也對(duì)應(yīng)著不同的合同類型。無論起什么名字,采取什么形式,從根本上來,就是兩種合同類型,一種是開口合同,一種是閉口的合同。在我們公司,開口合同以單價(jià)合同為代表(PMP中叫成本補(bǔ)償合同、工料合同),閉口合同以固定總價(jià)合同為典型。我想總結(jié)下這兩種合同各自的特點(diǎn)和適用場景。</p> <p>??? 要回答的問題是:當(dāng)一個(gè)客戶或項(xiàng)目過來時(shí),應(yīng)該如何選擇合同類型?最簡單合理的答案,就是看采用哪種類型的合同對(duì)項(xiàng)目最有利。那該如何判斷哪種合同對(duì)項(xiàng)目最有利呢?這就不得不先搞清楚這兩種合同類型各自的特點(diǎn),要先對(duì)他們做個(gè)對(duì)比,然后再根據(jù)項(xiàng)目本身的特點(diǎn)去選擇。</p> <div style="direction:ltr"> <table border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse; border-color:rgb(163, 163, 163); border-style:solid; border-width:1pt; direction:ltr; height:479px; width:395px"><tbody><tr><td style="background-color:#BFBFBF; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p><strong>項(xiàng)目</strong></p> </td> <td style="background-color:#BFBFBF; border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p class="rteindent1"><strong>固定總價(jià)合同</strong></p> </td> <td style="background-color:#BFBFBF; border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p><strong>單價(jià)合同</strong></p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>總價(jià)格</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>總價(jià)明確</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>單價(jià)明確,總價(jià)浮動(dòng)</p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>單位價(jià)格</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>相對(duì)較高</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>相對(duì)較低</p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>啟動(dòng)周期</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>前期準(zhǔn)備,長</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>立刻啟動(dòng),短</p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>項(xiàng)目范圍</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>非常明確</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>較為模糊</p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>響應(yīng)變化</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>嚴(yán)格控制,較弱</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>靈活應(yīng)變,很強(qiáng)</p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>發(fā)包方風(fēng)險(xiǎn)</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>較低</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>較高</p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>項(xiàng)目規(guī)模</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>中、小</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>大、中、小</p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>投資控制</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>總預(yù)算明確,強(qiáng)</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>月預(yù)算明確,弱</p> </td> </tr><tr><td style="background-color:#F2F2F2; border-color:#A3A3A3; vertical-align:top; width:.9833in"> <p>發(fā)包方要求</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.4416in"> <p>需要明確需求,高</p> </td> <td style="border-color:#A3A3A3; vertical-align:top; width:1.6437in"> <p>不需詳盡文檔,低</p> </td> </tr></tbody></table></div> <p>??? 顧名思義,固定總價(jià)合同的特點(diǎn)是有個(gè)明確的總價(jià)格。譬如雙方達(dá)成一致,說這個(gè)項(xiàng)目總價(jià)是100萬,這個(gè)價(jià)格會(huì)事先定好,寫在合同中,一般不發(fā)生變化。通常伴隨這個(gè)價(jià)格的,還有工期、質(zhì)量等方面的明確要求。說到這,有人就會(huì)產(chǎn)生疑問了,你這個(gè)100萬的價(jià)格,是如何給出的呢?這是個(gè)好問題。對(duì)固定總價(jià)項(xiàng)目來說,要給出一個(gè)明確的總報(bào)價(jià),是有前提的。它最大的前提就是項(xiàng)目(產(chǎn)品或服務(wù))的范圍能夠事先清晰地界定,就是說要做哪些事情,不做哪些事情,要提供哪些東西,不提供哪些東西,這些都要事先說清楚。舉個(gè)最簡單的例子,拿軟件項(xiàng)目來說,系統(tǒng)要不要跨平臺(tái),是否需要部署和培訓(xùn)服務(wù),要支持哪些瀏覽器,甚至是一個(gè)界面應(yīng)該如何布局,這些都會(huì)對(duì)工作量和價(jià)格產(chǎn)生不同的影響,事先不說清楚就難以確定總價(jià)格。如果范圍不先界定清楚就把價(jià)格定下來了,這非常容易造成后期的扯皮,對(duì)一個(gè)任務(wù)雙方往往各持一詞,一方說這個(gè)工作是不包含在最初報(bào)價(jià)中的因而要額外收費(fèi),另一方說這個(gè)是固定總價(jià)合同,要包干,所有的任務(wù)都不會(huì)額外付費(fèi),如此這般糾纏不清,不利于項(xiàng)目順利開展。由此可見,在固定總價(jià)合同中,是承包方承擔(dān)了較多的風(fēng)險(xiǎn),需求變更,意外事件等都會(huì)導(dǎo)致他們成本增加,但收入?yún)s是事先固定的。承包方也不傻,為了應(yīng)對(duì)這個(gè)風(fēng)險(xiǎn),通常會(huì)在固定總價(jià)合同中,增加一筆風(fēng)險(xiǎn)儲(chǔ)備金,這也容易理解,因?yàn)樗械捻?xiàng)目都或多或少存在一些不確定性,總有一些意料之外的事情發(fā)生。而人們也都能接受給承擔(dān)更高的風(fēng)險(xiǎn)一方以更高的回報(bào)。這一來,如果換算成單價(jià)的話,固定總價(jià)合同的平均單價(jià),通常會(huì)比較高,這是它的另一個(gè)特點(diǎn)。伴隨著固定總價(jià)格而來的,還有一個(gè)特性,就是對(duì)變更的抗拒,因?yàn)閷?duì)于承包方來說,變更就意味著更多的工作,就意味著成本的增加,意味著風(fēng)險(xiǎn)。所以通常在固定總價(jià)模式下,承包方會(huì)對(duì)變更有一種天然的抵制,嚴(yán)格地控制變更,即便不得不接受變更,也要走一個(gè)復(fù)雜的流程,先對(duì)變更的影響進(jìn)行仔細(xì)的評(píng)估,再談清楚費(fèi)用和工期的變化,待互相確認(rèn)達(dá)成一致后才會(huì)去處理。這樣的一個(gè)過程往往是比較耗時(shí)的,而且也會(huì)有不少討價(jià)還價(jià)在其中,幾輪之后,最終是合同雙方都會(huì)希望盡量減少變更。</p> <p><br /><img alt="" src="/sites/default/files/%E4%B8%80%E9%94%A4%E5%AE%9A%E9%9F%B3.jpg" style="height:279px; width:300px" /></p> <p>?? 總之,采用固定總價(jià)合同的項(xiàng)目,基本上圍繞著項(xiàng)目范圍能夠在事先被清晰定義這一假設(shè)進(jìn)行,這導(dǎo)致前期準(zhǔn)備工作相對(duì)較多,項(xiàng)目啟動(dòng)周期長。價(jià)格的固定也導(dǎo)致賣方承擔(dān)風(fēng)險(xiǎn)多,因而單價(jià)較貴。并且在合同執(zhí)行過程中對(duì)變更比較抗拒,可能無法靈活應(yīng)對(duì)變化。最大的好處是對(duì)投資和成本控制有利,能夠事先確定預(yù)算。</p> <p><img alt="" src="/sites/default/files/%E5%BC%80%E5%8F%A3%E5%90%88%E5%90%8C.png" style="height:343px; width:344px" /></p> <p>??? 遺憾的是,世事無常,常見的情況恰恰是很多事情都無法提前預(yù)料,人們的預(yù)知能力非常有限,越長遠(yuǎn)的未來,現(xiàn)在能夠預(yù)見的就越少。所以項(xiàng)目規(guī)模越大,持續(xù)時(shí)間越長,不確定性就越高,就越難以在一開始就把范圍清晰界定,變更發(fā)生的可能性也越大。越是這種類型的項(xiàng)目,在使用固定總價(jià)合作模式時(shí),越會(huì)遇到更多的問題。在這種情況下,開口合同就正式出場了。因?yàn)樗暮诵乃枷胧歉鶕?jù)工作量來計(jì)費(fèi),發(fā)生了多少工作就付多少費(fèi)用,不管持續(xù)時(shí)間長短,也不管項(xiàng)目范圍是否清晰,也不管變更發(fā)生得有多頻繁,只要工作發(fā)生了就算數(shù)。這種合作模式的好處是靈活性非常大,只要雙方對(duì)工作量單價(jià)達(dá)成共識(shí),可以很快啟動(dòng)項(xiàng)目,不需要一個(gè)漫長的前期準(zhǔn)備過程,即便項(xiàng)目范圍很不明確,也可以先開始做,邊做邊明確。同時(shí),因?yàn)榘凑諏?shí)際發(fā)生的工作計(jì)費(fèi),這種模式對(duì)任何變更都是包容的,發(fā)包方可以隨時(shí)變更工作內(nèi)容,這也意味著承包方的風(fēng)險(xiǎn)較低,因而在資源單價(jià)上面,會(huì)比固定總價(jià)合同更加優(yōu)惠??上~和熊掌不可兼得,開口合同在帶來這些優(yōu)勢(shì)的同時(shí),也帶來了一些風(fēng)險(xiǎn),那就是無法在項(xiàng)目初期明確總成本,也難以精確評(píng)估項(xiàng)目期限,這對(duì)于預(yù)算驅(qū)動(dòng)型、凡事都要提前明確下來的公司來說,往往是一個(gè)大問題??傊?,這兩種類型的合同,各有各的特點(diǎn),各自適用于不同的場景,并無絕對(duì)的優(yōu)劣。</p> <p>??? 最后,回到我們最初的問題上去,對(duì)一個(gè)項(xiàng)目,應(yīng)該如何判斷它適用哪種合同類型呢?個(gè)人認(rèn)為首要的考慮要素是看它能夠明確的東西有多少,或者反過來看它的不確定性有多高。不確定性越高的,可能用開口合同就越合適。反之,確定性越高的,用固定總價(jià)合同就更可靠。在實(shí)踐中,雙方的信任度也會(huì)對(duì)合同模式的選擇產(chǎn)生較大影響,在沒有建立起信任的時(shí)候,發(fā)包方往往會(huì)傾向于固定總價(jià),在信任度較高的時(shí)候,更易于采取開口合同。</p> <p>??? 以上淺見,歡迎大家點(diǎn)評(píng)。值得一提的是,這些認(rèn)知主要來自軟件開發(fā)這個(gè)領(lǐng)域的體會(huì),可能其它領(lǐng)域的情況并非如此。</p> </div></div></div><div id="comment-wrapper-nid-475"></div><div class="field field-name-field-nuova-blogtag field-type-taxonomy-term-reference field-label-above"><div class="field-label">諾懷博客標(biāo)簽:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/blogtag/%E6%80%BB%E4%BB%B7%E6%A0%BC" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">總價(jià)格</a></div><div class="field-item odd"><a href="/blogtag/%E5%BC%80%E5%8F%A3%E5%8D%8F%E8%AE%AE" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">開口協(xié)議</a></div></div></div> Fri, 20 Dec 2013 04:00:58 +0000 Caven 475 at http://www.redheartclinic.com http://www.redheartclinic.com/blog/%E5%9B%BA%E5%AE%9A%E6%80%BB%E4%BB%B7%E5%90%88%E5%90%8C-vs-%E5%B7%A5%E6%96%99%E5%90%88%E5%90%8C#comments Excel 插件開發(fā)經(jīng)驗(yàn)分享 http://www.redheartclinic.com/blog/excel-%E6%8F%92%E4%BB%B6%E5%BC%80%E5%8F%91%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><h1>&nbsp;</h1> <h1><strong>1. </strong><strong>這個(gè)文檔寫的是些什么?</strong></h1> <p>&nbsp;</p> <p><em>這個(gè)文檔分享了我在Excel插件開發(fā)中所遇到的問題和對(duì)應(yīng)的解決方案。希望對(duì)要進(jìn)行Excel插件開發(fā)或者想自己寫插件增加效率的朋友有所幫助。</em></p> <p>&nbsp;</p> <p>首先描述一下我的Excel開發(fā)遇到的場景:</p> <p>我需要開發(fā)一個(gè)Excel的插件可以從后臺(tái)Web Service獲取數(shù)據(jù)然后顯示到Excel中,那么就存在一個(gè)問題:Web Service的數(shù)據(jù)是通過什么方式寫到Excel中呢?答案是Function!通過函數(shù)的方式寫入Excel中。請(qǐng)看下面這幅圖:</p> <p><img src="/sites/default/files/clip_image001.png" /></p> <p>首先我會(huì)在C3 – C8 輸入年份 2005 - 2010,這時(shí)候我需要在D3 - D8 使用函數(shù) <strong>=GetPriceByYear()</strong>,參數(shù)就是C3 – C8的年份,然后從Web Service獲取相應(yīng)的數(shù)據(jù)寫入其中??吹竭@里你可能會(huì)說用VBA就好了啊?VBA也可以調(diào)用Web Service啊,問什么這么麻煩用插件?</p> <p>&nbsp;</p> <h1><strong>2. </strong><strong>為什么要使用插件這個(gè)東西?</strong></h1> <p>&nbsp;</p> <p>下面我來說一下為什么要用插件。</p> <p>之前這個(gè)功能的確是用VBA實(shí)現(xiàn)了的,但是VBA是和Excel綁定著的,換句話說你用VBA寫了這個(gè)功能保存到Excel中,只有保存的文檔能用這個(gè)函數(shù)功能,如果你用Excel新開一個(gè)文檔,那你之前寫的VBA用不到新的空白文檔里面去。這就造成了麻煩。</p> <p>那如果用插件呢?任何一個(gè)用文檔不管是Excel新建的,還是從別的地方拷貝過來的文檔,只要你的Excel安裝了插件,并且插件啟用了,那么就可以在任何一個(gè)文檔使用這個(gè)功能。是不是比之前用VBA的方式更通用更方便呢?有.NET強(qiáng)大的類庫支持,插件的功能可以寫得更強(qiáng)大更實(shí)用。</p> <p>那么就開始動(dòng)手開發(fā)插件吧!等等,好像需要先調(diào)查一下網(wǎng)上有沒有什么好的方案,存不存在什么問題。</p> <p>&nbsp;</p> <h1><strong>3. </strong><strong>用什么開發(fā)插件?</strong></h1> <p>&nbsp;</p> <p>.NET程序員傷不起,開發(fā)環(huán)境當(dāng)然首選Visual Studio了,接下來就有兩種選擇:</p> <p>一種是<strong>VSTO</strong><strong>(Visual Studio Tools for Office</strong><strong>)</strong></p> <p><img src="/sites/default/files/clip_image003.jpg" /></p> <p>還有一種就是:<strong>Shared Add-in</strong></p> <p><img src="/sites/default/files/clip_image005.jpg" /></p> <p>這兩種有什么異同呢?相同的點(diǎn)不用說了,都可以開發(fā)Excel Add-in,不同的就體現(xiàn)在Shared這個(gè)詞上,VSTO開發(fā)的插件是針對(duì)某一個(gè)Office產(chǎn)品的,也就是Excel,Word,Outlook需要用VSTO開發(fā)三個(gè)插件才能在這三個(gè)產(chǎn)品中使用,而Shard Add-in只需要開發(fā)一個(gè),就可以在這三個(gè)產(chǎn)品上使用,很強(qiáng)大是吧?所以根據(jù)你的需求選擇最適合你的一種方式開發(fā)就好了。</p> <p>如果你想深入了解他們之間的區(qū)別可以去這里看下:</p> <p><a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/3f97705a-6052-4296-a10a-bfa3a39ab4e7/shared-addin-vs-vsto-addin-whats-the-difference-betweenhow-can-i-tell-if-im-developing?forum=vsto">Shared Add-in vs. VSTO Add-in: What's the difference between/how can I tell if I'm developing?</a></p> <p>這時(shí)你可能興奮得馬上開始打開VS創(chuàng)建一個(gè)項(xiàng)目試試,試試歸試試,你回頭看到周圍電腦大家用的操作系統(tǒng)和Office都不一樣的時(shí)候,你突然開始思考了。。。</p> <p>&nbsp;</p> <h1><strong>4.</strong><strong>插件在Office 2000 – 2013</strong><strong>上都能用嗎?</strong></h1> <p>&nbsp;</p> <p>答案是否定的,首先看Wiki 上的VSTO怎么說:</p> <p>The developer editions of Office have been discontinued after Office XP and VSTO is available for Office 2003 and later versions only.</p> <p>很遺憾Office 2000 還有 Office XP不被支持了,其實(shí)現(xiàn)在沒看到用這兩個(gè)版本的了,最低版本也就是 2003了,但是看到這句話我心有余悸,微軟的這種拋棄式做法,那估計(jì)想同時(shí)兼容2003-2013也懸了,因?yàn)槟憧聪翺ffice2003和Office2007的界面差距有多大你就清楚了。</p> <p>結(jié)果正如我所料,請(qǐng)看下圖:</p> <p><img src="/sites/default/files/clip_image007.jpg" /></p> <p>當(dāng)我看到這個(gè)圖我凌亂了~哦難道要一個(gè)Office版本開發(fā)一個(gè)?</p> <p>經(jīng)過我的不懈Google。。。和虛擬機(jī)中的不懈測試。。。</p> <p>終于得出了結(jié)論:</p> <ul> <li><strong>如果開發(fā)Office 2003</strong><strong>的Add-in </strong><strong>使用 VS2008 + .NET 3.5 + VSTO 3.0</strong></li> <li><strong>如果開發(fā)Office 2007</strong><strong>以上的Add-in</strong><strong>使用(VS2010</strong><strong>或者VS2012 </strong><strong>)+ .NET 4.0 + VSTO 4.0</strong></li> </ul> <h1>&nbsp;</h1> <h1><strong>5. </strong><strong>那我寫個(gè)小Demo</strong><strong>發(fā)布一下試試?</strong></h1> <p>&nbsp;</p> <p>“開發(fā)機(jī)上運(yùn)行完美,客戶機(jī)上運(yùn)行不起來!”</p> <p>&nbsp;</p> <p>這個(gè)是很多人發(fā)布插件到客戶機(jī)安裝后得出的結(jié)論!是這么多人都SB嗎?腫么可能?是因?yàn)榘l(fā)布程序的陷阱太多了,換句話說,官方給了你發(fā)布程序的20個(gè)步驟,你看了之后說:你當(dāng)我沒發(fā)布過程序嗎?傻啊,我就5步搞定!當(dāng)你說出這話你就會(huì)說上面那句很多人都說的話了。。。</p> <p>因?yàn)槟愕拇_需要做20步,所以發(fā)布的確很讓人頭疼,不過你想想發(fā)布成功之后插件啟動(dòng)了之后。。。多么美好??!</p> <ul> <li>如果你開發(fā)的是Office 2003的插件那么請(qǐng)按照下面的步驟發(fā)布:</li> </ul> <p><a href="http://msdn.microsoft.com/en-us/library/bb332051(v=office.12).aspx">Deploying Visual Studio 2005 Tools for the Office System SE Solutions Using Windows Installer (Part 1 of 2)</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/bb332052(v=office.12).aspx">Deploying Visual Studio 2005 Tools for the Office System SE Solutions Using Windows Installer (Part 2 of 2)</a></p> <p>做完P(guān)art 1之后是Part 2,都要按步驟做哦!</p> <p>另外給一個(gè)寫的不錯(cuò)中文文章:</p> <p><a href="http://blog.csdn.net/v_jzho/article/details/1954454">如何簡單部署用VSTO SE 2005開發(fā)的Excel,Word插件</a></p> <p>&nbsp;</p> <ul> <li>如果你開發(fā)的是Office 2007以上的插件,請(qǐng)看這里的步驟:</li> </ul> <p><a href="http://www.cnblogs.com/brooks-dotnet/archive/2011/11/04/2236609.html">http://www.cnblogs.com/brooks-dotnet/archive/2011/11/04/2236609.html</a></p> <p>&nbsp;</p> <h1><strong>6. Office 2007</strong><strong>有問題怎么辦?</strong></h1> <p>&nbsp;</p> <p>開發(fā)和發(fā)布都沒有什么問題,應(yīng)為 Office 2007 版本以上的插件發(fā)布安裝都比 2003 不知道方便了多少,但是如果你發(fā)現(xiàn)調(diào)試沒問題,發(fā)布后也能成功安裝但是就是運(yùn)行出錯(cuò),首先確認(rèn)你的系統(tǒng)是不是 windows XP,因?yàn)?Windows 7 以上不會(huì)出現(xiàn)這種情況,windows 7 是自帶了 .NET Framework 2.0 的,但是XP沒有自帶,我一直奇怪用 .NET Framework 4.0 開發(fā)的插件為什么還要用 2.0 的 Framework?不過就是因?yàn)檫@個(gè)問題弄了我好久!</p> <p>所以記住讓你額客戶端無論如何都裝一個(gè)Framework 2.0比較保險(xiǎn)一點(diǎn)。</p> <p>&nbsp;</p> <h1><strong>7. </strong><strong>怎么讓函數(shù)參數(shù)列表自動(dòng)提示?</strong></h1> <p>&nbsp;</p> <p>一開始寫了個(gè)模塊定義了一些函數(shù),結(jié)果在Excel里面用的時(shí)候只是提示函數(shù)名參數(shù)都不提供,給其他人使用鬼曉得輸入什么參數(shù)???</p> <p><img alt="I=sho I" src="/sites/default/files/clip_image008.png" /></p> <p><img alt="I=ShowMeJheParameter(" src="/sites/default/files/clip_image009.png" /></p> <p>完全看不到參數(shù)提示,你說我該輸入什么?</p> <p>這時(shí)候如果按 Shift + Ctrl + A,下面就是見證奇跡的時(shí)刻!</p> <p><img alt="I=ShowMeTheParameter(IDIrName,Year,Month)" src="/sites/default/files/clip_image010.png" /></p> <p>參數(shù)列表出來了,這時(shí)候選擇參數(shù)去關(guān)聯(lián)Excel里面的單元格就可以了</p> <p><img alt="I=ShowMeTheparameter(C6,D6,E6,F4. . . .? ?.I I I :. . . .. ." src="/sites/default/files/clip_image011.png" /></p> <p>&nbsp;</p> <h1><strong>8. C# </strong><strong>如何動(dòng)態(tài)調(diào)用Web Service</strong><strong>?</strong></h1> <p>&nbsp;</p> <p>查了網(wǎng)上很多文章都不靠譜,自己寫了一個(gè),支持 Soapheader。</p> <pre class="brush: csharp"> using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO; using System.Web.Services.Description; using System.CodeDom; using Microsoft.CSharp; using System.CodeDom.Compiler; using System.Reflection; namespace ExcelAddIn { /// <summary> /// Call WebService Dynamically (support SoapHeader) /// </summary> public class WebServiceHelper { /// <summary> /// Get WebService Class Name /// </summary> /// <param name="wsUrl">WebService URL</param> /// <returns>WebService Class Name</returns> private static string GetWsClassName(string wsUrl) { string[] parts = wsUrl.Split('/'); string[] pps = parts[parts.Length - 1].Split('.'); return pps[0]; } /// <summary> /// Call WebService Without SoapHeader /// </summary> /// <param name="wsUrl">WebService URL</param> /// <param name="methodName">Method Name</param> /// <param name="args">Arguments</param> /// <returns>Method Result</returns> public static object InvokeWebService(string wsUrl, string methodName, object[] args) { return InvokeWebService(wsUrl, null, methodName, null, args); } /// <summary> /// Call WebService With SoapHeader /// </summary> /// <param name="wsUrl">WebService URL</param> /// <param name="methodName">Method Name</param> /// <param name="soapHeader">Soap Header</param> /// <param name="args">Arguments</param> /// <returns>Method Result</returns> public static object InvokeWebService(string wsUrl, string methodName, SoapHeader soapHeader, object[] args) { return InvokeWebService(wsUrl, null, methodName, soapHeader, args); } /// <summary> /// Call WebService /// </summary> /// <param name="wsUrl">WebService URL</param> /// <param name="className">Class Name</param> /// <param name="methodName">Method Name</param> /// <param name="soapHeader">Soap Header</param> /// <param name="args">Arguments</param> /// <returns>Method Result</returns> public static object InvokeWebService(string wsUrl, string className, string methodName, SoapHeader soapHeader, object[] args) { string @namespace = ""; if ((className == null) || (className == "")) { className = GetWsClassName(wsUrl); } WebClient wc = new WebClient(); Stream stream = wc.OpenRead(wsUrl + "?wsdl"); ServiceDescription sd = ServiceDescription.Read(stream); ServiceDescriptionImporter sdi = new ServiceDescriptionImporter(); sdi.AddServiceDescription(sd, "", ""); CodeNamespace cn = new CodeNamespace(@namespace); CodeCompileUnit ccu = new CodeCompileUnit(); ccu.Namespaces.Add(cn); sdi.Import(cn, ccu); CSharpCodeProvider csc = new CSharpCodeProvider(); ICodeCompiler icc = csc.CreateCompiler(); CompilerParameters cplist = new CompilerParameters(); cplist.GenerateExecutable = false; cplist.GenerateInMemory = true; cplist.ReferencedAssemblies.Add("System.dll"); cplist.ReferencedAssemblies.Add("System.XML.dll"); cplist.ReferencedAssemblies.Add("System.Web.Services.dll"); cplist.ReferencedAssemblies.Add("System.Data.dll"); CompilerResults cr = icc.CompileAssemblyFromDom(cplist, ccu); if (true == cr.Errors.HasErrors) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); foreach (System.CodeDom.Compiler.CompilerError ce in cr.Errors) { sb.Append(ce.ToString()); sb.Append(System.Environment.NewLine); } throw new Exception(sb.ToString()); } System.Reflection.Assembly assembly = cr.CompiledAssembly; Type t = assembly.GetType(@namespace + "." + className, true, true); FieldInfo[] arry = t.GetFields(); FieldInfo client = null; object clientkey = null; if (soapHeader != null) { client = t.GetField(soapHeader.ClassName + "Value"); Type typeClient = assembly.GetType(@namespace + "." + soapHeader.ClassName); clientkey = Activator.CreateInstance(typeClient); foreach (KeyValuePair<string, object> property in soapHeader.Properties) { typeClient.GetField(property.Key).SetValue(clientkey, property.Value); } } object obj = Activator.CreateInstance(t); if (soapHeader != null) { client.SetValue(obj, clientkey); } System.Reflection.MethodInfo mi = t.GetMethod(methodName); return mi.Invoke(obj, args); } /// <summary> /// Soap Header /// </summary> public class SoapHeader { /// <summary> /// SoapHeader /// </summary> public SoapHeader() { this.Properties = new Dictionary<string, object>(); } /// <summary> /// SoapHeader /// </summary> /// <param name="className">Soap Header Class Name</param> public SoapHeader(string className) { this.ClassName = className; this.Properties = new Dictionary<string, object>(); } /// <summary> /// SoapHeader /// </summary> /// <param name="className">Soap Header Class Name</param> /// <param name="properties">Soap Header Properties</param> public SoapHeader(string className, Dictionary<string, object> properties) { this.ClassName = className; this.Properties = properties; } /// <summary> /// Soap Header Class Name /// </summary> public string ClassName; /// <summary> /// Soap Header Properties /// </summary> public Dictionary<string, object> Properties; /// <summary> /// Add a Property to SoapHeader /// </summary> /// <param name="name">Soap Property Name</param> /// <param name="value">Soap Property Value</param> public void AddProperty(string name, object value) { if (this.Properties == null) { this.Properties = new Dictionary<string, object>(); } Properties.Add(name, value); } } } } </pre> <p>&nbsp;</p> <h1><em><strong>9. </strong></em><em><strong>待續(xù)</strong></em></h1> </div></div></div><div id="comment-wrapper-nid-472"></div><div class="field field-name-field-nuova-blogtag field-type-taxonomy-term-reference field-label-above"><div class="field-label">諾懷博客標(biāo)簽:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/blogtag/excel" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Excel</a></div><div class="field-item odd"><a href="/blogtag/%E5%BC%80%E5%8F%A3%E5%8D%8F%E8%AE%AE" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">開口協(xié)議</a></div><div class="field-item even"><a href="/blogtag/web-service" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Web Service</a></div></div></div> Fri, 13 Dec 2013 06:19:12 +0000 Yee 472 at http://www.redheartclinic.com http://www.redheartclinic.com/blog/excel-%E6%8F%92%E4%BB%B6%E5%BC%80%E5%8F%91%E7%BB%8F%E9%AA%8C%E5%88%86%E4%BA%AB#comments