将htmlwrite.zip 解压后,并将上面flash放在该文件夹中,主要有四个m文件,run_web.m主要示例文件。html_table.m生成表格web,html_script.m生成table链接web,html_myflash.m 生成调用flash的web mhhh run_web.m %test colheads = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Year'}; rowheads = {'Yield Budget'; 'Yield Actual'; 'Likely EOM'; 'Yield Variance'}; data = rand(4,12) * 2000 - 600; data(:,end+1) = sum(data,2); table_cell = [[{'Period'};rowheads] [colheads; num2cell(data)]]; caption_str = 'Test of HTML Table Output'; %创建table html_table(table_cell, 'run_web.html', 'Caption',caption_str, ... 'DataFormatStr','%1.0f', 'BackgroundColor','#EFFFFF', 'RowBGColour',{'#000099',[],[],[],'#FFFFCC'}, 'RowFontColour',{'#FFFFB5'}, ... 'FirstRowIsHeading',1, 'FirstColIsHeading',1,... 'NegativeCellFontColour','red'); %创建script html_script(table_cell,'run_web.html'); %创建flash web for k=1:4 html_myflash(table_cell, strcat(rowheads{k},'.html'),'row',k,'Title',... 'caption','xName','数值','yName','时间',... 'Cnames','主要', 'TitleName',rowheads{k},'Gtypes','bar|line|hbar|pie|mline|fun','Total',data(k,end)); end dos('explorer run_web.html'); html_table.m function s = html_table(table_cell, fname, varargin) % html_table writes a cell-array to an html file for display via html browsers. % % INPUTS: % s is an optional output argument if a string of the html code is required. % table_cell is a 2D cell array of the table contents. This should include the row and column headers if they are needed. % fname is a string for the file name, e.g. 'test_html_table.html' % Other options can be added as param-value pairs as listed in the code (esp for formatting the table). % % EXAMPLE: % colheads = {'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Year'}; % rowheads = {'Yield Budget'; 'Yield Actual'; 'Likely EOM'; 'Yield Variance'}; % data = rand(4,12) * 2000 - 600; % data(:,end+1) = sum(data,2); % table_cell = [[{'Period'};rowheads] [colheads; num2cell(data)]]; %Add row and col heading cell-arrays onto a double data matrix % caption_str = 'Test of HTML Table Output'; % html_table(table_cell, 'test_html_table.html', 'Caption',caption_str, ... % 'DataFormatStr','%1.0f', 'BackgroundColor','#EFFFFF', 'RowBGColour',{'#000099',[],[],[],'#FFFFCC'}, 'RowFontColour',{'#FFFFB5'}, ... % 'FirstRowIsHeading',1, 'FirstColIsHeading',1, 'NegativeCellFontColour','red'); % % Note re colours: These can be specified as text strings of either: % a) One of the html 16 color names, e.g. 'black' % b) Hexadecimal, e.g. '#CCFFFF' ref: http://www.quackit.com/html/html_color_codes.cfm for colour charts. % c) RGB, e.g. 'rgb(100,255,100)' % % AUTHOR: Roger Parkyn, roger.parkyn@hydro.com.au %% Sort out the inputs p = inputParser; % Create an instance of the inputParser class. p.addRequired('table_cell', @iscell); p.addRequired('fname', @ischar); p.addParamValue('WriteFileHtmlHeaders', true, @islogical); %Headers to allow the output file to look like a stand-alone html file. p.addParamValue('Title', [], @ischar); p.addParamValue('FontColor', 'black', @ischar); p.addParamValue('FontSize', 12, @isnumeric); p.addParamValue('FontFace', 'arial', @ischar); p.addParamValue('TextAlign', 'center', @(x)any(strcmpi(x,{'left','center','right'}))); p.addParamValue('CellPadding', 2.5, @isnumeric); p.addParamValue('CellSpacing', 0, @isnumeric); p.addParamValue('BorderSize', 1, @isnumeric); p.addParamValue('BorderColor', 'black', @ischar); p.addParamValue('BackgroundColor', 'white', @ischar); %Background colour of the whole table p.addParamValue('Caption', [], @ischar); %This give a caption above the table p.addParamValue('DataFormatStr', '%1.1f', @ischar); %Format of numeric data, e.g. '%1.3f' for 3 decimal places p.addParamValue('FirstRowIsHeading', 0, @isnumeric); %Enter 1 to make the first row a heading style row (shown in bold font) p.addParamValue('FirstColIsHeading', 0, @isnumeric); %Enter 1 to make the first column a heading style col (shown in bold font) p.addParamValue('RowBGColour', {}, @iscell); %Cell vector of background colour strings: if not empty, each i-th element of this cell-vector will over-ride the table bg colour for the i-th row. p.addParamValue('RowFontColour', {}, @iscell); %Cell vector of background colour strings: if not empty, each i-th element of this cell-vector will over-ride the table bg colour for the i-th row. p.addParamValue('NegativeCellFontColour', [], @ischar); %Over-ride to font colour if the cell is numeric and negative. p.parse(table_cell, fname, varargin{:}); %Pad RowBGColour with empty cells (in case the colours are not defined for later rows of the table) bgc_override = p.Results.RowBGColour; for i = 1+length(p.Results.RowBGColour):size(table_cell,1) bgc_override{i} = []; end row_font_override = p.Results.RowFontColour; for i = 1+length(p.Results.RowFontColour):size(table_cell,1) row_font_override{i} = []; end %% set up an HTML table fid = fopen(fname,'w+'); if p.Results.WriteFileHtmlHeaders fprintf(fid,['<html>/n/n/t<head>/n/t/t<title>',p.Results.Title, '</title>/n/t</head>/n/n/t<body>/n/n']); end fprintf(fid,['/t/t<table style=" color:',p.Results.FontColor,'; ',... 'font-size:', num2str(p.Results.FontSize),'; ',... 'font-family:', p.Results.FontFace,'; ',... 'text-align:', p.Results.TextAlign,'; " mce_style=" color:',p.Results.FontColor,'; ',... 'font-size:', num2str(p.Results.FontSize),'; ',... 'font-family:', p.Results.FontFace,'; ',... 'text-align:', p.Results.TextAlign,'; " ',... 'cellpadding="',num2str(p.Results.CellPadding),'" ',... 'cellspacing="',num2str(p.Results.CellSpacing),'" ',... 'border="',num2str(p.Results.BorderSize),'" ',... 'bordercolor="',p.Results.BorderColor,'" ',... 'bgcolor="',p.Results.BackgroundColor,'"',... '>/n']); fprintf(fid,['/t/t/t<caption>',p.Results.Caption,'</caption>/n']); %add the caption %% Step through and print each table element for i=1:size(table_cell,1); %begin a row of the table. if ~isempty(bgc_override{i}) || ~isempty(row_font_override{i}) fprintf(fid, ['/t/t/t<tr style="color:' row_font_override{i} ';background:' bgc_override{i} '" mce_style="color:' row_font_override{i} ';background:' bgc_override{i} '">/n']); else fprintf(fid,'/t/t/t<tr>/n'); end for j=1:size(table_cell,2); %step through each column in the current row if isnumeric(table_cell{i,j}) && ~isempty(table_cell{i,j}) && ~isnan(table_cell{i,j}); if (table_cell{i,j}>=0.0) || isempty(p.Results.NegativeCellFontColour) c = [' align="right"> ' num2str(table_cell{i,j}, p.Results.DataFormatStr)]; %Convert numbers to strings and right align them else % Add the negative-cell colour over-ride c = [' align="right" style=" color:' p.Results.NegativeCellFontColour '; "> ' num2str(table_cell{i,j}, p.Results.DataFormatStr)]; %Convert numbers to strings and right align them end elseif ischar(table_cell{i,j}) c = ['>' table_cell{i,j}]; else c = '> '; %'Non Breaking White Space' - If it's not a char not a numeric, or is NaN. end if (p.Results.FirstRowIsHeading && i==1) || (p.Results.FirstColIsHeading && j==1) fprintf(fid,['/t/t/t/t<th',c,'</th>/n']); %write a TableData element in heading style else fprintf(fid,['/t/t/t/t<td',c,'</td>/n']); %write a TableData element - Normal style end end fprintf(fid,'/t/t/t</tr>/n');%close the TableRow end %% Close fprintf(fid,'/t/t</table>/n/n'); %Close the table if p.Results.WriteFileHtmlHeaders fprintf(fid,' /t</body>/n/n</html>'); end %If an output string is required read it from the file if nargout > 0 frewind(fid); s = fscanf(fid, '%c', inf); end fclose(fid); %close the output file html_script.m function s = html_script(table_cell, fname,varargin) %% Sort out the inputs p = inputParser; % Create an instance of the inputParser class. p.addRequired('table_cell', @iscell); p.addRequired('fname', @ischar); p.addParamValue('WriteFileHtmlHeaders', true, @islogical); p.parse(table_cell, fname, varargin{:}); %% set up an HTML table fid = fopen(fname,'a+'); if p.Results.WriteFileHtmlHeaders fprintf(fid,'/n<html>/n/n/t<body>/n/n'); end fprintf(fid,['/t/t <mce:script type="text/javascript"><!-- /n',... '/t/t/t function linkClick(link)/n',... '/t/t/t/t {/n',... '/t/t/t/t hs.innerHTML = /''/'' ;/n',... '/t/t/t/t var iframe = document.createElement(/''<iframe width=/"100%%/" height=/"100%%/">/'');/n',... '/t/t/t/t iframe.src = link.href ;/n',... '/t/t/t/ths.appendChild(iframe);/n',... '/t/t/t/t return false;/n',... '/t/t/t/t}/n',... '/t/t/t // --></mce:script>/n',... '/t/t</head>/n',... '/t<body>/n']); %% 插入数据 for i=2:size(table_cell,1); fprintf(fid, ['<a href="',... table_cell{i,1},'.html','" mce_href="',... table_cell{i,1},'.html','" οnclick="return linkClick(this)">',... table_cell{i,1},'</a> | ']); end %% Close fprintf(fid,'/n <div id="hs">在此处显示外部网页</div>/n'); %Close the table if p.Results.WriteFileHtmlHeaders fprintf(fid,' /t</body>/n/n</html>'); end %If an output string is required read it from the file if nargout > 0 frewind(fid); s = fscanf(fid, '%c', inf); end fclose(fid); %close the output file html_myflash.m function s = html_myflash(table_cell, fname,varargin) %% Sort out the inputs p = inputParser; % Create an instance of the inputParser class. p.addRequired('table_cell', @iscell); p.addRequired('fname', @ischar); p.addParamValue('WriteFileHtmlHeaders', true, @islogical); p.addParamValue('row',1,@isnumeric); p.addParamValue('Title',@ischar); p.addParamValue('xName', @ischar); p.addParamValue('yName', @ischar); p.addParamValue('Cnames', @ischar); p.addParamValue('DataType',20, @isnumeric); p.addParamValue('TitleName', @ischar); p.addParamValue('Fsize',23, @isnumeric); p.addParamValue('Gtypes', @ischar); p.addParamValue('Total', 0, @isnumeric); p.parse(table_cell, fname, varargin{:}); %% set up an HTML table fid = fopen(fname,'w+'); if p.Results.WriteFileHtmlHeaders fprintf(fid,['<html>/n/n/t<head>/n/t/t<title>',p.Results.Title, '</title>/n/t</head>/n/n/t<body>/n/n']); end fprintf(fid,['/t/t<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ',... 'codebase="http://svmat.cublog.cn/#version=7,0,0,0" width="800" height="375" id="UrchinGraph" align="middle"', '>/n']); fprintf(fid,['<param name="allowScriptAccess" value="sameDomain" />/n',... '<param name="movie" value="Graph.swf" />/n',... '<param name="quality" value="high" />/n',... '<param name="bgcolor" value="#ffffff" />/n',... '<param name="wmode" value="transparent" />']); fprintf(fid,['<param name="FlashVars" value="ntitle=',p.Results.xName,... '&toggle=','全部显示|全部隐藏', ... '&vtitle=', p.Results.yName,... '&cnames=', p.Results.Cnames,... '&datatype=',num2str(p.Results.DataType),... '&rtitle=',p.Results.TitleName,... '&fsize=',num2str(p.Results.Fsize),... '>ypes=',p.Results.Gtypes,... '&total=',num2str(p.Results.Total),... '&xdata=']); %% 插入数据 i=p.Results.row+1; for j=2:size(table_cell,2); fprintf(fid, [table_cell{1,j},'//t',num2str(table_cell{i,j}),'//n']); end %% embed fprintf(fid,['/n<embed src="Graph.swf" mce_src="Graph.swf" quality="high"',... 'bgcolor="#ffffff" width="800" height="375" ',... 'name="UrchinGraph" align="middle" wmode="transparent"',... 'allowScriptAccess="sameDomain" '... 'type="application/x-shockwave-flash" ',... 'pluginspage="http://svmat.cublog.cn/" />']); %% Close fprintf(fid,'/t/t</table>/n/n'); %Close the table if p.Results.WriteFileHtmlHeaders fprintf(fid,' /t</body>/n/n</html>'); end %If an output string is required read it from the file if nargout > 0 frewind(fid); s = fscanf(fid, '%c', inf); end fclose(fid); %close the output file