| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 1237 人关注过本帖
标题:求助:怎么让数据库里的数据打印出来
收藏  订阅  推荐  打印 
cumtsc
Rank: 1
等级:新手上路
帖子:9
积分:204
注册:2007-12-24

我现在又出现了一个问题啦!
2008-1-9 14:34
cumtsc
Rank: 1
等级:新手上路
帖子:9
积分:204
注册:2007-12-24

我的代码是这样。在我电脑上运行没有问题,到别的电脑上时,就说什么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-1-9 14:37
fairy4
Rank: 3Rank: 3
来自:triosoft
等级:中级会员
威望:1
帖子:355
积分:4171
注册:2007-11-1

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-1-9 15:26
cumtsc
Rank: 1
等级:新手上路
帖子:9
积分:204
注册:2007-12-24

我的代码里面Dim xlApp As New Excel.Application这一句必须是
Dim myexcel As New Microsoft.Office.Interop.Excel.Application
要不然VB2005就会报错!那是怎么会事啊??
2008-1-10 09:57
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.045670 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved