Re: [jQuery] tables - is this possible ?
Matt, that's exactly what I was thinking! It will work for even user modifiable tables! If the table is not modifiable you could just write the data for the table to a file, and have the table built via ajax'ing the xls file and doing a simple parse (much easier for a tabbed file or the new excel xml format). This cuts back the bandwidth and most good browsers should serve the download right from the cache. On 2/19/07, Matt Kruse <[EMAIL PROTECTED]> wrote: > > I have a table populated by a php/mysql script. I've created an excel export > > option which changes the header to ms-excel and refreshes the current page > > by making another call to the mysql db to fetch the data. > > So I thought, the table data is already embedded in the current html page; > > why make another call to the mysql db to fetch the same data again? is not > > possible to use javascript to scan the current html page for and > > and create an excel file on the fly therefore saving bandwith ? > > Yes, it's possible - I do it all the time. The benefit of this approach is > that > if you allow client-side sorting, filtering, column hiding, etc, the user can > download exactly what they see because the manipulated client-side table is > exactly what they want. > > The problem is it can't be done _purely_ client-side, because there is no way > for js to generate a document of a specific mime type. Because of this, you > need to write a simple server-side component in your language of choice that > accepts a form value containing content to echo back. It slaps the excel mime > type on it and returns it as-is, and the user's browser (hopefully) opens > excel > to handle the response. > > My solution is for an IE-only webapp, so the code isn't very cross-browser, > but > I suppose you could generalize the approach. I do these steps: > > 1) Get the outerHTML of the table > 2) Create a hidden iframe and write out the table as part of it > 3) Get a reference to the new table and manipulate it using standard dom to > clean it into something that excel will like. For example, > a) Convert text inputs into plain text > b) Convert checkboxes into an "X" if checked, else blank > c) Convert select lists into their selected option's visible text > d) Convert links to plain text > e) Replace images with their [alt] text > f) Make sure borders are on > g) Put nowrap on every cell > h) etc... > 4) Get the outerHTML of the resulting table and set it into a textarea in the > iframe > 5) Submit the iframe form to the server, which echoes back the submitted > content with the excel mime type > > It all happens very quickly and the resulting Excel output matches exactly to > what the user sees on screen. Depending on your data, you may need to scrub > your tables more to get dates in the right formats that excel will parse > correctly or to remove other markup that will ugly up the excel. > > Once written, though, it becomes pretty reusable on almost any table with very > good results. > > With the power of jQuery, I imagine that 'cleaning' the table would be > extremely trivial and the resulting js file would be pretty small. I would add > it to my general table library (which I'm going to release as a jQuery plugin > soon) but since it requires a server-side component I think it needs to be > separate. > > Hope that helps! > > Matt > > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > -- Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] tables - is this possible ?
> I have a table populated by a php/mysql script. I've created an excel export > option which changes the header to ms-excel and refreshes the current page > by making another call to the mysql db to fetch the data. > So I thought, the table data is already embedded in the current html page; > why make another call to the mysql db to fetch the same data again? is not > possible to use javascript to scan the current html page for and > and create an excel file on the fly therefore saving bandwith ? Yes, it's possible - I do it all the time. The benefit of this approach is that if you allow client-side sorting, filtering, column hiding, etc, the user can download exactly what they see because the manipulated client-side table is exactly what they want. The problem is it can't be done _purely_ client-side, because there is no way for js to generate a document of a specific mime type. Because of this, you need to write a simple server-side component in your language of choice that accepts a form value containing content to echo back. It slaps the excel mime type on it and returns it as-is, and the user's browser (hopefully) opens excel to handle the response. My solution is for an IE-only webapp, so the code isn't very cross-browser, but I suppose you could generalize the approach. I do these steps: 1) Get the outerHTML of the table 2) Create a hidden iframe and write out the table as part of it 3) Get a reference to the new table and manipulate it using standard dom to clean it into something that excel will like. For example, a) Convert text inputs into plain text b) Convert checkboxes into an "X" if checked, else blank c) Convert select lists into their selected option's visible text d) Convert links to plain text e) Replace images with their [alt] text f) Make sure borders are on g) Put nowrap on every cell h) etc... 4) Get the outerHTML of the resulting table and set it into a textarea in the iframe 5) Submit the iframe form to the server, which echoes back the submitted content with the excel mime type It all happens very quickly and the resulting Excel output matches exactly to what the user sees on screen. Depending on your data, you may need to scrub your tables more to get dates in the right formats that excel will parse correctly or to remove other markup that will ugly up the excel. Once written, though, it becomes pretty reusable on almost any table with very good results. With the power of jQuery, I imagine that 'cleaning' the table would be extremely trivial and the resulting js file would be pretty small. I would add it to my general table library (which I'm going to release as a jQuery plugin soon) but since it requires a server-side component I think it needs to be separate. Hope that helps! Matt ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] tables - is this possible ?
I would try something like: $("table").each(function() { // Loop through each table $(this).find("> td").each(function() { // Loop through each TD in the table $(this).find("> tr").each(function() { // Loop through each TR in the TD // do something with the data }); }); }); Im not sure what the format of an excel file is, but you should be able to build on that. You said you have 'basic' JS skills, I would think that this would be a more advanced job, but you can try it out. On 2/19/07, ronaldo <[EMAIL PROTECTED]> wrote: Hi all, I have pretty basic js & jquery skills so need some input on whether this is feasible: With some code, would i be able to scan the html page for a tag; and create an excel file based on the table data ? if so, whats the correct syntax to loop through ? The main advantage for this would be speed and bandwith, as it'll save me making a call to the database. Thanks R -- View this message in context: http://www.nabble.com/tables---is-this-possible---tf3252465.html#a9041221 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] tables - is this possible ?
Oh come on guys... if you collect the data and simply separate the fields by a tab, then ajax it back to a simplistic cgi, it could save the file for a short period of time, and the user could download the tab separated data right into excel. But the server side solutions might be more flexible... and my idea would not save bandwidth. You are better off storing the data in a data file in the first place and using ajax to load it into the table and use the same file to download right to excel... it would be in the cache, so it will save bandwidth (and use less than all those table,tr,td,th tags) On 2/19/07, Alexandre Plennevaux <[EMAIL PROTECTED]> wrote: > Basically, it's no, not possible. > > More info here: http://www.thescripts.com/forum/thread93938.html > > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On > Behalf Of ronaldo > Sent: mardi 20 février 2007 1:11 > To: discuss@jquery.com > Subject: Re: [jQuery] tables - is this possible ? > > > Apologies for not being clearer. This is the situation: > I have a table populated by a php/mysql script. I've created an excel export > option which changes the header to ms-excel and refreshes the current page > by making another call to the mysql db to fetch the data. > So I thought, the table data is already embedded in the current html page; > why make another call to the mysql db to fetch the same data again? is not > possible to use javascript to scan the current html page for and > and create an excel file on the fly therefore saving bandwith ? > > let me know your thoughts > > T > > > DavidIcreate wrote: > > > > ronaldo schreef: > >> Hi all, > >> > >> I have pretty basic js & jquery skills so need some input on whether > >> this is > >> feasible: > >> With some code, would i be able to scan the html page for a > >> tag; and create an excel file based on the table data > >> ? > >> > >> if so, whats the correct syntax to loop through ? > >> > >> The main advantage for this would be speed and bandwith, as it'll > >> save me making a call to the database. > >> > >> Thanks > >> > >> R > >> > >> > >> > > The none jquery question would be: isn't it possible to fetch your > > data to a variable or an object and output that as html and make an > > excel file? this will not fatten your javascript code which needs to > > be downloaded too. > > > > -- > > David Duymelinck > > > > [EMAIL PROTECTED] > > > > > > ___ > > jQuery mailing list > > discuss@jquery.com > > http://jquery.com/discuss/ > > > > > > -- > View this message in context: > http://www.nabble.com/tables---is-this-possible---tf3252465.html#a9052307 > Sent from the JQuery mailing list archive at Nabble.com. > > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- > Ce message Envoi est certifié sans virus connu. > Analyse effectuée par AVG. > Version: 7.5.441 / Base de données virus: 268.18.2/692 - Date: 18/02/2007 > 16:35 > > > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > -- Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] tables - is this possible ?
Basically, it's no, not possible. More info here: http://www.thescripts.com/forum/thread93938.html -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of ronaldo Sent: mardi 20 février 2007 1:11 To: discuss@jquery.com Subject: Re: [jQuery] tables - is this possible ? Apologies for not being clearer. This is the situation: I have a table populated by a php/mysql script. I've created an excel export option which changes the header to ms-excel and refreshes the current page by making another call to the mysql db to fetch the data. So I thought, the table data is already embedded in the current html page; why make another call to the mysql db to fetch the same data again? is not possible to use javascript to scan the current html page for and and create an excel file on the fly therefore saving bandwith ? let me know your thoughts T DavidIcreate wrote: > > ronaldo schreef: >> Hi all, >> >> I have pretty basic js & jquery skills so need some input on whether >> this is >> feasible: >> With some code, would i be able to scan the html page for a >> tag; and create an excel file based on the table data >> ? >> >> if so, whats the correct syntax to loop through ? >> >> The main advantage for this would be speed and bandwith, as it'll >> save me making a call to the database. >> >> Thanks >> >> R >> >> >> > The none jquery question would be: isn't it possible to fetch your > data to a variable or an object and output that as html and make an > excel file? this will not fatten your javascript code which needs to > be downloaded too. > > -- > David Duymelinck > > [EMAIL PROTECTED] > > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/tables---is-this-possible---tf3252465.html#a9052307 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/ -- Ce message Envoi est certifié sans virus connu. Analyse effectuée par AVG. Version: 7.5.441 / Base de données virus: 268.18.2/692 - Date: 18/02/2007 16:35 ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] tables - is this possible ?
Apologies for not being clearer. This is the situation: I have a table populated by a php/mysql script. I've created an excel export option which changes the header to ms-excel and refreshes the current page by making another call to the mysql db to fetch the data. So I thought, the table data is already embedded in the current html page; why make another call to the mysql db to fetch the same data again? is not possible to use javascript to scan the current html page for and and create an excel file on the fly therefore saving bandwith ? let me know your thoughts T DavidIcreate wrote: > > ronaldo schreef: >> Hi all, >> >> I have pretty basic js & jquery skills so need some input on whether this >> is >> feasible: >> With some code, would i be able to scan the html page for a >> >> tag; and create an excel file based on the table data ? >> >> if so, whats the correct syntax to loop through ? >> >> The main advantage for this would be speed and bandwith, as it'll save me >> making a call to the database. >> >> Thanks >> >> R >> >> >> > The none jquery question would be: isn't it possible to fetch your data > to a variable or an object and output that as html and make an excel > file? this will not fatten your javascript code which needs to be > downloaded too. > > -- > David Duymelinck > > [EMAIL PROTECTED] > > > ___ > jQuery mailing list > discuss@jquery.com > http://jquery.com/discuss/ > > -- View this message in context: http://www.nabble.com/tables---is-this-possible---tf3252465.html#a9052307 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
Re: [jQuery] tables - is this possible ?
ronaldo schreef: > Hi all, > > I have pretty basic js & jquery skills so need some input on whether this is > feasible: > With some code, would i be able to scan the html page for a > tag; and create an excel file based on the table data ? > > if so, whats the correct syntax to loop through ? > > The main advantage for this would be speed and bandwith, as it'll save me > making a call to the database. > > Thanks > > R > > > The none jquery question would be: isn't it possible to fetch your data to a variable or an object and output that as html and make an excel file? this will not fatten your javascript code which needs to be downloaded too. -- David Duymelinck [EMAIL PROTECTED] ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
[jQuery] tables - is this possible ?
Hi all, I have pretty basic js & jquery skills so need some input on whether this is feasible: With some code, would i be able to scan the html page for a tag; and create an excel file based on the table data ? if so, whats the correct syntax to loop through ? The main advantage for this would be speed and bandwith, as it'll save me making a call to the database. Thanks R -- View this message in context: http://www.nabble.com/tables---is-this-possible---tf3252465.html#a9041221 Sent from the JQuery mailing list archive at Nabble.com. ___ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/