资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb点虐 输出表格 vbnet formatnumber

VB.NET输出到Excel的问题

一、DCOM修复

网站建设哪家好,找成都创新互联公司!专注于网页设计、网站建设、微信开发、微信平台小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了云南免费建站欢迎大家使用!

1.运行:mmc comexp.msc /32,找到我的电脑 - DCom配置中的Microsoft Excel Application

2.在Microsoft Excel Application上点击右键,选择"属性"

3.点击"标识"标签,选择"交互式用户"

4.点击"安全"标签,在"启动和激活权限"上点击"自定义",然后点击对应的"编辑"按钮,在弹出的"安全性"对话框中填加一个"NETWORK SERVICE"用户(注意要选择本计算机名),并给它赋予"本地启动"和"本地激活"权限.

5.依然是"安全"标签,在"访问权限"上点击"自定义",然后点击"编辑",在弹出的"安全性"对话框中也填加一个"NETWORK SERVICE"用户,然后赋予"本地访问"权限.

二、如果找不到Microsoft Excel 应用程序

1、进行OFFICE菜单中的组件重注册

2、如果仍未解决问题,点 开始--运行--输入EXCEL文件所在的路径 “c:\program files\exel.exe” /regserver 进行修复注册

参考:

vb点虐 输出 excel

这里有段VB6.0的,你可以参考。

注意添加引用。

Private Sub Command6_Click()

Dim i, j As Integer

Dim xlApplication As Excel.Application, xlWorkbook As Excel.Workbook, xlSheet

Dim xlApp As Excel.Application

On Error Resume Next

Set xlApplication = GetObject(, "Excel.Application")

Set xlApp = CreateObject("Excel.Application")

If MsgBox("确认将文件信息导出到EXCEL中?�", vbExclamation + vbYesNo, "警告") = vbYes Then

If Err.Number 0 Then Set xlApplication = CreateObject("Excel.Application")

Set xlWorkbook = xlApplication.Workbooks.Add

Set xlSheet = xlWorkbook.ActiveSheet

xlSheet.Cells(1, 2) = lblcl.Caption

xlSheet.Range("A1:E1").MergeCells = True

xlSheet.Range("A1:E1").HorizontalAlignment = xlCenter

xlSheet.Cells(2, 2).ColumnWidth = 18

For i = 1 To DataGrid1.Columns.Count

xlSheet.Cells(2, 1) = "编号"

xlSheet.Cells(2, i + 1) = DataGrid1.Columns(i).Caption

For j = 0 To DataGrid1.VisibleRows - 1

xlSheet.Cells(j + 3, 1) = j + 1

xlSheet.Cells(j + 3, i + 1) = DataGrid1.Columns(i).CellText(DataGrid1.RowBookmark(j))

Next j

Next i

xlApplication.Visible = True

Set xlSheet = Nothing

Set xlWorkbook = Nothing

Set xlApplication = Nothing

'xlApp.Range("A2:L2").Columns.Interior.ColorIndex = 40

'xlApp.Range("A2:L2").Borders.LineStyle = xlContinuous

'xlApp.Visible = True

'xlApp.Range(xlSheet.Cells(2 + PartsRs.RecordCount + 1, 1), xlSheet.Cells(2 + PartsRs.RecordCount + 1, 8)).Columns.Interior.ColorIndex = 40

'xlApp.Range(xlSheet.Cells(2 + PartsRs.RecordCount + 1, 1), xlSheet.Cells(2 + PartsRs.RecordCount + 1, 8)).Borders.LineStyle = xlContinuous

Else

MsgBox "无信息可供您导出,请确认!", vbExclamation + vbOKOnly, "警告"

End If

End Sub

在VB点虐 中,如何使几个数组变量按照列表示出来,并输出到指定的EXCEL表格中!

先在: My Project 中引用 Microsoft Excel 11.0 Object Library(这个是Excel 2003,Excel 2007 是12.0),之后在窗体代码中加入相关内容就行了。以下是一个窗体的简单实例

假设在C盘根文件夹中有:TEST.xls

Public Class 引用EXCEL窗体

Private A() As String = {"A", "B", "CC", "C", "D"}

Private B() As Integer = {1, 22, 34, 50, 16, 99, 14}

Private excelapp As New Microsoft.Office.Interop.Excel.Application

Private excelworkbook As Microsoft.Office.Interop.Excel.Workbook

Private Sub 引用EXCEL_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim Index As Integer

excelworkbook = excelapp.Workbooks.Open("c:\test.xls")

excelapp.Application.Workbooks.Add(True)

excelapp.Cells(1, 1) = "数组:A"

For Index = 0 To UBound(A)

excelapp.Cells(Index + 2, 1) = A(Index)

Next

excelapp.Cells(1, 2) = "数组:B"

For Index = 0 To UBound(B)

excelapp.Cells(Index + 2, 2) = B(Index)

Next

excelapp.Visible = True

End Sub

End Class

运行结果:

数组:A 数组:B

A 1

B 22

CC 34

C 50

D 16

99

14


当前标题:vb点虐 输出表格 vbnet formatnumber
网页链接:http://cdkjz.cn/article/ddjhiie.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220