Create Text or CSVFile

  1. Newline characters: chr(13) & chr(10)
  2. position = page_size * (page – 1) + 1
  3. Tab character: chr(9)
  4. File handler:
    set fso = createObject("Scripting.FileSystemObject")

    path = "../list/White.csv"
    set file = fso.createTextFile(server.MapPath(path), true, true)
  5. total = rs.recordCount
  6. How to get page count:
    rs.pageSize = 100
    page_count = rs.pageCount 
  7. To improve performance, write contents every specific number of records:
    if i mod 500 = 0 then
    file.writeLine temp & field_line
    temp = ""
    else
    temp = temp & field_line & new_line
    end ifrs.moveNext

    if rs.eof then
    file.writeLine temp
    exit for
    end if

  8. To avoid numbers that start with "0" will be removed, need to add chr(127) before value
     

​Sample:

<%@ codepage=65001 %>
<!-- #include file="classes/DB_Class.asp" -->
<!-- #include file="classes/Functions.asp" -->
<!-- #include file="includes/init_page.asp" -->
<%
csv_name = "Media_Database.csv"
headers = array("公司", "名字", "職稱", "商務電話", "傳真", "行動電話", "電子郵件", "總部地址", "備註", "First Tag", "Second Tag", "Third Tag", "Country")

dim fs,fname
set fs=Server.CreateObject("Scripting.FileSystemObject")
set file = fs.CreateTextFile(Server.mapPath("uploaded/" & csv_name),true)

file.WriteLine join(headers, ",")
file.Close
set file=nothing
set fs=nothing

response.redirect "uploaded/" & csv_name
%>

 

4 thoughts on “Create Text or CSVFile

  1. I’m extremely impressed along with your writing abilities and also with the structure for your blog. Is that this a paid topic or did you modify it yourself? Either way stay up the nice quality writing, it’s rare to see a great weblog like this one nowadays..

  2. Amazing things here. I am very happy to see your post. Thank you so much and I’m having a look ahead to contact you. Will you kindly drop me a mail?

  3. Generally I don’t learn post on blogs, but I wish to say that this write-up very forced me to check out and do so! Your writing style has been amazed me. Thanks, very nice article.

  4. You actually make it seem so easy together with your
    presentation but I to find this topic to be really one thing that I
    feel I would by no means understand. It kind of feels too complicated and
    extremely large for me. I’m looking forward in your subsequent post, I will try to get the cling of it!

Comments are closed.