数据导出到excel,但是excel上没有标题文本,请帮助我...... [英] Data export to excel but header text is not come on the excel, Please Help me...............

查看:169
本文介绍了数据导出到excel,但是excel上没有标题文本,请帮助我......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将数据导出到excel,但是excel上没有标题文本,您能帮我吗?我使用的是

将ExcelApp作为对象变暗,将ExcelBook作为对象变暗
       将ExcelSheet变暗为对象
        Dim i As Integer
        Dim j As Integer

        '创建excel对象
        ExcelApp = CreateObject("Excel.Application")
        ExcelBook = ExcelApp.WorkBooks.Add
        ExcelSheet = ExcelBook.WorkSheets(1)

       使用ExcelSheet

           对于我= 1 To Me.DataGridView1.RowCount
                .cells(i,1)= Me.DataGridView1.Rows(i-1).Cells(0).Value
               对于j = 1到DataGridView1.Columns.Count-1
                    .cells(i,j + 1)= DataGridView1.Rows(i-1).Cells(j).Value
               下一个
           下一个

       结尾为

        ExcelApp.Visible =真
        '
        ExcelSheet =没什么
        ExcelBook =没什么
        ExcelApp =什么都没有

此编码

Data export to excel but header text is not come on the excel, can you help me. i use the 

Dim ExcelApp As Object, ExcelBook As Object
        Dim ExcelSheet As Object
        Dim i As Integer
        Dim j As Integer

        'create object of excel
        ExcelApp = CreateObject("Excel.Application")
        ExcelBook = ExcelApp.WorkBooks.Add
        ExcelSheet = ExcelBook.WorkSheets(1)

        With ExcelSheet

            For i = 1 To Me.DataGridView1.RowCount
                .cells(i, 1) = Me.DataGridView1.Rows(i - 1).Cells(0).Value
                For j = 1 To DataGridView1.Columns.Count - 1
                    .cells(i, j + 1) = DataGridView1.Rows(i - 1).Cells(j).Value
                Next
            Next

        End With

        ExcelApp.Visible = True
        '
        ExcelSheet = Nothing
        ExcelBook = Nothing
        ExcelApp = Nothing

this coding 

推荐答案

此代码用于获取Excel工作表第一行的列文本.用您的Excel代码替换Console.WriteLine.

This code is for getting column text for the first row of an Excel sheet. Replace Console.WriteLine with your excel code.

For colIndex As Integer = 0 To DataGridView1.Columns.Count - 1
    Console.WriteLine(DataGridView1.Columns(colIndex).HeaderText)
Next


这篇关于数据导出到excel,但是excel上没有标题文本,请帮助我......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆