ASP.NET EXCEL資料的匯出和匯入

iDotNetSpace發表於2008-09-25

    資料的匯入和匯出在實際的專案中,用的非常普遍。我在自己的專案中實現了從excel檔案中匯入和到處資料,現分析如下:

     一、資料的匯出,其基本思想是首先將要匯出的內容放在Table中並拼成字串,然後以EXCEL檔案的形式匯出。在我的專案中,使用者可以自己選擇要匯出的資料欄位。因為實際的欄位較多,故只列出部分欄位。

     頁面的html如下:

ASP.NET EXCEL資料的匯出和匯入
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--&gt <div id="DivProjectProperty" style="text-align: center; color: White">
            
<fieldset>
                
<legend>專案匯出欄位legend>
                
<div id="DivProjectBasic" style="margin-top: 5px">
                    
<fieldset style="text-align: left;">
                        
<legend>專案基本欄位legend>
                        
<table id="tableProjectBasic" cellpadding="0" cellspacing="0" width="99%" style="margin-left: 10px">
                            
<tr>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectBasicSelectAll" name="ProjectBasic" class="ProjectBasic"
                                        onclick
="selectProjectPropertyAll(this)" />選擇全部
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectName" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />名稱
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectSerialNumber" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />流水號
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectNumber" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />編號
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectPrincipalNumber" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />負責人工作證號
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectPrincipalName" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />負責人姓名
                                
td>
                            
tr>
                            
<tr>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectState" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />狀態
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectStartDate" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />開始日期
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectEndDate" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />結束日期
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectCreator" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />創立人
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectCreateDate" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />創立日期
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxprojectUpdateDate" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />更新日期
                                
td>
                            
tr>
                            
<tr>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectSubjectCode" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />學科程式碼
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectResearchType" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />研究型別
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectIsSerect" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />是否保密
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectBaseName" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />基地名稱
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectCooperationType" class="ProjectBasic" checked="checked"
                                        runat
="server" onclick="changeSelectAllState(this)" />合作型別
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectUnit" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />合作單位
                                
td>
                            
tr>
                            
<tr>
                                
<td>
                                    
<input type="checkbox" id="CheckboxPorjectTaskFrom" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />任務來源
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectCorporationPlace" class="ProjectBasic"
                                        
checked="checked" runat="server" onclick="changeSelectAllState(this)" />公司地址
                                
td>
                                
<td>
                                    
<input type="checkbox" id="CheckboxProjectRemark" class="ProjectBasic" runat="server"
                                        
checked="checked" onclick="changeSelectAllState(this)" />備註
                                
td>
                            
tr>
                        
table>
                    
fieldset>
                
div>
            
fieldset>
        
div>
        
<div id="DivOperator" style="text-align: center; margin-

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-464292/,如需轉載,請註明出處,否則將追究法律責任。

下一篇: c# oop思想
ASP.NET EXCEL資料的匯出和匯入
請登入後發表評論 登入
全部評論

相關文章