Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: How to convert logs to HTML including TABLES


From   Timothy P Cheney <[email protected]>
To   [email protected]
Subject   Re: st: RE: How to convert logs to HTML including TABLES
Date   Wed, 29 Aug 2007 11:31:53 -0400 (EDT)

Thanks for the tip. I wrote a perl script that pretty much gets the job done. The major annoyance is that it won't get the header row right if there are embedded spaces in a column header. It could be smarter about it by looking ahead to an interior row of the table a figuring out the numerical column positions. It works with the text logs rather than the smcl. I would have liked to write something in stata but it would take forever to write using the limited macro string functions available.


$file1 = $ARGV[0];
$file2 = "$file1".".html";
open(FILE1,"<$file1") or die "Input file: Cannot open $file1\n\n";
open(FILE2,">$file2") or die "Output file: Cannot open $file2\n\n";



print FILE2 "<HTML><BODY>\n";

$tab_on=0;

while (<FILE1>){
chop;
# if it is a command then print and return
if ($_ =~ /^[\.]/) { print FILE2 $_."<br>\n" }
# else if there is a pipe assume we are in a table
elsif ($_ =~ /[\|]/) {
$caught_pipe=1;
if ($tab_on==0) {
$tab_on=1;
print FILE2 "<TABLE BORDER=1>\n";
}
($stub, $rest)=split(/\|/,$_);
$rest =~ s/\s+/ /g;
#print "$rest\n";
@cells = split(/ /, $rest);
print FILE2 "<TR><TD>".$stub."</TD>";
foreach $cell (@cells) {
print FILE2 "<TD> $cell </TD>";
}
print FILE2 "</TR>\n";
}
# some tables have a "--------------+----------" which we will skip
elsif ($_ =~ /^[\-]+[\+][\-]+/) {
}
else {
if ($tab_on==1) {
$tab_on=0;
print FILE2 "</TABLE>\n";
print FILE2 $_."<BR>\n";
}
else {

print FILE2 $_."<BR>\n";
}
}
}

print FILE2 "</BODY><HTML>/n";

close(FILE2);
print "$file2 created\n";
close(FILE1);



On Tue, 28 Aug 2007, Newson, Roger B wrote:


A possible route to automatic HTML table generation is to use
-xcontract- and -listtex-, both of which are downloadable from SSC.
-xcontract- creates an output Stata dataset (or resultsset) with 1
observation per combination of values and data on frequencies or
percents, -listtex- can convert such a dataset to a HTML table.

I hope this helps.

Roger


Roger Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected]
Web page: www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/pop
genetics/reph/

Opinions expressed are those of the author, not of the institution.

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Timothy P
Cheney
Sent: 28 August 2007 18:25
To: [email protected]
Subject: st: How to convert logs to HTML including TABLES

Does anybody have a program to do this?  log2html creates html files but

does not parse the results into an HTML table.

When I produce a large number of tabs I would like to be able to dump
the
whole thing into a spreadsheet without having to copy as table and paste

each one.

Thanks,
Tim

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index