国标GB/T4754的HTML转换程序

戻る


gbt4754_0.htm(new)

<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>GB/T4754-2002,国民经济行业分类,Industrial classification for national economic activities</TITLE> </HEAD> <BODY bgcolor="#FFFFFF"> <center> <h2>GB/T4754-2002,国民经济行业分类,Industrial classification for national economic activities</h2> </center> <a href="economic1.htm">返回</a> <hr color="#003366"> <center> <table width=85% align="center" border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th colspan=4 width=20%>代码</th> <th rowspan=2 width=40%>类别名称</th> <th rowspan=2 width=40%>说明</th> </tr> <tr bgcolor="#3399FF" align="center"> <th>门类</th> <th>大类</th> <th>中类</th> <th>小类</th> </tr> <TMPL_LOOP NAME="LOOP"> <tr bgcolor="lightcyan"> <TMPL_VAR NAME="LINE1"> </tr> </TMPL_LOOP> <tr bgcolor="#3399FF" align="center"> <th>门类</th> <th>大类</th> <th>中类</th> <th>小类</th> <th rowspan=2 width=40%>类别名称</th> <th rowspan=2 width=40%>说明</th> </tr> <tr bgcolor="#3399FF" align="center"> <th colspan=4 width=20%>代码</th> </tr> </table> <br><br> <h3>企业登记注册类型(国统[1998]200号)</h3> <table width=85% align="center" border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th width=20%>编码</th> <th width=80%>企业登记注册类型</th> </tr> <TMPL_LOOP NAME="LOOP2"> <tr bgcolor="lightcyan" align="left"> <td><TMPL_VAR NAME="A"></td> <td><TMPL_VAR NAME="B"></td> </tr> </TMPL_LOOP> </table> <hr color="#003366"> </center> <a href="economic1.htm">返回</a><br> </BODY> </HTML> -------------------------------------------

gbt4754_0.htm(old)

<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>GB/T4754-2002,国民经济行业分类,Industrial classification for national economic activities</TITLE> </HEAD> <BODY bgcolor="#FFFFFF"> <center> <h2>GB/T4754-2002,国民经济行业分类,Industrial classification for national economic activities</h2> </center> <a href="economic1.htm">返回</a> <hr color="#003366"> <center> <table width=85% align="center" border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th colspan=4 width=20%>代码</th> <th rowspan=2 width=40%>类别名称</th> <th rowspan=2 width=40%>说明</th> </tr> <tr bgcolor="#3399FF" align="center"> <th>门类</th> <th>大类</th> <th>中类</th> <th>小类</th> </tr> <TMPL_LOOP NAME="LOOP"> <tr bgcolor="lightcyan" align="left"> <td><TMPL_VAR NAME="A1"></td> <td><TMPL_VAR NAME="A2"></td> <td><TMPL_VAR NAME="A3"></td> <td><TMPL_VAR NAME="A4"></td> <td><TMPL_VAR NAME="B1"></td> <td><TMPL_VAR NAME="C1"></td> </tr> </TMPL_LOOP> <tr bgcolor="#3399FF" align="center"> <th>门类</th> <th>大类</th> <th>中类</th> <th>小类</th> <th rowspan=2 width=40%>类别名称</th> <th rowspan=2 width=40%>说明</th> </tr> <tr bgcolor="#3399FF" align="center"> <th colspan=4 width=20%>代码</th> </tr> </table> <h3>企业登记注册类型(国统[1998]200号)</h3> <table width=85% align="center" border=1 cellpadding=5> <tr bgcolor="#3399FF" align="center"> <th width=20%>编码</th> <th width=80%>企业登记注册类型</th> </tr> <TMPL_LOOP NAME="LOOP2"> <tr bgcolor="lightcyan" align="left"> <td><TMPL_VAR NAME="A"></td> <td><TMPL_VAR NAME="B"></td> </tr> </TMPL_LOOP> </table> <hr color="#003366"> </center> <a href="economic1.htm">返回</a><br> </BODY> </HTML> -------------------------------------------

gbt4754_0.pl(new)

# gbt4754.pl use strict; use HTML::Template; use utf8; my(%t,@fld,$n,$template,@loop,@loop2); open(IN,"name.txt") or die "Can't open the file name.txt.\n"; while(<IN>) { if ( /^8888/ ) { @fld = split; $t{d1} = $fld[1]; } } close(IN); # Read csv data @loop = (); $t{NO} = 0; open(IN,"gbt4754.txt") or die "Can't open the file gbt4754.txt.\n"; while(<IN>){ next if $. == 1; chop; $t{NO}++; $t{TYPE1} = 0; @fld = split($t{d1}); $t{A1} = $fld[0]; if ( $t{A1} =~ /[A-Z]/ ) { $t{A1} =~ s/\s$//g; # 把末尾的空格去掉 $t{LINE_A1}{$t{NO}} = $t{A1}; $t{TYPE1} = 'A1'; $t{A1_old} = $t{A1}; $t{lists}{$t{A2_old}}--; # A1类侵占了A2类的位置,需要减去1 $t{lists}{$t{A3_old}}--; # A1类侵占了A3类的位置,需要减去1 } else { $t{lists}{$t{A1_old}}++; # A1类自己增加一个空格 } $t{A2} = $fld[1] + 0; if ( $t{A2} != 0 ) { $t{A2} = sprintf("%02d",$t{A2}); $t{LINE_A2}{$t{NO}} = $t{A2}; $t{TYPE1} = 'A2'; $t{A2_old} = $t{A2}; $t{lists}{$t{A3_old}}--; # A2类侵占了A3类的位置,需要减去1 } else { $t{lists}{$t{A2_old}}++; # A2类自己增加一个空格 } $t{A3} = $fld[2] + 0; if ( $t{A3} != 0 ) { $t{A3} = sprintf("%03d",$t{A3}); $t{LINE_A3}{$t{NO}} = $t{A3}; $t{TYPE1} = 'A3'; $t{A3_old} = $t{A3}; } else { $t{lists}{$t{A3_old}}++; } $t{A4} = $fld[3] + 0; if ( $t{A4} != 0 ) { $t{A4} = sprintf("%04d",$fld[3]); } $t{LINE_A4}{$t{NO}} = $t{A4}; $t{LINE_B1}{$t{NO}} = $fld[4]; $t{LINE_C1}{$t{NO}} = $fld[5]; if ( $t{TYPE1} ) { push(@{ $t{LINE_TYPE} },$t{TYPE1}); } else { push(@{ $t{LINE_TYPE} },'A0'); } } close(IN); # 把数据输出到HTML文件 for $n ( 1 .. $t{NO} ) { $t{TYPE1} = $t{LINE_TYPE}[$n-1]; if ( $t{TYPE1} eq 'A1' ) { $t{A1} = $t{LINE_A1}{$n}; $t{A1no} = $t{lists}{$t{A1}} + 1; # 这个操作是关键! 出了变量$t{LINE_B1}{$n},其他的参数如 td,rowspan等也可以作为Template的变量! $t{LINE1} = '<td valign="top" rowspan=' . $t{A1no} . '>'; $t{LINE1} .= $t{A1} . '</td>'; $t{LINE1} .= '<td colspan=3></td>'; $t{LINE1} .= '<td>' . $t{LINE_B1}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_C1}{$n} . '</td>'; } elsif ( $t{TYPE1} eq 'A2' ) { $t{A2} = $t{LINE_A2}{$n}; $t{A2no} = $t{lists}{$t{A2}} + 1; $t{LINE1} = '<td valign="top" rowspan=' . $t{A2no} . '>'; $t{LINE1} .= $t{A2} . '</td>'; $t{LINE1} .= '<td colspan=2></td>'; $t{LINE1} .= '<td>' . $t{LINE_B1}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_C1}{$n} . '</td>'; } elsif ( $t{TYPE1} eq 'A3' ) { if ( $t{LINE_A4}{$n} == 0 ) { $t{A3} = $t{LINE_A3}{$n}; $t{A3no} = $t{lists}{$t{A3}} + 1; $t{LINE1} = '<td valign="top" rowspan=' . $t{A3no} . '>'; $t{LINE1} .= $t{A3} . '</td>'; $t{LINE1} .= '<td></td>'; $t{LINE1} .= '<td>' . $t{LINE_B1}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_C1}{$n} . '</td>'; } else { $t{A3} = $t{LINE_A3}{$n}; $t{A3no} = $t{lists}{$t{A3}} + 1; $t{LINE1} = '<td valign="top" rowspan=' . $t{A3no} . '>'; $t{LINE1} .= $t{A3} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_A4}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_B1}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_C1}{$n} . '</td>'; } } else { $t{LINE1} = '<td>' . $t{LINE_A4}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_B1}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_C1}{$n} . '</td>'; } my %row = ( LINE1 => $t{LINE1} ); push(@loop, \%row); } # 输出第二个表格 @loop2 = (); open(IN,"gbt4754_2.txt") or die "Can't open the file gbt4754_2.txt.\n"; while(<IN>){ next if $. == 1; chop; @fld = split($t{d1}); $t{A} = $fld[0]; $t{B} = $fld[1]; if ( $#fld == 1 ) { my %row = ( A => $t{A}, B => $t{B} ); push(@loop2, \%row); } } close(IN); $template = HTML::Template->new(filename => "gbt4754_0.htm"); $template->param(loop => \@loop); $template->param(loop2 => \@loop2); open(OUT,">gbt4754_2002.htm"); print OUT $template->output; close(OUT); print "The output file is gbt4754_2002.htm\n"; __END__; -------------------------------------------

gbt4754.pl(old)

# gbt4754.pl use strict; use HTML::Template; use utf8; my(%t,@fld,$n,$template,@loop,@loop2); open(IN,"name.txt") or die "Can't open the file name.txt.\n"; while(<IN>) { if ( /^8888/ ) { @fld = split; $t{d1} = $fld[1]; } } close(IN); # Read csv data @loop = (); open(IN,"gbt4754.txt") or die "Can't open the file gbt4754.txt.\n"; while(<IN>){ next if $. == 1; chop; @fld = split($t{d1}); $t{A1} = $fld[0]; $t{A2} = $fld[1] + 0; if ( $t{A2} != 0 ) { $t{A2} = sprintf("%02d",$t{A2}); } else { $t{A2} = ''; } $t{A3} = $fld[2] + 0; if ( $t{A3} != 0 ) { $t{A3} = sprintf("%03d",$t{A3}); } else { $t{A3} = ''; } $t{A4} = $fld[3] + 0; if ( $t{A4} != 0 ) { $t{A4} = sprintf("%04d",$t{A4}); } else { $t{A4} = ''; } $t{B1} = $fld[4]; $t{C1} = $fld[5]; my %row = ( A1 => $t{A1}, A2 => $t{A2}, A3 => $t{A3}, A4 => $t{A4}, B1 => $t{B1}, C1 => $t{C1} ); push(@loop, \%row); } close(IN); @loop2 = (); open(IN,"gbt4754_2.txt") or die "Can't open the file gbt4754_2.txt.\n"; while(<IN>){ next if $. == 1; chop; @fld = split($t{d1}); $t{A} = $fld[0]; $t{B} = $fld[1]; if ( $#fld == 1 ) { my %row = ( A => $t{A}, B => $t{B} ); push(@loop2, \%row); } } close(IN); $template = HTML::Template->new(filename => "gbt4754_0.htm"); $template->param(loop => \@loop); $template->param(loop2 => \@loop2); open(OUT,">gbt4754.htm"); print OUT $template->output; close(OUT); print "The output file is gbt4754.htm\n"; __END__; ------------------------------------------- filename=name.txt 8888 XX -------------------------------------------

EXCEL->TXT->HTML程序,safe.pl

use strict; use HTML::Template; use utf8; my(%t,@fld,$n,$n1,$template,@loop); open(IN,"name.txt") or die "Can't open the file name.txt.\n"; while(<IN>) { if ( /^8888/ ) { @fld = split; $t{d1} = $fld[1]; $t{d2} = $fld[2]; $t{d3} = $fld[3]; } } close(IN); # Read csv data @loop = (); $t{NO} = 0; $t{NO1} = 0; open(IN,"safe.txt") or die "Can't open the file safe.txt.\n"; while(<IN>){ chop; $t{NO}++; $t{TYPE1} = 0; @fld = split($t{d1}); $t{A1} = $fld[0]; if ( $t{A1} =~ /$t{d2}/ ) { $t{LINE_A1}{$t{NO}} = $t{A1}; $t{TYPE1} = 'A1'; $t{A1_old} = $t{A1}; } elsif ( $t{A1} =~ /$t{d3}/ ) { $t{LINE_A1}{$t{NO}} = $t{NO1}; $t{TYPE1} = 'A2'; } else { $t{lists}{$t{A1_old}}++; } if ( $t{TYPE1} eq 'A1') { push(@{ $t{LINE_TYPE} },$t{TYPE1}); push(@{ $t{LINE_NO1} },$t{NO1}); } elsif ( $t{TYPE1} eq 'A2' ) { push(@{ $t{LINE_TYPE} },$t{TYPE1}); push(@{ $t{LINE_NO1} },$t{NO1}); @{ $t{LINE_B}{$t{NO}} } = @fld; } else { $t{NO1}++; push(@{ $t{LINE_TYPE} },'A0'); push(@{ $t{LINE_NO1} },$t{NO1}); @{ $t{LINE_B}{$t{NO}} } = @fld; } } close(IN); for $n ( 1 .. $t{NO} ) { $t{TYPE1} = $t{LINE_TYPE}[$n-1]; $t{NO1} = $t{LINE_NO1}[$n-1]; if ( $t{TYPE1} eq 'A1' ) { $t{A1} = $t{LINE_A1}{$n}; $t{A1no} = $t{lists}{$t{A1}} + 1; $t{LINE1} = '<td colspan=6>'; $t{LINE1} .= $t{A1} . '</td>'; } elsif ( $t{TYPE1} eq 'A2' ) { $t{A1} = $t{LINE_A1}{$n}; $t{LINE1} = '<td>'; $t{LINE1} .= $t{A1} . '</td>'; @fld = @{ $t{LINE_B}{$n} }; for $n1 ( 1 .. $#fld ) { $t{LINE1} .= '<td>' . $fld[$n1] . '</td>'; } } else { $t{NO1} = sprintf("%02d",$t{NO1}); $t{LINE1} = '<td>' . $t{NO1} . '</td>'; @fld = @{ $t{LINE_B}{$n} }; for $n1 ( 1 .. $#fld ) { $t{LINE1} .= '<td>' . $fld[$n1] . '</td>'; } } my %row = ( LINE1 => $t{LINE1} ); push(@loop, \%row); } $template = HTML::Template->new(filename => "safe0.htm"); $template->param(loop => \@loop); open(OUT,">safe_2008.htm"); print OUT $template->output; close(OUT);

EXCEL->TXT->HTML程序,3835.pl

use strict; use HTML::Template; use utf8; my(%t,@fld,$n,$template,@loop); #print "Please input filename(*.txt)="; #chop($t{root}=<STDIN>); $t{inputf} = '3835.txt'; $t{htm0} = 'it0.htm'; $t{outputf} = 'it1.htm'; open(IN,"name.txt") or die "Can't open the file name.txt.\n"; while(<IN>) { if ( /^8888/ ) { @fld = split; $t{d1} = $fld[1]; } } close(IN); # Read excel data @loop = (); $t{NO} = 0; open(IN,"$t{inputf}") or die "Can't open the file $t{inputf}.\n"; while(<IN>){ chop; $t{NO}++; @fld = split($t{d1}); $t{LINE_C1}{$t{NO}} = $fld[2]; if ( $t{NO} % 2 == 1 ) { $t{LINE_B1}{$t{NO}} = $fld[1]; } else { $t{LINE_B1}{$t{NO}} = 0; } $t{TYPE1} = 0; $t{A1} = $fld[0]; if ( $t{A1} ne "\t" ) { $t{TYPE1} = 'A1'; $t{LINE_A1}{$t{NO}} = $fld[0]; $t{P1} = 'P' . $t{NO}; $t{lists}{$t{P1}}++; } else { $t{lists}{$t{P1}}++; } if ( $t{TYPE1} && $t{LINE_B1}{$t{NO}} ) { $t{LINE_TYPE}{$t{NO}} = 'A1'; } elsif ( $t{TYPE1} == 0 && $t{LINE_B1}{$t{NO}} ) { $t{LINE_TYPE}{$t{NO}} = 'A2'; } else { $t{LINE_TYPE}{$t{NO}} = 'A0'; } } close(IN); for $n ( 1 .. $t{NO} ) { $t{TYPE1} = $t{LINE_TYPE}{$n}; if ( $t{TYPE1} eq 'A1' ) { $t{A1} = $t{LINE_A1}{$n}; $t{P1} = 'P' . $n; $t{P1no} = $t{lists}{$t{P1}}; $t{LINE1} = '<tr bgcolor="lightcyan"><td rowspan=' . $t{P1no} . '>'; $t{LINE1} .= $t{A1} . '</td>'; $t{LINE1} .= '<td rowspan=2>' . $t{LINE_B1}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_C1}{$n} . '</td></tr>'; } elsif ( $t{TYPE1} eq 'A2' ) { $t{LINE1} = '<tr bgcolor="lightcyan">'; $t{LINE1} .= '<td rowspan=2>' . $t{LINE_B1}{$n} . '</td>'; $t{LINE1} .= '<td>' . $t{LINE_C1}{$n} . '</td></tr>'; } elsif ( $t{TYPE1} eq 'A0' ) { $t{LINE1} = '<tr bgcolor="lightcyan">'; $t{LINE1} .= '<td>' . $t{LINE_C1}{$n} . '</td></tr>'; } else { print "ERROR!\n"; exit; } my %row = ( LINE1 => $t{LINE1} ); push(@loop, \%row); } $template = HTML::Template->new(filename => "$t{htm0}"); $template->param(loop => \@loop); open(OUT,">$t{outputf}"); print OUT $template->output; close(OUT);
戻る