我是用owc组件生成的excel文档这里面的datagrid没有rows,怪事。
Dim xlsheet As New SpreadsheetClass()
Dim i As Integer = 0
Dim j As Integer = 0
'Response.End()
' 输出标题
'xlsheet.ActiveSheet.Cells (a1:a5)="123456" Dim oItem As DataGridColumn
For Each oItem In DataGrid1.Columns
xlsheet.ActiveSheet.Cells(2, i + 1) = oItem.HeaderText
'xlsheet.ActiveSheet.Range(xlsheet.ActiveSheet.Cells(1, 1),xlsheet.ActiveSheet.Cells(1, i + 1)).Font.Bold = True
'设置格式
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Bold = False
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Color = "black"
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Name = "黑体"
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Size = "12"
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).ColumnWidth = "170"
i = i + 1
Next Dim numbercols As Integer = DataGrid1.Items.Item(0).Cells.Count
'Dim dataitem As
'Dim viewcount As Integer
'viewcount = dataitem.Rows.Count
'Response.Write("viewcount")
'Response.End() Dim l As Integer = 1 ' 输出字段内容
For j = 0 To DataGrid1.Items.Count - 1
' For j = 0 To DataGrid1.rows.count
For i = 0 To numbercols - 1
' xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Color = "black"
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Bold = False
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Color = "black"
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Name = "arial black"
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Size = "12"
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).ColumnWidth = "170"
''xlsheet.Range("A2:B14").WrapText = True
'xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).AutoFitColumns()
xlsheet.ActiveSheet.Cells(l + 2, i + 1) = DataGrid1.Items.Item(j).Cells(i).Text.Replace(" ", " ")
Next
l = l + 1
Next
Try
xlsheet.ActiveSheet.Export(Server.MapPath(".") + "\doc\" + strurl, OWC.SheetExportActionEnum.ssExportActionNone)
Catch e As System.Runtime.InteropServices.COMException
Response.Write("错误:" + e.Message)
End Try
Dim strdoc As String = strurl4 & "doc/" & strurl Response.Redirect("doc/" & strurl) End Sub
Dim xlsheet As New SpreadsheetClass()
Dim i As Integer = 0
Dim j As Integer = 0
'Response.End()
' 输出标题
'xlsheet.ActiveSheet.Cells (a1:a5)="123456" Dim oItem As DataGridColumn
For Each oItem In DataGrid1.Columns
xlsheet.ActiveSheet.Cells(2, i + 1) = oItem.HeaderText
'xlsheet.ActiveSheet.Range(xlsheet.ActiveSheet.Cells(1, 1),xlsheet.ActiveSheet.Cells(1, i + 1)).Font.Bold = True
'设置格式
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Bold = False
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Color = "black"
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Name = "黑体"
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).Font.Size = "12"
xlsheet.Range(xlsheet.Cells(2, 1), xlsheet.Cells(2, i + 1)).ColumnWidth = "170"
i = i + 1
Next Dim numbercols As Integer = DataGrid1.Items.Item(0).Cells.Count
'Dim dataitem As
'Dim viewcount As Integer
'viewcount = dataitem.Rows.Count
'Response.Write("viewcount")
'Response.End() Dim l As Integer = 1 ' 输出字段内容
For j = 0 To DataGrid1.Items.Count - 1
' For j = 0 To DataGrid1.rows.count
For i = 0 To numbercols - 1
' xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Color = "black"
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Bold = False
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Color = "black"
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Name = "arial black"
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).Font.Size = "12"
xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).ColumnWidth = "170"
''xlsheet.Range("A2:B14").WrapText = True
'xlsheet.Range(xlsheet.Cells(3, 1), xlsheet.Cells(l + 2, i + 1)).AutoFitColumns()
xlsheet.ActiveSheet.Cells(l + 2, i + 1) = DataGrid1.Items.Item(j).Cells(i).Text.Replace(" ", " ")
Next
l = l + 1
Next
Try
xlsheet.ActiveSheet.Export(Server.MapPath(".") + "\doc\" + strurl, OWC.SheetExportActionEnum.ssExportActionNone)
Catch e As System.Runtime.InteropServices.COMException
Response.Write("错误:" + e.Message)
End Try
Dim strdoc As String = strurl4 & "doc/" & strurl Response.Redirect("doc/" & strurl) End Sub
解决方案 »
- asp.net DataList 显示二进制图片问
- 内嵌Repeater绑定数据时Repeater2未将对象引用到实例
- 求助啊!! 在线鼠标签名并且生成图片
- 关于杂志网站实现的问题
- 如何在绑定后的DataList控件中,已经棒定好的USERID和所给的分数?
- 问题总是来得突然.....[水晶问题]
- 用户控件载入时出现的问题 --希望MVP 们给出正解
- 跪求个人网页数据库及网页需求分析
- 如何在字符串中加入回车?
- DataList嵌套子DataList如何添加提交按钮,并将两个DataList的数据提交
- 请问"http://202.109.114.243:8083/home.aspx"这个网站的导航栏是用什么作的
- 请问这个链接怎么写?
遍历datagrid中的行,
dim litem as datagriditem
dim t as integer
for each litem in datagrid.items
t+=1
next
最后的T就是行的总数。虽然办法有点笨,但应该可行