Gossamer Forum
Home : Products : DBMan : Customization :

Export To Excel Mod Used With Short/Long display

Quote Reply
Export To Excel Mod Used With Short/Long display
I am implementing the Export to Excel Mod.

In the standard version of Dbman, I got this to work great. However, now that I am using the short/long display mod, I can not get it to work. Here is why:

Quote:
###################################################################################
# script: html.pl #
# #
# add new line #
# #
# <INPUT TYPE="SUBMIT" NAME="export_records" VALUE="Export Results"> #
# #
# Where to put it-- #
# subroutines: html_view_success #
# html_view_failure #
# Location: in between ... #
# <p><center> **** <INPUT TYPE="SUBMIT" NAME="view_records" VALUE="View Records"> #
# #
##################################################################################

In the short/long display, if you put the submit button in html_view_success, it does not function because when the html page is printed to the browser, the button is not contained in a <form></form> tag.

I tried to put it in sub record_long and the same results. How do you make this work? I hope I'm not a pain with the questions I have been posting lately. Sorry if I am.

Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Well, what I have done is created a separate sub-routine for the search form with the form anchors in them and the input button.

Then in the sub html_view_search, I have referenced this search sub-routine in the following manner:

Code:
|;
&html_search_form
print qq|

What you could do is have a search form with hidden fields and then put the input button in that routine and call it in the above manner in your sub html_view_sucess routine.

Hope this makes sense and helps.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Thanks for the reply. I am a little confused though.

Code:
<form action="$db_script_url" method="GET" name="form1">
<INPUT TYPE="SUBMIT" NAME="export_records" VALUE="Export Results">
</form>

I am certain there would be a lot more, but don't know how. Could you kindly post the code I could use? I am not asking because I am lazy, I just don't know how. I have already tried for several hours to no avail.

Eventually, I think I will learn more, just like you and Carol did, from digging into the depths of coding hell and by asking questions and seeing examples!

Thanks again in advance!!!!!!!!!!!!!!

P.S.

What has happened to Carol (JPdeni)? I still need an answer regarding her archive mod as posted in thread http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/001288.html.



[This message has been edited by BrianYork (edited October 27, 1999).]
Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Brian,

Code:
<input type="hidden" name="db" value="$db_setup">
<input type="hidden" name="uid" value="default">

You might also have to add a keyword hidden field like the following:

Code:
<input type="hidden" name="keywords" value="">

But play around with it and see what you come up with...Experimentation is the key to success!

Smile

Hope this is a bit clearer and helps.

Regards,


------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Eliot,

This is the jist of what I tried in html.pl:

Code:
sub html_view_search {
# --------------------------------------------------------
# This page is displayed when a user requests to search the
# database for viewing.
# Note: all searches must use GET method.
#

&html_search_form;

}

sub html_search_form {
#---------------------------------------------------------
#

print "<form action=$db_script_url method=GET name=form1>
<INPUT TYPE=Submit Name=export_records VALUE=Export Results>
<input type=hidden name=db value=$db_setup>
<input type=hidden name=uid =value=default>
<input type=hidden name=keywords value=>
</form>"

}

Now, don't pay too much attention at this time to the missing "" in the new subroutine. I was playing around with the print and the print qq statements because if I used print qq, than I get a cgi error and the script doesn't run at all.

The above code allows my script to work, but as soon as I hit the View button (Which I retitled Search on my site), I get a 500 server error when it tries to invoke the new search sub routine. I know this is a result of my lack of code writing skills.

Am I on the right track? I am about to give up on this mod, even though I know we are probably on track. Like I said, I got it to work before implementing the long/short mod.

Can you help me with the code? (Eye Browes go up and eyeballs protrude to the monitor).

By the way, I forgot that I did also try the following in html.pl for the short/long mod:

Code:
sub html_record_long {
#----------------------------------------------------------------
my (%rec) = @_;

if ($db_total_hits > 1) {

# create links to previous and next records

$next_url = $ENV{'QUERY_STRING'};
$next_url =~ s/\&nh=\d+//;
$next_hit = $nh + 1;
$prev_hit = $nh - 1;

if ($prev_hit) {
$previous = qq~<a href="$db_script_url?$next_url&nh=$prev_hit"><$font>Previous</font></a>~;
}
else { $previous = " "; }

if ($next_hit <= $db_total_hits) {
$next = qq~<a href="$db_script_url?$next_url&nh=$next_hit"><$font>Next</font></a>~;
}
else { $next = " "; }

# create link back to short display
$list_url = $next_url;
$list_url =~ s/\&mh=\d+//;
$mh = $db_max_hits;
$lh = int(($nh-1)/$mh) + 1;
$list = qq~<a href="$db_script_url?$list_url&nh=$lh"><$font>Back to record list</font></a>~;

# print out the links
print qq|
<table width=100%>
<tr><td width=50%>$previous</td>
<td width=50% align=right>$next</td></tr>
<tr><td colspan=2 align=center>$list</td></tr>
<tr><td colspan=2 align=center><$font>Record $nh of $db_total_hits</font></table>
|;
}

# Below is where you define your form.

# <-- Start of record display -->

print qq|
<form action="$db_script_url" method="POST" name="form1">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
|;

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';

print qq|
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>ID:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'ID'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Name:</FONT></TD>
<TD> <$font>$rec{'Name'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Email: </FONT></TD>
<TD> <$font>$rec{'Email'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Date:</FONT></TD>
<TD> <$font>$rec{'Date'}</Font></TD></TR>
</TABLE>
|;

print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="export_records" VALUE="Export Results">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center></p>
</form>
|;



# <-- End of record display -->

}

If you can see, I now got the form tags to print out to the html document. However, when I hit the Export Results button, I get:

Search Failed

There were problems with the search. Reason: no search terms specified
Please fix any errors and submit the record again.

Why does the button think I am searching instead of trying to export. Secondly, why do the instructions for the export mod want you to put an export results button on the search failure page. To me, I can't understand what you would export if there were no results found.



[This message has been edited by BrianYork (edited October 28, 1999).]
Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Okay...I think you are on the right track...I would not give up so quick. This would be a wonderful Mod to use. Let me look over the codes you've written so far, and see what I can come up with....Give me a few days, please!

I am going out of town to hunt for an apartment in Boulder, CO (since I got a new job and I am relocating from Flagstaff, AZ). So, I will not be in the Forum over the weekend.

But I would encourage anyone else who reads this Thread to provide some ideas!

Smile

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Hi, Eliot!

I know your probably just leaving for your venture to find a new abode. Hope all goes/went well. Moving is always fun!

I resolved a big chunk of issues with this mod. I will break it all down here.

1) First of all, I kind of misunderstood exactly how this mod was supposed to work. Originally, I thought it was supposed to allow you to export a record once you had it displayed. However, what it is supposed to do is when you are on a search form (sub html_view_search), it provides you with the option to print the search results to a file (in this case, as csv file) via the export button instead of to the browser (sub html_view_success) using the view records button. I guess this okay. However, as a user, I would rather see my search results first prior to exporting them. I think Carol mentioned this to Mitch (DonM) in another thread.

2) This leads to problem resolve #2. In Don's instructions for the Excel mod he says to do the following:

Code:
print qq|
<form action="$db_script_url" method="POST" name="form1">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
|;
my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
print qq|
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=1 BGCOLOR="#FFFFCC">
<TR><TD ALIGN="Right" VALIGN="TOP" WIDTH="20%"><$font_color>ID:</FONT></TD>
<TD WIDTH="80%"> <$font>$rec{'ID'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Name:</FONT></TD>
<TD> <$font>$rec{'Name'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Email: </FONT></TD>
<TD> <$font>$rec{'Email'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Date:</FONT></TD>
<TD> <$font>$rec{'Date'}</Font></TD></TR>
<TR><TD ALIGN="Right" VALIGN="TOP"><$font_color>Date Last Modified:</FONT></TD>
<TD> <$font>$rec{'DateLastModified'}</Font></TD></TR>
</TABLE>
|;
print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="export_found_records" VALUE="Export Results">
<INPUT TYPE="SUBMIT" NAME="view_records" VALUE="New Search">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center></p>
</form>
|;

Part 2 - Then create a new subroutine in db.cgi under sub export_results:

Code:
sub export_found_records {
# --------------------------------------------------------
# This is called when a user wants to export found records to Excel
# All the work is done in query()

&export_to_Excel;
}

I got the above to work. I then putzed with the code a little bit and now when I hit the export results button, I get an action unknown error meassage. However, while it was working, when you download the file and open it, it only has the Field names but no records. I think this is because the new sub routine I created is looking in sub query for hits but it probably does not need to be doing this at this time. I know there should be more code in the new sub routine, but I don't know what else to put! You might not even need a new subroutine. You might be able to edit Don's exist export routine to include a new else statement.

When I had this mod working before implementing the short/long mod, I used to get the following error when trying to open the csv file:

Quote:
SYLK: FILE FORMAT IS INVALID

I don't know why. The same thing still happens when I invoke the export routine from the search page (field names and database entries show though in a text editor). This is what my csv file looks like if I open it in a text editor. I have tried opening it in Excel 97 and Excel 2000.

Quote:
ID,Name,Email,Date,DateLastModified
"1","Brian Michael","brian.michael@york.com","29-Oct-1999","29-Oct-1999"
"2","Brian York","brian.michael@york.com","29-Oct-1999","29-Oct-1999"

I then went to Don's site and tried his hockey demo. The csv file I got from his site opened right up in Excel. So I opened it in a text editor to compare it to my file and here is what it looked like:

Quote:
NHL,FirstName,LastName,Pos,Height,Weight,BirthDate,DraftedBy,Drafted,Active
"ANA","Mike","LeClerc","F","6'1","205","10-Nov-1976","Not Drafted","No","No"
"PHI","John","LeClair","F","6'3","228","05-Jul-1969","Chebib_Jim","Yes","Yes"

Looks similar in format to mine. What's wrong?

Third problem.. Using Internet Explorer 5.0, when I click on the link to retrieve the csv file, I get a window that opens up along with the download prompt box and after I hit the save file to disk button, this new window loads a blank page saying action cancelled - no page to be displayed (the file itself downloads successfully). Anyway to stop this? It just looks sloppy.

I think we got this thread close to complete. Please provide some code, Eliot or Don, if you can to finish this up. I am stumped at this point. Sorry if this so long - I just did not want to miss anything!

Thanks!

[This message has been edited by BrianYork (edited October 30, 1999).]
Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
I figured out why I was getting an Unknown Action error message. Add the following new code to db.cgi sub main within all of the other elseif statements:

Code:
elsif ($in{'export_found_records'}){ if ($per_view) { &export_found_records; } else { &html_unauth; } }

I am determined to get this to work! I now get all of the field names in my csv file, but no records. Any ideas?

ALERT...ALERT...ALERT!!!

I think I found the clue to how to get the records to show below the fieldnames in the csv file. Take a look at thread http://www.gossamer-threads.com/...m12/HTML/001143.html

Carol says:

Quote:
You might consider moving the export button to the search results page, though, so the user can see the records that will be exported before actually doing it. It would just require a little hidden form with fields for each database field, each with a value of "$in{'fieldname'}".

I need help coming up with this "little hidden form" setup. I think this will resolve the problem. Where and what do you put. I tried adding <input type=hidden name="Name" value="$in{'Name'}">, etc. into my code above in sub html_record_long in between the form tags, but it did not work.

I know your not back yet Eliot (or JPDeni for that matter). I just did not want to forget my thoughts, so I am posting away with lots of words as usual. Hope you can help when you get back. Hope the apartment hunting went well.


[This message has been edited by BrianYork (edited October 30, 1999).]
Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Whoa - this is going to take awhile to go through. I am not familiar
with the long/short display mod, but will have a go at it.

A couple of things first off.

1. Thanks for the pointer to the documentation error - I have modified the mod
so it says to insert in html_view_search - not html_view_success.

2. As for the Excel import error, you might try renaming your 'DATE' field
to something else. DATE is a reserved word in Excel.

3. It looks like you are on the right track with your export_found_records subroutine.
If you already have the query results in @hits, you can eliminate that call. But you
likely need to change your submit subroutine to match it.

Code:
print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="export_records" VALUE="Export Results">
<INPUT TYPE="SUBMIT" NAME="view_records" VALUE="New Search">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center></p>
</form>
|;

should likely be ...

Code:
print qq|
<p><center>
<INPUT TYPE="SUBMIT" NAME="export_found_records" VALUE="Export Results">
<INPUT TYPE="SUBMIT" NAME="view_records" VALUE="New Search">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center></p>
</form>
|;

Hope that helps.



------------------
Don Mitchinson
Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Don:

Hello! I changed the Date field to DateAdded. Still get the error message in excel 97 and excel 2000.

Maybe you could try it:

http://www.yorkphiladelphia.com/jobtrack/db.cgi

Just a demo there, but try to export the search just like you do on your page and see what you get.

I edited the post above. I did have the code you mentioned, but when I tried to re-edit it a few minutes after posting it, it got wiped out for some reason.
Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Well you had me stumped for awhile, but it looks like you found an undocumented Excel 'feature'.
Apparently you cannot have the first field starting with ID, unless it is in quotes.
So either call your ID field something else or place it in a column other than the first one,
or probably the easiest to implement, is to dump the fieldnames enclosed by "quotes".

Also as an aside, there was nothing wrong with your Date fieldname.
You can leave that as is.

Let me know how it goes.



------------------
Don Mitchinson
Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Don:

YAHOOOOOO! It worked! You resolved one issue. I changed "ID" to "JobID" and when I created the export file, it opened right up in Excel. How did you figure out that this was the problem? You might want to add this to the documentation to your mod just so other people don't come across the same bizarre thing. Thanks a zillion!

Now I only need to get one more step complete and we can close this thread.

How do I get the records to print to the excel export file when I am on the Search Results page? Read the above posts, particularly my second one on Oct. 29. That is where the answer lies, I believe. I just can't figure how to do what JPDeni meant in her passage that I quoted above.

Eliot, now that you are probably back and online today, do you have any ideas? Please read the posts above since you were out of town.

Hope the apartment hunting went well! Smile
Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
Brian,

Hi there...I should've given you codes for the printing routine earlier. I am using this type of option in one of my DBMAN projects.

I have also been fighting with the challenge of putting a method of linking to the "printable" option in the search results.

What you could try doing is adding a link to the top of the search result table, like the following:

Code:
<a href="$db_script_url&JobID=$in{'JobID'}&Name=$in{'Name'}&Email=$in{'Email'}&DateAdded=$in{'DateAdded'}&DateLastModified=$in{'DateLastModifie d'}&keyword=$in{'keyword'}&export_found_records=1">Export Records</a>

OR you could just export each record individually with the following codes:

Code:
<a href="$db_script_url&JobID=$rec{'JobID'}&ww=on&export_found_records=1">Export Record</a>

In terms of adding a button, I don't know if this would be possible, but what you could do is try adding the following codes:

Code:
<form>
<input type="submit" name="export_found_records" value="Export Records">
</form>

I don't gaurantee if any of these options will work ideally how you want it. But these options are based on earlier advice provided by Carol (JPDeni).

Hope this helps somewhat.

Wink

BTW: Apartment hunting was very successful!

Smile

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Export To Excel Mod Used With Short/Long display In reply to
It make take a bit of work to make the export work from the Search Results page.
Right now I can't see a way around getting it to work without resubmitting the query.
This is more of a Perl question than anything. You have to find a way to
send the array @hits to the subroutine export_found_results.
That's normally not a problem in Perl, but in this case it seems impossible to me.
I guess it comes down to if you can get the contents of @hits into sub main() in db.pl then you're okay.

I'll see what I can do...

------------------
Don Mitchinson