AFL to Export Exploration Results to HTML - custom fonts and alignment?

I have been using the batches and running my exporations and having the batch auto export them to html. However, the output in the html is ugly and unformatted....

I am trying to find a way to do this... i know how to write to html files during the backest and by looping watchlists etc... however this particular exploration has alot of calcuations and filters...

The ExportToHtml formats are all messed (font size, alignment etc)

AuotExportHtml

And below is my on screen view of my exploration.... i tried to use Status( "action" ) == actionExplore as well... i just basically want to READ this exploration and write to html (again i know how to fput etc to html).. i just cant figure out how to loop the results in this exploration and write them to html...

formattedoutput

or maybe easier... is there any way to format the alignment and or font on the ExportToHtml file the batch creates... thats really all i need....i cant stand the right justified text..its fine for me but when i share with others it drives them crazy

thanks

All you have to do is opening your HTML file with some text editor (such as NotePad++) and in line 5 change from

text-align: right

to

text-align: left

and then save HTML file.

BEFORE
745

AFTER
800

2 Likes

yes. i have been doing that to a degree... however, i have 18 explorations i export daily to html then FTP to a private web so all users can see it.....

thanks for the tip tho

And why haven't you said so but actually let me waste time preparing post??
I really do not like that at all.
You didn't mention anything that you did.

All what you have said is this

and then

So fact remains that what I have suggested does exactly what you were asking for.
Now all you have to do is automate the edit process for all of your 18 HMTL files.
Simply use Google search because it is not really AmiBroker related on how to change HTML file content.

1 Like

im sorry.. I did not mean to waste you or any others time... I guess I was trying to just create my own export code (like I did for backtest etc) from the explore window.... when I asked about the alignment, I meant do so programically in amibroker ...

Again, thanks for the response and I apologize for the confusion

@mfu5324 did you evaluate the automation of the workflow via the "Batch Window" functionality?

Using it, you can run your explorations, export the results as an HTML file, then use another AFL (saved as .apx) to read the output file (line by line) and rewrite it, altering only the alignment line (or the first few lines to redefine the style).
If needed, you can use some string manipulation functions to replace also the hardcoded colors in the table rows lines, before rewriting them.

If you are more ambitious, always using a batch sequence, export your exploration results to a .csv file and then, as above, use a second .apx to execute a formula with your logic to read/parse the saved file and rewrite it as a new HTML with all the required tags ideally replacing the table ones with divs using your custom .css styles.

As @fxshrat told you - edit the CSS in the header. HTML produced by AmiBroker uses CSS, which means that alignment is set in the header (in CSS part) and other than that there is no other formatting in the table. This makes it extremely easy to change alignment, font and whatever. Learn more about CSS! (Hint: google). There are tools available on the net that you can use to replace <STYLE>...</STYLE section automatically with the CSS of your choice. Google for replace text in files. Really Google search is your friend, use it.

3 Likes

I ALMOST HAVE IT... THANK YOU ALL for your direction.....I never thought of modifying the text file with afl....

My code is below... it works well IF IT ONLY RUNS ONCE.. if I run it again on same file it messes up...All I want to do is replace the first 8 lines in the text file with my coded 8 lines.... however, after I run it once, my line0 thru line8 all end up on line0 ... so the next time it runs it messes up. I must need a chr(13), newline or something, but am stumped on how to get each line0 thru line8 on their own line. Help please>

path = "C:\\AMIWEB\\ZEROTEST.html";
StaticVarRemove("line*");
	fh = fopen( path, "r" );
	line = 0;
	while( ! feof( fh ) )
		{
			VarSetText("line"+(line++), fgets( fh ));
		}
	fclose( fh );

	LineX0 = "<HTML><P><FONT class='TITLE'><P ALIGN=CENTER><b>Analyses: ABO US Low Volatility<b></FONT></P></tr>";
	LineX1 = "<STYLE>";
	LineX2 = "<!--TH { font-family:Tahoma; } TH { text-align: left; } TH{ font-size:9pt;} TH{font-weight: normal;} TH{background-color:#c6d9eb;} .NOBOLD { font-size:8pt; text-align: center;font-weight: normal }";
	LineX3 = "BODY { font-family:Tahoma; } BODY { font-size:14; }";
	LineX4 = "TD { text-align: left; } TD { font-size:9pt; } TD{padding-right:10px;} tr:nth-child(even) {background: #FFF} tr:nth-child(odd) {background: #eeebeb}";
	LineX5 = "-->";
	LineX6 = "</STYLE>";
	LineX7 = "<!-- ABEXC: Type=0, ReportPath= --><BODY>";
	LineX8 = "<TABLE border=0 cellspacing='0' cellpadding='4' align='Center' column-gap='100';'>";
	
	VarSetText( "line0", LineX0 );
	VarSetText( "line1", LineX1 );	
	VarSetText( "line2", LineX2 );
	VarSetText( "line3", LineX3 );
	VarSetText( "line4", LineX4 );
	VarSetText( "line5", LineX5 );
	VarSetText( "line6", LineX6 );
	VarSetText( "line7", LineX7 );
	VarSetText( "line8", LineX8 );

	fh = fopen( path, "w" );
	
	for( i = 0; i < line; i++ )
	{
		fputs( VarGetText("line"+i ), fh );
	}

	fclose( fh );

finalUS

@mfu5324, just add a "\n" to each of your custom HTML lines.

By the way you can do it in a loop replacing the block of multiple repetitive lines (VarSetText( "line0", LineX0 ), etc.)

for( i = 0; i < 9; i++ )
    VarSetText( "line" + i, VarGetText( "LineX" + i) + "\n");
1 Like

AWESOME... worked perfect BIG THANKS TO ALL OF YOU

HERE IS THE FINAL CODE...

path = "C:\\AMIWEB\\ZEROTEST.html";
StaticVarRemove("line*");
	fh = fopen( path, "r" );
	line = 0;
	while( ! feof( fh ) )
		{
			VarSetText("line"+(line++), fgets( fh ));
		}
	fclose( fh );

	Line0 = "<HTML><P><FONT class='TITLE'><P ALIGN=CENTER><b>Analyses: ABO US Low Volatility<b></FONT></P></tr>\n";
	Line1 = "<STYLE>\n";
	Line2 = "<!--TH { font-family:Tahoma; } TH { text-align: left; } TH{ font-size:9pt;} TH{font-weight: normal;} TH{background-color:#c6d9eb;} .NOBOLD { font-size:8pt; text-align: center;font-weight: normal }\n";
	Line3 = "BODY { font-family:Tahoma; } BODY { font-size:14; }\n";
	Line4 = "TD { text-align: left; } TD { font-size:9pt; } TD{padding-right:10px;} tr:nth-child(even) {background: #FFF} tr:nth-child(odd) {background: #eeebeb}\n";
	Line5 = "-->\n";
	Line6 = "</STYLE>\n";
	Line7 = "<!-- ABEXC: Type=0, ReportPath= --><BODY>\n";
	Line8 = "<TABLE border=0 cellspacing='0' cellpadding='4' align='Center' column-gap='100';'>\n";
	
/*	VarSetText( "line0", LineX0 );
	VarSetText( "line1", LineX1 );	
	VarSetText( "line2", LineX2 );
	VarSetText( "line3", LineX3 );
	VarSetText( "line4", LineX4 );
	VarSetText( "line5", LineX5 );
	VarSetText( "line6", LineX6 );
	VarSetText( "line7", LineX7 );
*/	//VarSetText( "line8", LineX8 );

	fh = fopen( path, "w" );
	
	for( i = 0; i < line; i++ )
	{
		fputs( VarGetText("line"+i ), fh );
	}

	fclose( fh );
3 Likes