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   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: How to convert logs to HTML including TABLES
Date   Wed, 29 Aug 2007 17:13:23 +0100

If you have the inclination, do signal what you can 
do here with Perl but could not do with Mata -- which 
is the appropriate language here. I am
sure that Mata's developers are interested in a wishlist. 

Nick 
[email protected] 

Timothy P Cheney
> 
> 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.

> 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.

*
*   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