用asp.net直接生成word excel,并且不下载,直接打开
用asp.net直接生成word excel,而且不下载,直接打开
使用asp.net写这么一个功能
通过asp.net生成一个word 或者 excel,并在写入想要加入的内容,要带格式的
然后不用下载,直接打开
求高手给一个比较详尽的例子
------解决方案--------------------
找个控件接住~~
------解决方案--------------------
能不能直接打开不是你控制得了的,要看客户端有没有安装相应的office软件,没有就会提示下载文件
------解决方案--------------------
我的可用的代码(生成excel报表)
Dim xlBooks As Excel.Workbooks, xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
' Dim rowIndex, colIndex As Integer
Dim spath As String
spath = Server.MapPath("./")
spath = spath & "uploads\book1.xls"
'missing2 = missing.Value
xlApp.Visible = False
' xlBook = xlApp.Workbooks().Add
xlApp.DisplayAlerts = False
xlBooks = xlApp.Workbooks
xlBooks.Open(spath)
xlBook = xlBooks.Item(1)
'xlBook = xlApp.Application.Workbooks.Open("rep1.xlt", missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
xlSheet = xlBook.Worksheets("sheet1")
'处理数据 。。。。
ds = Funlib.MyQueryUsesqlDataSet(ss, "temp")
If ds.Tables("temp").Rows.Count > 0 Then
xlApp.Cells(1, 3) = Tb.Text.Trim & "报表"
xlApp.Cells(2, 3) = CStr(Funlib.getdate())
xlApp.Cells(3, 2) = "等级"
xlApp.Cells(3, 1) = "序号"
xlApp.Cells(3, 3) = "名称"
xlApp.Cells(3, 4) = "单位"
xlApp.Cells(3, 5) = "人"
xlApp.Cells(3, 6) = "得分"
xlApp.Cells(3, 7) = "备注"
For i = 0 To ds.Tables("temp").Rows.Count - 1
For j = 0 To ds.Tables("temp").Columns.Count - 1
xlApp.Cells(i + 4, j + 1) = ds.Tables(0).Rows(i)(j)
Next j
Next i
Else
lblstatus.Text = "没有符合条件的数据!"
End If
Dim spath2 As String
spath2 = Server.MapPath("./") & "uploads\book2.xls"
'
'RegisterClientScriptBlock("提示:", "<script language=javascript>alert('save file!')</script>")
使用asp.net写这么一个功能
通过asp.net生成一个word 或者 excel,并在写入想要加入的内容,要带格式的
然后不用下载,直接打开
求高手给一个比较详尽的例子
------解决方案--------------------
找个控件接住~~
------解决方案--------------------
能不能直接打开不是你控制得了的,要看客户端有没有安装相应的office软件,没有就会提示下载文件
------解决方案--------------------
我的可用的代码(生成excel报表)
Dim xlBooks As Excel.Workbooks, xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
' Dim rowIndex, colIndex As Integer
Dim spath As String
spath = Server.MapPath("./")
spath = spath & "uploads\book1.xls"
'missing2 = missing.Value
xlApp.Visible = False
' xlBook = xlApp.Workbooks().Add
xlApp.DisplayAlerts = False
xlBooks = xlApp.Workbooks
xlBooks.Open(spath)
xlBook = xlBooks.Item(1)
'xlBook = xlApp.Application.Workbooks.Open("rep1.xlt", missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)
xlSheet = xlBook.Worksheets("sheet1")
'处理数据 。。。。
ds = Funlib.MyQueryUsesqlDataSet(ss, "temp")
If ds.Tables("temp").Rows.Count > 0 Then
xlApp.Cells(1, 3) = Tb.Text.Trim & "报表"
xlApp.Cells(2, 3) = CStr(Funlib.getdate())
xlApp.Cells(3, 2) = "等级"
xlApp.Cells(3, 1) = "序号"
xlApp.Cells(3, 3) = "名称"
xlApp.Cells(3, 4) = "单位"
xlApp.Cells(3, 5) = "人"
xlApp.Cells(3, 6) = "得分"
xlApp.Cells(3, 7) = "备注"
For i = 0 To ds.Tables("temp").Rows.Count - 1
For j = 0 To ds.Tables("temp").Columns.Count - 1
xlApp.Cells(i + 4, j + 1) = ds.Tables(0).Rows(i)(j)
Next j
Next i
Else
lblstatus.Text = "没有符合条件的数据!"
End If
Dim spath2 As String
spath2 = Server.MapPath("./") & "uploads\book2.xls"
'
'RegisterClientScriptBlock("提示:", "<script language=javascript>alert('save file!')</script>")