主题:【求助】VB.Net高手们进来瞅一瞅啦, CR问题 -- MacArthur
终于发现了一个极其简单的办法 -- 本来也是,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
- 相关回复 上下关系8
🙂【求助】VB.Net高手们进来瞅一瞅啦, CR问题 1 MacArthur 字2427 2006-11-07 16:24:22
😄CrystalReport去死吧
🙂用EXCEL做chart一样方便 1 晓晴夕照 字401 2006-12-04 15:59:00
🙂谢谢,献花 MacArthur 字102 2006-12-04 17:04:53
🙂see the text in red 1 晓晴夕照 字1075 2006-12-04 18:39:55
🙂直接填数据这招狠 lanchong 字53 2006-11-17 21:51:55
🙂不晓得是啥问题~~ 1 并非马甲 字117 2006-11-08 07:29:37
🙂多谢 1 MacArthur 字0 2006-11-08 08:54:57