Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Aug 2003
    Location
    Maryland
    Posts
    17

    Unanswered: Importing from Excel

    I am having a problem with DTS importing NULL values from an Excel spreadsheet when there are numbers and text in the same column. Other than that, the import works fine. I am using VBScript in an ASP web page to create and execute a DTS package to import an Excel file.

    I have read Allan Mitchell's article about using IMEX=1 (http://www.sqldts.com/default.aspx?254). I added IMEX=1 and modified the registry setting, but when I do that NO data at all is imported.

    Any ideas? My code is very long, so I'll only post it if you'd really like to see it.

    Much thanks in advance!

    Bill

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    I would export the excel file into a delimited file - the ms driver for excel causes too many headaches. Also, did you modify the TypeGuessRows setting in your registry ?

  3. #3
    Join Date
    Aug 2003
    Location
    Maryland
    Posts
    17
    Originally posted by rnealejr
    I would export the excel file into a delimited file - the ms driver for excel causes too many headaches. Also, did you modify the TypeGuessRows setting in your registry ?
    I did modify the TypeGuessRows setting to 0. Is there a way to programmatically export the Excel file to a CSV file?

    Thanks,

    Bill

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    It has been a while since I used the TypeGuessRows - but I believe setting it to 0 will not work - you have to explicitly supply a value (something big enough to sample your data).

    Programmatically - Do you mean from within sql server or any executable ?

  5. #5
    Join Date
    Aug 2003
    Location
    Maryland
    Posts
    17
    Originally posted by rnealejr
    It has been a while since I used the TypeGuessRows - but I believe setting it to 0 will not work - you have to explicitly supply a value (something big enough to sample your data).

    Programmatically - Do you mean from within sql server or any executable ?
    I read somewhere to set it to 0 and use IMEX=1. I just tried setting it to 16 and 8, but neither of those worked either.

    Actually, when I said programatically I meant VBScript, but I guess that's for the VBScript forum!

    Thanks,

    Bill

  6. #6
    Join Date
    Feb 2002
    Posts
    2,232
    You can create an excel object - open the workbook - use the saveas method for the workbook.

  7. #7
    Join Date
    Aug 2003
    Location
    Maryland
    Posts
    17
    Originally posted by rnealejr
    You can create an excel object - open the workbook - use the saveas method for the workbook.
    Where can I find information on using the excel object's saveas function? I'm sure there are a number of options, and I'd like to take a look at them.

    Thanks!

    Bill

  8. #8
    Join Date
    Feb 2002
    Posts
    2,232
    Here is the snapshot from the help (Also, look for a vbaxl9.chm file on your computer):

    Saves changes to the sheet (Syntax 1) or workbook (Syntax 2) in a different file.

    Syntax 1

    expression.SaveAs(Filename, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AddToMru, TextCodePage, TextVisualLayout)

    Syntax 2

    expression.SaveAs(Filename, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodePage, TextVisualLayout)

    expression Required. An expression that returns a Chart or Worksheet object (Syntax 1) or a Workbook object (Syntax 2).

    Filename Optional Variant. A string that indicates the name of the file to be saved. You can include a full path; if you donít, Microsoft Excel saves the file in the current folder.

    FileFormat Optional Variant. The file format to use when you save the file. For a list of valid choices, see the FileFormat property. For an existing file, the default format is the last file format specified; for a new file, the default is the format of the version of Excel being used.

    Password Optional Variant. A case-sensitive string (no more than 15 characters) that indicates the protection password to be given to the file.

    WriteResPassword Optional Variant. A string that indicates the write-reservation password for this file. If a file is saved with the password and the password isnít supplied when the file is opened, the file is opened as read-only.

    ReadOnlyRecommended Optional Variant. True to display a message when the file is opened, recommending that the file be opened as read-only.

    CreateBackup Optional Variant. True to create a backup file.

    AccessMode Optional Variant. The workbook access mode. Can be one of the following XlSaveAsAccessMode constants: xlShared (shared list), xlExclusive (exclusive mode), or xlNoChange (donít change the access mode). If this argument is omitted, the access mode isnít changed. This argument is ignored if you save a shared list without changing the file name. To change the access mode, use the ExclusiveAccess method.

    ConflictResolution Optional Variant. Specifies the way change conflicts are resolved if the workbook is a shared list. Can be one of the following XlSaveConflictResolution constants: xlUserResolution (display the conflict-resolution dialog box), xlLocalSessionChanges (automatically accept the local userís changes), or xlOtherSessionChanges (accept other changes instead of the local userís changes). If this argument is omitted, the conflict-resolution dialog box is displayed.

    AddToMru Optional Variant. True to add this workbook to the list of recently used files. The default value is False.

    TextCodePage Optional Variant. Not used in U.S. English Microsoft Excel.

    TextVisualLayout Optional Variant. Not used in U.S. English Microsoft Excel.


    The following are the available file formats:

    xlAddIn
    xlCSV

    xlCSVMac

    xlCSVMSDOS

    xlCSVWindows

    xlCurrentPlatformText

    xlDBF2

    xlDBF3

    xlDBF4

    xlDIF

    xlExcel2

    xlExcel2FarEast

    xlExcel3

    xlExcel4

    xlExcel4Workbook

    xlExcel5

    xlExcel7

    xlExcel9795

    xlHTML

    xlIntlAddIn

    xlIntlMacro
    xlSYLK
    xlTemplate

    xlTextMac

    xlTextMSDOS

    xlTextPrinter

    xlTextWindows

    xlUnicodeText

    xlWJ2WD1

    xlWK1

    xlWK1ALL

    xlWK1FMT

    xlWK3

    xlWK4

    xlWK3FM3

    xlWKS

    xlWorkbookNormal

    xlWorks2FarEast

    xlWQ1

    xlWJ3

    xlWJ3FJ3

  9. #9
    Join Date
    Aug 2003
    Location
    Maryland
    Posts
    17
    Awesome, thanks!

    So if I do this:

    <code>
    set xlApp = CreateObject("excel.application")
    xlApp.Workbooks.Open <filename>
    xlApp.ActiveWorkbook.SaveAs <newFileName>, xlCSVWindows
    xlApp.ActiveWorkbook.Close
    xlApp.Quit
    Set xlApp = Nothing
    </code>

    It would save it as a CSV file?

    Thanks!

    Bill

  10. #10
    Join Date
    Feb 2002
    Posts
    2,232
    Yes, that looks good. Let me know if there are any problems.

  11. #11
    Join Date
    Aug 2003
    Location
    Maryland
    Posts
    17
    Originally posted by rnealejr
    Yes, that looks good. Let me know if there are any problems.
    Thanks, I'm going to try to give it a test today!

  12. #12
    Join Date
    Aug 2003
    Location
    Maryland
    Posts
    17
    Originally posted by rnealejr
    Yes, that looks good. Let me know if there are any problems.
    Okay, I tried that code and I'm getting the following error message:

    Microsoft Excel error '800a03ec'
    SaveAs method of Workbook class failed

    Any ideas?

    Thanks!

    Bill

  13. #13
    Join Date
    Aug 2003
    Location
    Maryland
    Posts
    17
    Originally posted by rnealejr
    Yes, that looks good. Let me know if there are any problems.
    Okay, I may have found the issue, but I'm not sure. I saved the current workbook file format value to a variable and printed it to the screen. The value was -4143. Is the fileformat value supposed to be a number or the values from the help file (i.e., xlCSV)?

    Thanks for all your help!

    Bill

  14. #14
    Join Date
    Feb 2002
    Posts
    2,232
    I do not have to vb at the moment to confirm but the xlCSV value should be and the xlWindowsCSV is 23.

  15. #15
    Join Date
    Feb 2002
    Posts
    2,232
    Also, sorry for the delay - your post got buried.

Posting Permissions

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