1
我從excel中獲取圖表名稱並創建文本爲圖紙名稱的按鈕。在asp.net中停止對excel中的圖紙名稱進行排序
但每次創建按鈕時,都按字母順序排序。我不想整理它們。
這是我的代碼:
Dim objConn As OleDbConnection = Nothing
Dim dt As System.Data.DataTable = Nothing
Try
Dim connString As String = ""
If Extension = "xls" Or Extension = ".xls" Then
connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & FileUploadPath & sender.text & ";Extended Properties=" + Convert.ToChar(34).ToString() + "Excel 8.0;HDR=No;IMEX=1" + Convert.ToChar(34).ToString() + ""
ElseIf Extension = "xlsx" Or Extension = ".xlsx" Then
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & FileUploadPath & sender.text & ";Extended Properties=" + Convert.ToChar(34).ToString() + "Excel 12.0;HDR=No;IMEX=2" + Convert.ToChar(34).ToString() + ""
End If
objConn = New OleDbConnection(connString)
objConn.Open()
dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
If Not dt Is Nothing Then
Dim i As Integer = 1
For Each row As DataRow In dt.Rows
Dim btn As Button = New Button
btn.ID = "btnSheet" & i
btn.Text = row("TABLE_NAME").ToString().Substring(0, row("TABLE_NAME").ToString.Length - 1)
excelSheetButtonsList.Add(btn)
tdInfo.Controls.Add(btn)
tdInfo.Controls.Add(New LiteralControl(" "))
AddHandler btn.Click, AddressOf ExcelSheetNameButtons_Click
i += 1
Next
End If
Catch ex As Exception
Finally
If objConn IsNot Nothing Then
objConn.Close()
objConn.Dispose()
End If
If dt IsNot Nothing Then
dt.Dispose()
End If
End Try
圖像1是上述代碼的輸出:
現在圖像2描述了excel表:
我wa nt我的輸出順序,因爲它是在圖像2.
可能重複[此問題](http://stackoverflow.com/questions/995984/get-index-of-the-excel-sheet-using-asp-net?rq=1)雖然沒有一個確認的答案。請參閱[這裏](http://forums.asp.net/t/1783814.aspx/1)並參考已接受的答案鏈接[here](http://csharpdotnetfreak.blogspot.com/2011/12/upload-和-read-excel-file-in-aspnet.html) – 2013-05-06 01:38:14
我不是滿瓶,但你可以使用Excel對象來獲取它們嗎?這將保持順序。 – glh 2013-05-06 06:10:48
@DavidZemens我引用了你提供的最後一個鏈接,並從那裏得到了問題中顯示的代碼。但也有工作表名稱排序。 – Vishal 2013-05-06 18:33:15