| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2338 人关注过本帖
标题:求助:怎么让数据库里的数据打印出来
只看楼主 加入收藏
cumtsc
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-12-24
收藏
得分:0 
我现在又出现了一个问题啦!
2008-01-09 14:34
cumtsc
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-12-24
收藏
得分:0 
我的代码是这样。在我电脑上运行没有问题,到别的电脑上时,就说什么office版本不对啦!不能安装程序啦!
Try
            
            '给excel表格填写值()
            Dim myexcel As New Microsoft.Office.Interop.Excel.Application
            myexcel.Workbooks.Open("cement.xls")

            myexcel.Cells(3, 9).value = TextBox4.Text
                        myexcel.Visible = True
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            Dim pList() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("excel")
            For Each proc As System.Diagnostics.Process In pList
                'Try
                '    proc.Kill()
                'Catch ex As Exception
                '    MsgBox(ex.Message)
                'End Try
            Next

        End Try
2008-01-09 14:37
fairy4
Rank: 4
等 级:贵宾
威 望:10
帖 子:738
专家分:267
注 册:2007-11-1
收藏
得分:0 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call outExecl()
    End Sub
    Private Sub outExecl()
        Call KillExcel()
        Dim i, j, k As Integer
        Dim xlApp As New Excel.Application
        Dim xlBook As Excel.Workbook
        Dim xlSheet As Excel.Worksheet
        Dim intCount As Integer
        xlApp = CreateObject("Excel.Application")

        xlBook = xlApp.Workbooks.Open(Application.StartupPath & "\a.xls")

        xlSheet = xlBook.Worksheets(1)
        xlApp.Visible = False
        xlSheet.Activate()
   
        Dim rowindex1 As Integer = 3
        Dim colindex1 As Integer
        Dim col1 As DataColumn
        Dim row1 As DataRow
        Dim nxh1 As Integer = 1

        For Each col1 In Table.Columns '表頭
            colindex1 = colindex1 + 1
            xlApp.Cells(4, colindex1) = col1.ColumnName '獲取列名字
        Next
        For Each row1 In CType(DataGrid1.DataSource, DataTable).Rows '樣本數據
            colindex1 = 1
            For Each col1 In CType(DataGrid1.DataSource, DataTable).Columns
                xlApp.Cells(rowindex1, colindex1) = RTrim(Convert.ToString(row1(col1.ColumnName)))
                colindex1 += 1
            Next
            rowindex1 += 1

        Next
        xlApp.Visible = False
        xlBook.Save()
        xlApp.Quit()
        xlApp = Nothing
        xlBook = Nothing
        xlSheet = Nothing

        MsgBox("保存成功!")

    End Sub
    Private Sub KillExcel()
        Dim pProcess() As Process
        pProcess = Process.GetProcesses()
        Dim i As Integer
        For i = 0 To pProcess.Length() - 1
            If (pProcess(i).ProcessName = "EXCEL") Then
                pProcess(i).Kill()
            End If
        Next

    End Sub
這個將datagrid裡面的數據導出excel!自己去看看

一个人只有一个心脏,却有两个心房。一个住着快乐;一个住着悲伤。不要笑得太大声,不然会吵醒旁边的悲伤
2008-01-09 15:26
cumtsc
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-12-24
收藏
得分:0 
我的代码里面Dim xlApp As New Excel.Application这一句必须是
Dim myexcel As New Microsoft.Office.Interop.Excel.Application
要不然VB2005就会报错!那是怎么会事啊??
2008-01-10 09:57
快速回复:求助:怎么让数据库里的数据打印出来
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016613 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved