+ Reply to Thread
Results 1 to 2 of 2

import csv file, how to set default column properties

  1. #1
    Registered User
    Join Date
    04-27-2009
    Location
    Newcastle upon Tyne , England
    MS-Off Ver
    Excel 2003
    Posts
    8

    import csv file, how to set default column properties

    Hi

    I produce a CSV file from a mainframe application which users must import into Excel.

    I need to know how I can influence the import wizard into selecting a numeric field with for example leading zeros as a text Column.

    I know I can use the import wizard to manually set the desired columns to text, or write a macro to set the column to text, but as I wont be physically doing the import, I want to make it as easy as possible for the user who receives the comma delimeted mainframe file, to import into a blank worksheet on his workstation.

    I have tried inserting a single leading apostrophe into the csv file for a value that i wish to be treated as text, [as you can when you type into a cell ] but that imports the apostraphe rather than setting the cell to text.

    I would welcome any suggestions as to how I could achieve this

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388

    Re: import csv file, how to set default column properties

    This can be done by creating a database connection to the csv file and using a Schema.ini file to specify the data types for each column in the csv file.
    The Schema.ini file has to be in the same folder as the csv file. Here is an example:

    test.csv file:
    id, description, quantity, cost
    00000001,aa,4,5.00
    00000002,bb,5,5.50
    00000003,cc,6,7.25
    00000004,dd,7,8.51
    00000005,ee,8,8.94
    00000006,ff,9,10.08
    00000007,gg,10,11.59

    Schema.ini file:
    [test.csv]
    ColNameHeader=True
    Format=CSVDelimited
    Col1=ID Text
    Col2=Description Text
    Col3=Quantity Integer
    Col4=Cost Currency

    Create Database connection:
    Data > Import External Data > New Database Query.
    Select <New Data Source>
    In Create New Data Source,
    1. choose a name
    2. select the driver - Microsoft Text Driver (*.txt, *.csv)
    3. click Connect and in ODBC Text Setup select the folder containing the csv file
    4. select a default table - the csv file (optional)

    In Query Wizard, choose the columns from the table and click Next through each dialog to Finish.
    In Import Data choose a cell and click OK.
    When the CSV file changes select a data cell and click Refresh Data on the External Data toolbar (or right-click a data cell).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1