0

Let me start by stating that my end goal is to create an Export to Comma Separated File (.csv) or Export to Excel button on a page of our site. Our site currently has a search mechanism that returns the data in XML. That XML is loaded into a Microsoft.XMLDOM object.

Dim objXMLDom
Set objXMLDOM = Server.CreateObject("Microsoft.XMLDOM")

...

Function LoadXML(strXML)
    objXMLDOM.loadXML(strXML)
end function

This XML data is parsed into a variable called myData and is displayed in an HTML Grid using different columns & rows. Like I said above, ideally I would like to add a button to the page that can export to csv or Excel. I've searched around and found that this is not an easy task when the code is in Classic ASP...so I found a semi-work around.

The workaround is to use Downloadify. It's a jquery/flash script that allows you to copy code into the HTML of a DOM element and then pull that data back out all on the client side. It works for the most part...the only problem I'm having is adding in a new line character. I think it gets removed going into HTML and back out again.

Here's the code for how I put data into the element

for (i = 0; i < <%=RowCount %>; i++) {
    parent.document.getElementById('data').innerHTML += '\n';
    for (j = 0; j < <%=columnCount%>; j++) {
        parent.document.getElementById('data').innerHTML += myData[i][j];
        parent.document.getElementById('data').innerHTML += ',';

    }
};

Here's what I use to pull it back out:

function load() {
    Downloadify.create('downloadify', {
        filename: function() {
            return document.getElementById('filename').value;
        },
        data: function() {
            return document.getElementById('data').value;
        },
        onComplete: function() { alert('Your File Has Been Saved!'); },
        onCancel: function() { alert('You have cancelled the saving of this file.'); },
        onError: function() { alert('You must put something in the File Contents or there will be nothing to save!'); },
        swf: 'media/downloadify.swf',
        downloadImage: 'images/download.png',
        width: 100,
        height: 30,
        transparent: true,
        append: false
    }

    );

}

I really don't know very much Flash, but I've tried putting in different strings ('<br>', '&#13;', even ";:;" ) and replacing them in the data : function part using Flash's replace method, but it seems to hang and never finish processing (i think this is because I needed to put the replace method in a while loop since the replace method only replaces one instance and I have many).

Any help will be appreciated. Thank you in advance.

Mark
  • 1,455
  • 3
  • 28
  • 51
  • that's the way the `Downloadify` plugin is already structured to work. I think i'm going to scrap it and try to work it out using only ASP & Javascript... – Mark May 30 '12 at 11:35
  • @wvxvw - I can't believe I didn't see that! :-) You're suggestion worked. If you want to write it up as an answer, i'll accept it as the solution. I did have to use this question as a reference too (because my data is in an iframe) http://stackoverflow.com/questions/1301540/set-variable-in-parent-window-from-iframe – Mark May 30 '12 at 15:27
  • We export to csv, excel, txt, and access. All in less than 2000 lines of code :P Yeah it is kind of a pain. Though the 2000 includes things like translating the recordsets, decrypting columns, etc. – Brian White May 31 '12 at 19:08

2 Answers2

1

why don't you have the ASP create a .csv file along with the html page? It seems like that would be a lot easier.

PitaJ
  • 12,969
  • 6
  • 36
  • 55
0

I had a problem like this awhile back when I was using Flash and ASP together. I remember calling ASP from Flash and it hanging. I THINK the fix was to add a "response.end" to the end of the ASP page. That seemed to tell the server, "Done. Back to Flash now." Sorry I can't be more sure. It was a long time ago and I can't find the code.

ScotterMonkey
  • 1,007
  • 12
  • 25