Excel and TempTable

Posted by lefty1984 on 28-Nov-2015 15:33

Hi,

Is it posible to create a TempTable from an Excel file (CSV, XLS OR XSLX) without predefined field names?

I want to create a dynamic TempTable created from the Excel file.

Greatz,

Rick

All Replies

Posted by James Palmer on 29-Nov-2015 05:55



Are you asking how to create a dynamic temp table or how to deal with excel?

James Palmer | Application Developer & DBA
Tel: 01253 785103

Posted by lefty1984 on 30-Nov-2015 04:50

how to create a dynamic temp table.

Posted by Sanjeva Manchala on 30-Nov-2015 04:58

Hi,
 
A quick Google search shown the following article from Progress KBase:
 
Hope this helps,
Sanjeev.

Posted by lefty1984 on 30-Nov-2015 05:54

Hi Sanjeev,

I found that one, but how do i create it from excel headers?

Greatz..

Posted by James Palmer on 30-Nov-2015 06:04

So this is how I do it.

I read the excel headers using the com object stuff - I'm in Windows so I can. I then go and look at the format of the next cell down and parse the format so I can work out a data type for it. I then create a column in my dynamic table that's named after the column header (with non-alphanumeric characters removed), with a datatype we just calculated. I then do this for the rest of the columns in the sheet until I come to a column with no header.

Posted by lefty1984 on 06-Dec-2015 15:00

Define Variable FileNaam As Character No-undo.
Define Variable TabelNaam As Character No-undo.

FileNaam = "c:\tmp\bianca.csv".
TabelNaam = "ttbianca".

Define Variable ttHandle As Handle.
Define Variable bHandle As Handle.
Define Variable qHandle As Handle.
Define Variable fHandle As Handle.
Define Variable bTableHandle As Handle No-undo.

Define Variable ExcelHeaders As Character No-undo.
Define Variable ExcelData As Character No-undo.
Define Variable pColName As Character No-undo.
Define Variable pDbColName As Character No-undo.

Define Variable i As Integer No-undo.

Create Temp-table ttHandle.

Input From Value(FileNaam).

Import Unformatted ExcelHeaders.

Do i=1 To Num-entries(ExcelHeaders,";"):
    pColName = Entry(i, ExcelHeaders,";").
    If pColName Eq "" Then Next.
    /*Display "1 " pcolname Format "x(25)".*/
    pDbColName = TabelNaam + "." + pColName.
    /*Display "2 " pdbcolname Format "x(25)".  */
    ttHandle:Add-new-field(pColName,"Character").
End.

ttHandle:Temp-table-prepare("ttFile").

bHandle = ttHandle:Default-buffer-handle.

Repeat:
    Import UNFORMATTED ExcelData.
    bHandle:Buffer-create.

    Do i=1 To Num-entries(ExcelHeaders,";"):
        pColName = Entry(i, ExcelHeaders,";").
        If pColName Eq "" Then Next.
        fHandle = bHandle:Buffer-field(pColName).
        fHandle:Buffer-value = Entry(i,         ExcelData,";").
       /* Display pColname exceldata.*/
    End.
End.

Input Close.

Create Query qHandle.
qHandle:Set-buffers(bHandle).
qHandle:Query-prepare("FOR EACH ttFile").
qHandle:Query-open().

Create Buffer bTableHandle For Table TabelNaam.

Repeat Transaction:
    qHandle:Get-next().
    If qHandle:Query-off-end Then Leave.
    
    bTableHandle:Buffer-create().
    bTableHandle:Buffer-copy(bHandle).
    bTableHandle:Buffer-release().
End.

qHandle:Query-close().
bHandle:Buffer-release().
                                     
Delete Object bTableHandle.
Delete Object ttHandle.
Delete Object qHandle.


Can anyone tell me why this code wont do anything?

Posted by James Palmer on 07-Dec-2015 03:28

Is your data really separated by ';'?

Posted by James Palmer on 07-Dec-2015 03:29

You don't need to do this:

pDbColName = TabelNaam + "." + pColName.

The table name is defined when you temp-table-prepare. Just use pColName and see if that gets you closer. 

Posted by lefty1984 on 07-Dec-2015 14:01

yup

Posted by lefty1984 on 07-Dec-2015 14:07

unfortunately i get still this error

Could not create buffer object for table <table name>. (7334)

A buffer object could not be created for the table.  Perhaps the table referenced is no longer in scope or belongs to a database that has become disconnected.

Posted by Brian K. Maher on 07-Dec-2015 14:14

Lefty,
 
That isn't the error you are getting.  That is the generic error text.  I suggest you post the EXACT error text so folks can know what table is being referred to. You should also post the current code since I don't think anyone here is psychic (smile).
 
Brian
 

This thread is closed