Link to home
Start Free TrialLog in
Avatar of sukimaster
sukimaster

asked on

Export Query to Flat File/ASCII

Hello,

I'm wanting to export the same result page to a flat file with out recreating the query to accomodate to ASCII formating.

First, some history on what I am doing:

I have a report that has an option to allow the individual to export the results to a flat file. What happens on the back end is that the same query is run BUT if the is_download is 1 executes the following two lines:

<cfheader name="content-disposition" value="Inline; filename=AddressLabels.txt">
<cfcontent type="application/unknown" reset="Yes">

I use the 'application/unknown' so that it brings up the 'save as' option instead of displaying the results on the page. Everything works fine.


Here is my dilemma:
I have now been given the task to repeat the process accross ALL our reports (over 50). This can take a long time in that I will now need to create an entire sepatate query in order to get the output to diplay in straight ASCII text. I'm wondering if there is an easier way to accomplish this rather than having me create a whole new query/format layout if the is_download option is selected.

Ideally, if I could just have the above two lines selected and then output the format with all backend html/cf logic code stripped/removed that would accomplish my task.

Otherwise, I'll be quite busy for the next few weeks tweaking this <cfoutput> to work !

If anyone could provide any examples, assistance or any other reference points that would help me I'd GREATLY appreciate it!!

TIA.
Avatar of anandkp
anandkp
Flag of India image

Use value="attachment; instead of value="Inline; - to bring up the save as option.

& if u have all 50 of ur reports to be downloaded using the CFHEADER & CFCONTENT ... then i guess theres no bypassing it.
U'll have to do it

i didnit quite get this :"Ideally, if I could just have the above two lines selected and then output the format with all backend html/cf logic code stripped/removed that would accomplish my task"

let me know

K'Rgds
Anand
Avatar of sukimaster
sukimaster

ASKER

Thanks for your response.

Below is what I meant. I get an output that includes my backend HTML code...

A really good example would be reReplacing the <table... >< /table> tags with "" and the <t r> with a an ascii br and any <td > </ td> with ascii 'tabs' .. Is that possible to parse though an entire < ... > tag w/ cf knowing when to stop/start?


Below is an example of my output. It places the actual HTML code with the cfoutput variables(??)

<!-- begin ascii output -->
     
<table width='100%' cellpadding='0' cellspacing='0' valign='top'><tr width='100%'><td width='100%'><table width="100%" cellpadding="0" cellspacing="0" valign="top"><tr><td align="left" width="70%"> </td><td align="right" width="30%">463&nbsp;</td></tr></table></td></tr><tr><td>Block, Steven</td></tr><tr><td>9287 Orange Crest Ct 2 </td></tr><tr><td>Elk Grove, CA 95624</td></tr><tr><td align='right'>&nbsp;</td></tr><tr><td align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td></tr><tr><td><IMG src='/SISWEB/images/spacer.gif' width='1' height='21'></td></tr></table>
     </td>
     
          <td align="left">
               &nbsp;
               &nbsp;
               &nbsp;
               &nbsp;
               &nbsp;
               &nbsp;
               &nbsp;
               &nbsp;
               &nbsp;
               &nbsp;
          </td>
     
               </td>
          </tr>
          </table>
     </td>
</tr>
</table>


     
     <hr>
     <strong>Rights</strong>
     View: 1
     Edit: 1
     Delete: 0
     Admin: 1
     

</BODY>
</HTML>

<!-- end ascii output -->

Any ideas?

ASKER CERTIFIED SOLUTION
Avatar of anandkp
anandkp
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this may have bugs to work out, but should work. just have your <cfif > to run this code:

<cfloop list="#queryname.columnlist#" index="col">
      #col#
</cfloop>
<cfloop from="1" to="#queryname.recordcount#" index="i">
      <cfloop list="#queryname.columnlist#" index="col">
            <cfset val=evaluate("queryname.#col#[#i#]")>
            #val#
      </cfloop>
</cfloop>
Thank you all for your responses. Unfortunately, it still requires me to re-create a whole new query.

Let me elaborate on what I'm trying to accomplish.

I have a page that contains static html included with a <cfoutput>
tag. I've created an option to allow the user to 'check' an option to
export the results instead to a flat file. The same query is run but
the result is displayed in ASCII text instead of HTML. I made a
sepatate query so that if the is_download is 1 - execute the extract.
Otherwise disregard. No biggie.

I'm now being asked to replicate this accross the board for over 50
reports. This is going to take some time since I have to create a
whole new query for each results page to use if the use elects to
download the page into an ASCII file. I'm thinking there has to be an
easier way.

I know that there is a way to reReplace text on a variable so that if
there is any type of <html> tags they are removed. Is there something
which can be done though on a phisical page with <html>, <table>
tags?

I've been trying to see if there is an option for weeks now and have
not been able to get anywhere. If anyone could lend any sort of cf
tag or provide me with a resource/example that would assist me with
this I would be eternally grateful!! :)

Ideally, if there was some way to define a cf_tag to be executed to
remove all html and replace the <tr> with carrige returns and <td>
with tab dillimiters, that would be great. Again, not sure if it is
possible when the html is actually on the back end page and not in
the var.

I really appreciate all of your assistance with this. I'm increasing the points to 400 for an answer. :)
U cld write that code as a tag if required !

CF wld do a search & replace for all the files in ur project folder - if u run the Search & replace function in CFSTudio
& send in the search text in the form of a Expression - u'll see a checkbox at the bottom right of the search screen -
"Regular Expression" - chk that & run the code on few of ur sample files - u wanna test with.

if the results are successfull - then run if for all the files

PS : make sure u have backups - before u do this operation - as undo wld be impossible.

let me know

K'Rgds
Anand
I've still been unable to get this resolved. I'm actually thinking that I could instead just output it to a separate page.

I would still like to be able to simplify this by just passing a comma delimitted list and then loop through that list. Which brings me to my next question:

Can CF accept 2 dilitters? For instance , and | ??? If it can how???
yes CF can accept 2 delimeters

<cfset x = "1,2,,//3,5,4">

<Cfloop LIST="x" INDEX="i" DELIMITERS=",/">
      #x#
</CFLOOP>

K'Rgds
Anand