从vb.net上传值到excel [英] Upload Values to excel from vb.net

查看:53
本文介绍了从vb.net上传值到excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在将值检索到数据集,并尝试将这些值上传到excel.
但是我收到此错误无法创建ActiveX组件.代码粘贴在下面.

Hi ,

I am retriving the values to dataset and trying to upload those values to excel .
But i am getting this error Cannot create ActiveX component.The code is pasted below.

Public Function CreateXLObjects(ByVal XLName As String) As Object
        Try
            XL = CreateObject("Excel.Application")
            Dim TemplateXL As String = XLName
            If TemplateXL.Substring(TemplateXL.Length - 1) <> "\" Then TemplateXL = TemplateXL & "\"
            TemplateXL = TemplateXL & "SS 2 1-ClosureReport.xls"
            WB = XL.Workbooks.Add(TemplateXL)
            Return WB
        Catch ex As Exception
        End Try
        Return WS
    End Function


尝试创建对象时,即XL = CreateObject("Excel.Application").
请帮助我它非常紧急的


when trying to createobject i.e XL = CreateObject("Excel.Application").
Please help me its very urgent

推荐答案

Havent以前使用过CreateObject,但是为什么不使用这里的代码作为模板呢?
http://support.microsoft.com/kb/302084 [
Havent used CreateObject before but why dont you use the code here as a template instead:
http://support.microsoft.com/kb/302084[^]


这是我的代码
Here is my code
'excel
Dim oexcel As Object
oexcel = CreateObject("Excel.Application")
Dim obook As Excel.Workbook
Dim osheet As Excel.Worksheet
Dim fnExc As String
Dim curLine As Integer = 0

' this should be used only once
obook = oexcel.Workbooks.Add

'first
If oexcel.Application.Sheets.Count() < 1 Then
    osheet = CType(obook.Worksheets.Add(), Excel.Worksheet)
Else
    osheet = oexcel.Worksheets(1)
End If
osheet.Name = "Payroll Detail Report"

'second
If oexcel.Application.Sheets.Count() < 2 Then
    osheet = CType(obook.Worksheets.Add(), Excel.Worksheet)
Else
    osheet = oexcel.Worksheets(2)
End If
osheet.Name = "Payroll Detail Report (real)"

'third
If oexcel.Application.Sheets.Count() < 3 Then
    osheet = CType(obook.Worksheets.Add(), Excel.Worksheet)
Else
    osheet = oexcel.Worksheets(3)
End If
osheet.Name = "Payroll Summary Report"

'next
If oexcel.Application.Sheets.Count() < 4 Then
    osheet = CType(obook.Worksheets.Add(), Excel.Worksheet)
Else
    osheet = oexcel.Worksheets(4)
End If
osheet.Move(After:=obook.Worksheets(obook.Worksheets.Count))
osheet.Name = "Weekly Payroll Report - Week 1"


obook.SaveAs(fnExc)
obook.Close()
obook = Nothing




相同的视频示例
http://www.youtube.com/watch?v=BaYxwKUnw0U [




Same video example http://www.youtube.com/watch?v=BaYxwKUnw0U[^]


这篇关于从vb.net上传值到excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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