Page 2 of 2 FirstFirst 12
Results 41 to 48 of 48

Thread: create excel file without excel installed in vb6.0

  1. #41
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: create excel file without excel installed in vb6.0

    Excellent....(rs.movefirst)...
    Thanks for all the work you did....I may never use this, but it ill sit in my bag in case.

    Sam

  2. #42
    Addicted Member Wolfgang Enzinger's Avatar
    Join Date
    Apr 2014
    Location
    Munich, Germany
    Posts
    160

    Re: create excel file without excel installed in vb6.0

    Quote Originally Posted by LaVolpe View Post
    A follow up to this post. Actually came upon a need to create an XLS format without having MS Office installed. In post #2 above a DAO example exists. Here is a similar example using ADO:
    Code:
    Sub Main()
    Dim cn As ADODB.Connection
    Dim rs As  ADODB.Recordset
    
    Set cn = New ADODB.Connection
    cn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0; data source=c:\test.xls; Extended Properties=""Excel 8.0;HDR=YES"""
    cn.Open 
    
    cn.Execute "Create Table Table1(field1 VARCHAR(255))"
    Set rs = New ADODB.RecordSet
    rs.Open "[Table1$]", cn, adOpenDynamic, adLockOptimistic, adCmdTable
    
    rs.AddNew
    rs.Fields(0).Value = "hello!"
    rs.Update
    rs.Close: cn.Close
    Set rs = Nothing
    Set cn = Nothing
    End Sub
    Diggin' out an old thread ... it looks like this solution, as well as my DAO code in post #2, doesn't work anymore. They somehow broke it.

  3. #43
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: create excel file without excel installed in vb6.0

    Working fine here. Somewhat more elaborate example.
    Attached Files Attached Files

  4. #44
    Addicted Member Wolfgang Enzinger's Avatar
    Join Date
    Apr 2014
    Location
    Munich, Germany
    Posts
    160

    Re: create excel file without excel installed in vb6.0

    Quote Originally Posted by dilettante View Post
    Working fine here. Somewhat more elaborate example.
    You're right, this works, thank you.

    However, did you try the examples in posts #2 and #30, too? These used to work as well, but they do not anymore (tested in Win7 and 8.1 so far). Creating the XLS file actually happens, but in the same step error 3274 occurs (something like "the external table does not have the expected format" - translated from German here).

    Anyway, your code shows that ADOX still does the job. Thanks for that.

    Wolfgang

  5. #45
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,152

    Re: create excel file without excel installed in vb6.0

    To counter the spam here are links to free resources:

    https://gist.github.com/wqweto/4eb3ecee2961ec2f60bf -- can export only tabular data in .xls/.xlsx/.xlsb/.csv files
    https://github.com/wqweto/Biff12Writer -- can export pictures, multiple sheets, text formatting, etc. in BIFF12 (.xlsb) files

    cheers,
    </wqw>

  6. #46
    Lively Member
    Join Date
    May 2022
    Posts
    85

    Re: create excel file without excel installed in vb6.0

    I know it's and old post, but if someone can help..

    I'm using the first link from wqweto to export to excel an adodb recordset (https://gist.github.com/wqweto/4eb3ecee2961ec2f60bf -- can export only tabular data in .xls/.xlsx/.xlsb/.csv files)

    It's working fine, I modified all the "stable" variables to this: [" & sTable & "], this way i can create table names with dots, and more chars.

    But i have a problem when creating the destination recordset.

    Here:

    Code:
       '--- dump source recordset
        If Not rsSrc.BOF And Not rsSrc.EOF Then
            rsSrc.MoveFirst
        End If
    
        Do While Not rsSrc.EOF
            rsDest.AddNew
            For Each oFld In rsSrc.Fields
                rsDest.Fields(oFld.Name).Value = oFld.Value
            Next
            rsDest.Update
            rsSrc.MoveNext
        Loop
    If I want to use a name of the field something llike "Cod. Postal" is not working due the "."

    How can i change this line: rsDest.Fields(oFld.Name).Value = oFld.Value in order to accept the . and save the values? any Ideas?

    Thanks for all


    Edit:

    I must check all possibilities but changing the name for the position it seems to be working fine, the code:

    Code:
        Dim aa As Single
        
        Do While Not rsSrc.EOF
            rsDest.AddNew
            aa = 0
            For Each oFld In rsSrc.Fields
                rsDest.Fields(aa).Value = oFld.Value
                aa = aa + 1
            Next
            rsDest.Update
            rsSrc.MoveNext
        Loop
    Last edited by Calcu; Nov 1st, 2023 at 06:05 PM.

  7. #47
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,152

    Re: create excel file without excel installed in vb6.0

    Yes, escaping Workbook name needs some more attention in the code. Currenly the procedure expects this name to be quoted from the caller, i.e. use "[Cod. Postal]" when calling WriteToExcel, not "Cod. Postal" for Workbook name but obv. this is cumbersome and error prone.

    I have no idea what is the problem with field names though and why would these need quoting when accessing Fields collection. Using numeric indexes is a solution to a problem that should never happen.

    Btw, Dim aa As Single is dubious -- better use Long.

    cheers,
    </wqw>

  8. #48
    Lively Member
    Join Date
    May 2022
    Posts
    85

    Re: create excel file without excel installed in vb6.0

    Thanks! did it with Long.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width