主题:【求助】VB.Net高手们进来瞅一瞅啦, CR问题 -- MacArthur
或者google上也行
不过不过,我的的确确是给了License Key了 -- 我的那个License Key是去年得到的... 莫非过期了?
看看是否还缺其它的安装包!
要部署使用 Crystal Reports for Visual Studio .NET 2003 的程序,需要添加如下合并模块(在解决方案资源管理器中tree的顶端节点右键-->添加):
Crystal_Database_Access2003.msm
Crystal_Database_Access2003_enu.msm
Crystal_Managed2003.msm
Crystal_regwiz2003.msm
VC_User_CRT71_RTL_X86_---.msm
VC_User_STL71_RTL_X86_---.msm
我在中文版下用的VS.Net2003,也许和楼主的VS.Net2002环境有所不同,供参考!
终于发现了一个极其简单的办法 -- 本来也是,Excel也是微软的,微软怎么会不照顾自己一家子呢?
在Project里面add reference -> COM object -> MS Excel 11.0 -- 加了这个之后就可以在VB里名正言顺地引用微软的一堆便民服务... 瞅人这名儿起的,Microsoft.Office.Core -- 一core在手,谁敢阻拦?
这个CrystalReport呢,功能的确比较强大,而且formatting出来也很漂亮。不过呢,出了个连他们自己都解释不了的问题,不能用还不全白搭么... 而且俺只关心数据,不在乎格式 -- 只求您能把数据全部灌到报表里就是大功一件啦...
附上例程,供有心者参考...
......
......
Sub generateCryatalReport(ByVal strReportName As String)
Dim datatable As System.Data.DataTable = dsWKIT.Tables(0)
Dim Application As New Excel.Application()
Application.SheetsInNewWorkbook = 1
Dim wb As Excel.Workbook = Application.Workbooks.Add()
Dim ws As Excel.Worksheet = wb.Worksheets("Sheet1")
ws.Name = strReportName
Dim rowIndex As Integer
Dim colIndex As Integer
Try
' Create the headers on the sheet.
For colIndex = 1 To datatable.Columns.Count
ws.Cells(1, colIndex) = datatable.Columns(colIndex - 1).ColumnName
Next
' Add each row of data to the sheet.
' The sheet cell row is incremented by one because the first row was used for the header.
For rowIndex = 1 To datatable.Rows.Count
For colIndex = 1 To datatable.Columns.Count
ws.Cells(rowIndex + 1, colIndex) = datatable.Rows(rowIndex - 1)(colIndex - 1).ToString()
Next
Next
Catch ex As System.Runtime.InteropServices.COMException
End Try
wb.SaveAs("C:\" & strReportName & ".xls")
wb.Close()
Application.Quit()
End Sub
CrystalReport的好处是鼠标拉拉就可以用,适合俺这类人用
做出来效果不比CR差。如果有兴趣看看Excel.Series class. 有一个问题是office都是out-of-proc,所以所有的COM object 都要用
Marshal.ReleaseComObject去de-reference 然后再GC, 不然的话一旦出exception,会有一堆dead excel.exe process 你没法kill掉。
还有,如果你只是想export data, 你可以output your data in html format , 然后
Response.ContentType = "application/vnd.ms-excel"
这样client会用EXCEL打开这个HTML。
这里能否详细解释一下,给个例子?多谢!
Sub generateCryatalReport(ByVal strReportName As String)
Dim datatable As System.Data.DataTable = dsWKIT.Tables(0)
Dim Application As New Excel.Application()
Application.SheetsInNewWorkbook = 1
Dim wb As Excel.Workbook = Application.Workbooks.Add()
Dim ws As Excel.Worksheet = wb.Worksheets("Sheet1")
ws.Name = strReportName
Dim rowIndex As Integer
Dim colIndex As Integer
Try
...
Catch ex As System.Runtime.InteropServices.COMException
finally
wb.SaveAs("C:\" & strReportName & ".xls")
wb.Close()
Application.Quit()
if not wb is nothing then marshal.releasecomobject(wb)
if not ws is nothing then marshal.releasecomobject(ws)
if not application is nothing then marshal.releasecomobject(application)
wb=nothing:ws=nothing:application=nothing
gc.collect()
End Try
End Sub