Asp.net高手請進! (200分)

  • 主题发起人 主题发起人 james0337
  • 开始时间 开始时间
J

james0337

Unregistered / Unconfirmed
GUEST, unregistred user!
Asp.net(c#)高手:
如何用Asp.net 讀取dataexcel.xls 文檔,用datagrid呈現,
我有用一種方法,select * from [sheet1$] 但不能滿足我的要求.
我的需求是: a.Excel檔資料列不定,可否都load進來.
b.Excel檔第一列不是表頭時,可否都load進來
c.Excel檔第一個sheet,如果名稱不固定,可否都load進來.
d.Excel檔是用Html呈現時,可否都load進來.
這個問題已困擾我項目很久了,高分求解!
能否給出源代碼! [:(]
 
Help Help ....me !
 
沒有Asp.net c#高手嗎?[:)]
 
哥們 ,能否提供.net論壇?
 
应可以实现吧,这还没有试,你看下这些资料先,也许有用。
'功能:将asp.net中DataGrid生成Excel文件下载。
'Mountains改进:1、支持中文 2、隐藏列不显示
'日期:2002.10.30
Public Class DataGridToCSV
Public Function GenerateFile(ByRef Page As System.Web.UI.Page, ByVal MyDataGrid As System.Web.UI.WebControls.DataGrid, ByVal FileName As String) As String
Dim resp As HttpResponse
Dim colCount As Integer = MyDataGrid.Columns.Count - 1
resp = Page.Response
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312") '解决中文乱码之关键
'resp.Charset = "utf-8"
'resp.AddFileDependency(FileName)
'resp.ContentType = "Text/HTML"
''resp.AppendHeader("Content-Type", "text/html;
charset=gb2312")
resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName) '必要,做成下载文件

Dim colHeaders As String = ""
Dim strItems As StringBuilder = New StringBuilder()
Dim myCol As DataGridColumn
Dim i As Integer
For i = 0 To colCount
myCol = MyDataGrid.Columns(i)
If myCol.Visible = True then
colHeaders = colHeaders &
myCol.HeaderText.ToString &
","
End If
Next
If colHeaders.Length > 0 then
colHeaders = colHeaders.Substring(0, colHeaders.LastIndexOf(","))
End If
colHeaders = colHeaders &
Chr(13) &
Chr(10)

resp.Write(colHeaders)
Dim colRow As String
Dim item As DataGridItem
For Each item In MyDataGrid.Items
resp.Write(FormatExportRow(colCount, item, MyDataGrid))
Next item
resp.End()
End Function
Private Function FormatExportRow(ByVal colCount As Integer, ByVal Item As DataGridItem, ByVal MyDataGrid As System.Web.UI.WebControls.DataGrid) As String
Dim strItem As String
Dim i As Integer
For i = 0 To colCount
If MyDataGrid.Columns(i).Visible = True then
If Item.Cells(i).Text Is System.DBNull.Value then
Item.Cells(i).Text = ""
End If
If i = colCount then
strItem += Item.Cells(i).Text.ToString &
Chr(13) &
Chr(10)
else
strItem += Item.Cells(i).Text.ToString &
","
End If
End If
Next
strItem = Replace(strItem, " ", " ")
Return strItem
End Function

End Class
End Namespace
 
没有作过,你看这个论坛www.asp.net
 
我所需要是從dataExcel.xls 讀取資料存到Dataset或DataTable
use Asp.Net (c#)
Help greatly appreciated
 
后退
顶部