weixin_40187983
weixin_40187983
2019-04-27 13:07

vb.net 导出Excel后,格式要固定行的高度及数字转文字-线上等

5
  • visual studio

如图片,现在主要有两点问题
1、行的高度,乎大乎小,我想统一成,比如14像素,要怎么写呢

2、手机号及身分证号是文字,但说excel就变数字了
比如我要指定D和M这两栏必需是文字,要怎么做呢?

图片说明

以下为我的代码
Private Sub ExcelExport_New(ByVal dt As DataTable, ByVal ProgressBar1 As Object)
ProgressBar1.Visible = True
ProgressBar1.Value = 10
'建立Excel
Dim xlApp, xlBook, xlSheet As Object
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets(1)

    Dim row As DataRow                               '定义row为datatable的行
    Dim col As DataColumn                            '定义col为datatable的列
    Dim rowindex, colindex As Integer

    '打开sheet1那页
    xlSheet = xlApp.Worksheets("sheet1")

    '赋初值
    rowindex = 1                                        '行(原值1)
    colindex = 0                                             '列
    '写入字段名
    For Each col In dt.Columns
        colindex = colindex + 1
        xlApp.Cells(1, colindex) = col.ColumnName            '原值是1,
    Next

    '向表格中写入具体内容
    For Each row In dt.Rows
        rowindex = rowindex + 1
        colindex = 0
        For Each col In dt.Columns
            colindex = colindex + 1
            xlApp.Cells(rowindex, colindex) = row(col.ColumnName)
        Next
        ProgressBar1.Value = rowindex * (ProgressBar1.Maximum / dt.Rows.Count - 1)
    Next
    '显示Excel应用程序
    ProgressBar1.Value = 0
    ProgressBar1.Visible = False
    xlApp.Visible = True

End Sub
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答