save a flat export data file as an excel file

Discussion in 'ASP General' started by c676228, Jul 17, 2008.

  1. c676228

    c676228 Guest

    Hi all,

    I have a question for you.

    I have a .csv file which has many lines of data.
    Each line has many data fields which are delimited by ",".
    Now I need to extract part of data from this file but save it as an excel
    file.

    The data in this excel file will be imported into an Access database. The
    reason I have to save it into an excel file is Access program only accept
    excel data file, but not flat text file.

    Can you tell me how to save extracted data into an excel file?

    Thanks.
    --
    Betty
    c676228, Jul 17, 2008
    #1
    1. Advertising

  2. c676228

    Old Pedant Guest

    WHY???

    Why go to the trouble of converting CSV to Excel and then Excel to Access????

    Why not just use ASP to go directly from CSV to Access???

    <%
    Set csvconn = Server.CreateObject("ADODB.Connection")
    csvconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\path\to\DIRECTORY\only\;" & _
    "Extended Properties=""text;HDR=Yes;FMT=Delimited"""

    Set dbconn = Server.CreateObject("ADODB.Connection")
    dbconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=c:\path\to\yourAccessDatabase.mdb;"

    SQL = "SELECT * FROM nameOfFile.csv"
    Set inRS = csvconn.Execute( SQL )

    Set outRS = Server.CreateObject("ADODB.Recordset")
    outRS.Open "TableName", dbconn, adOpenStatic, adLockPessimistic

    Do Until inRS.EOF
    outRS.AddNew
    outRS("field1") = inRS("fieldA")
    outRS("field2") = inRS("fieldB")
    ... etc ...
    outRS.Update
    inRS.MoveNext
    Loop
    outRS.Close
    inRS.Close
    dbConn.Close
    csvConn.Close
    %>

    THere are actually some even more efficient ways to do this, but without
    know more of your details I'm hesitant to choose one. The above is simple
    minded enough it should work so long as your CSV file doesn't have any quirks.
    Old Pedant, Jul 17, 2008
    #2
    1. Advertising

  3. Hi Betty,

    From your description, you have an existing CSV file and you want to
    extract some part of the CSV file out and export them into excel file,
    correct?

    Are you wantting to do it programmtically or just want to do such an
    transformation and not necessary to use code? Based on my experience,

    #SQL Server 2005 ┬ĘC Integration Services
    http://technet.microsoft.com/en-us/sqlserver/bb671392.aspx

    #How to import an Excel file into SQL Server 2005 using Integration Services
    http://www.builderau.com.au/program/sqlserver/soa/How-to-import-an-Excel-fil
    e-into-SQL-Server-2005-using-Integration-Services/0,339028455,339285948,00.h
    tm

    http://www.mssqltips.com/tip.asp?tip=1202

    If this need to be done programmtically, a common approach is read the csv
    file via OLD db provider(jet engine) and access the data like a database
    table. However, I think it maybe a bit hard to export it exactly as excel
    format, btw, excel can directly convert csv format, will it work for your
    case.

    #How To Open Delimited Text Files Using the Jet Provider's Text IIsam
    http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:
    80/support/kb/articles/Q262/5/37.ASP&NoWebContent=1&NoWebContent=1

    #Using OleDb to import text files (tab, csv, custom)
    http://www.codeproject.com/KB/cs/UsingJetForImport.aspx

    Also, are you going to do this converting in ASP web page? If not, for
    normal desktop applicatin, we can use excel automation object model to
    create excel worksheet:

    http://support.microsoft.com/kb/302096

    http://support.microsoft.com/kb/302094

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
    --------------------
    >From: =?Utf-8?B?YzY3NjIyOA==?= <>
    >Subject: save a flat export data file as an excel file
    >Date: Wed, 16 Jul 2008 20:24:01 -0700


    >
    >Hi all,
    >
    >I have a question for you.
    >
    >I have a .csv file which has many lines of data.
    >Each line has many data fields which are delimited by ",".
    >Now I need to extract part of data from this file but save it as an excel
    >file.
    >
    >The data in this excel file will be imported into an Access database. The
    >reason I have to save it into an excel file is Access program only accept
    >excel data file, but not flat text file.
    >
    >Can you tell me how to save extracted data into an excel file?
    >
    >Thanks.
    >--
    >Betty
    >
    Steven Cheng [MSFT], Jul 17, 2008
    #3
  4. Re: WHY???

    "Old Pedant" <> wrote in message
    news:...
    > Why go to the trouble of converting CSV to Excel and then Excel to
    > Access????
    >
    > Why not just use ASP to go directly from CSV to Access???
    >
    > <%
    > Set csvconn = Server.CreateObject("ADODB.Connection")
    > csvconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    > "Data Source=c:\path\to\DIRECTORY\only\;" & _
    > "Extended Properties=""text;HDR=Yes;FMT=Delimited"""
    >
    > Set dbconn = Server.CreateObject("ADODB.Connection")
    > dbconn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    > "Data Source=c:\path\to\yourAccessDatabase.mdb;"
    >
    > SQL = "SELECT * FROM nameOfFile.csv"
    > Set inRS = csvconn.Execute( SQL )
    >
    > Set outRS = Server.CreateObject("ADODB.Recordset")
    > outRS.Open "TableName", dbconn, adOpenStatic, adLockPessimistic
    >
    > Do Until inRS.EOF
    > outRS.AddNew
    > outRS("field1") = inRS("fieldA")
    > outRS("field2") = inRS("fieldB")
    > ... etc ...
    > outRS.Update
    > inRS.MoveNext
    > Loop
    > outRS.Close
    > inRS.Close
    > dbConn.Close
    > csvConn.Close
    > %>
    >
    > THere are actually some even more efficient ways to do this, but without
    > know more of your details I'm hesitant to choose one. The above is simple
    > minded enough it should work so long as your CSV file doesn't have any
    > quirks.
    >


    Yep. Much more efficient is to simpy set up a connection to the Access
    database, and then use a SQL statement like this:

    INSERT INTO AccessTable (Field1, Field2, ...Fieldn) SELECT Col1, Col2,
    ....Coln FROM [Text;DATABASE=" & path_to_file & ";].[myfile.csv]

    More info here: http://www.mikesdotnetting.com/Article.aspx?ArticleID=67
    (it's .NET - but the SQL etc is identical for classic ASP).

    --
    Mike Brind
    MVP - ASP/ASP.NET
    Mike Brind [MVP], Jul 17, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U3JpZGhhcg==?=

    using Microsoft Excel image for Export to Excel button

    =?Utf-8?B?U3JpZGhhcg==?=, Dec 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,098
    =?Utf-8?B?U3JpZGhhcg==?=
    Dec 9, 2005
  2. Server Control
    Replies:
    0
    Views:
    741
    Server Control
    Mar 21, 2006
  3. =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=

    Export to Excel (Default File Type - Excel)

    =?Utf-8?B?SGVtYW50IFNpcGFoaW1hbGFuaQ==?=, Apr 24, 2006, in forum: ASP .Net
    Replies:
    15
    Views:
    17,511
    syed hassan
    May 21, 2009
  4. Grey
    Replies:
    4
    Views:
    1,965
    Mark Rae [MVP]
    Oct 17, 2007
  5. Replies:
    2
    Views:
    127
    Dan Anderson
    Nov 21, 2003
Loading...

Share This Page