注册 登录
编程论坛 VB.NET论坛

求助:怎么让数据库里的数据打印出来

cumtsc 发布于 2007-12-24 15:41, 2339 次点击
请教:打印出来的格式必须按照自己的要求,并且每个数据在固定的位置打印!谢谢各位高手多多指点!
13 回复
#2
fairy42007-12-24 18:03
使用水晶報表!!
#3
cumtsc2007-12-25 10:25
我也用了水晶报表啊!但是有个问题啊!我在别的电脑上安装这个程序时,说那台电脑没有水晶报表,安装不上啊!我想用excel的方式打印我的数据!就是不知道应该怎么弄!代码怎么写
#4
fairy42007-12-25 11:54
按自己要求把數據導出excel,并且設定好excel的格式!如有需要,可提供簡單代碼!
水晶報表打包時時需要把水晶報表的一些控件打包進去的,具體我也不會!可從網上查找資料! 我都是使用excel的!
#5
cumtsc2007-12-26 10:29
问题是我现在连把数据导入excel都不会啊!能不能给个导入实例啊!谢谢啦!我的QQ15471750,邮箱是[email]cumtsc@[/email]
#6
b6292008-01-03 08:54
先導出轉excel再打印 代碼網上很多的 baidu一下就可以了 嘿嘿
#7
b6292008-01-03 08:55
先導出轉excel再打印 代碼網上很多的 baidu一下就可以了 嘿嘿
#8
cumtsc2008-01-03 09:56
现在有出现了一个问题,我怎么才能把值填入excel指定的单元格中呢????我查了一下网上的代码,但是不能运行
各位高手帮我看看是哪里出错啦!
 Dim x As String
        If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            x = OpenFileDialog1.FileName
        End If
        Dim mExcel As Object = CreateObject("Excel.Application")
        Dim App As New Microsoft.Office.Interop.Excel.Application
        Dim xlBook As New Microsoft.Office.Interop.Excel.Workbook
        Dim xlSheet As New Microsoft.Office.Interop.Excel.Worksheet
        mExcel.Workbooks.Open(x)
        mExcel.Visible = True
        xlSheet.Cells(14, 4) = "0712001"
        App = Nothing '交还控制给Excel
        xlBook = Nothing
        xlSheet = Nothing
#9
b6292008-01-04 09:03
給你一個參考一下!
Sub ToExcel(ByVal ctl As System.Web.UI.Control)

        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls")
        HttpContext.Current.Response.Charset = "UTF-8"
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default
        HttpContext.Current.Response.ContentType = "application/ms-excel"
        ctl.Page.EnableViewState = False
        Dim tw As = New
        Dim hw As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(tw)
        ctl.RenderControl(hw)
        HttpContext.Current.Response.Write(tw.ToString())
        HttpContext.Current.Response.End()

    End Sub
#10
b6292008-01-04 09:04
"application/ms-excel"
是excel模板的名字
#11
cumtsc2008-01-09 14:34
我现在又出现了一个问题啦!
#12
cumtsc2008-01-09 14:37
我的代码是这样。在我电脑上运行没有问题,到别的电脑上时,就说什么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
#13
fairy42008-01-09 15:26
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!自己去看看
#14
cumtsc2008-01-10 09:57
我的代码里面Dim xlApp As New Excel.Application这一句必须是
Dim myexcel As New Microsoft.Office.Interop.Excel.Application
要不然VB2005就会报错!那是怎么会事啊??
1