以前研究过输出excel表格的方法,找到一种快捷的报表输出方式,就是直接将html表格页面,直接更改输出方式为excel。
jsp代码这样更改:
?
String fileName = "test.xls";?
response.setContentType("application/x-octetstream;charset=UTF-8");?
response.setHeader("Content-disposition","attachment;filename=" + fileName + "");
输出使用这种方法,可以轻松输出excel报表。
html页面增加如下内容,可以冻结窗格:
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>这里是sheet的显示</x:Name>
<x:WorksheetOptions>
<x:FrozenNoSplit/>
<x:SplitHorizontal>3</x:SplitHorizontal>
<x:TopRowBottomPane>3</x:TopRowBottomPane>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
我还研究过输出图表(就是excel种的柱状图,饼图等各种图表),有兴趣的可以和我沟通,其实就是增加一些配置而已。
研究过程很简单,就是在excel表格中先输入一些数据或图表,然后另存为html,分析html中的代码,就可以获取输出表格或其他内容的方法。
注意,输出报表时,用js这样处理这样不会弹出窗口:
window.location = ?"http....."';//这里是报表输出页面。
输出图表范例:童鞋们可以把下面的代码复制到本地文件,改名为test.xls(已上传附件)。注意红色部分代码,
【部分内容解析:
<x:SplitHorizontal>4</x:SplitHorizontal>
<x:TopRowBottomPane>4</x:TopRowBottomPane>
<x:SplitVertical>2</x:SplitVertical>
<x:LeftColumnRightPane>2</x:LeftColumnRightPane>
这个是冻结窗格。
?x:autofilter="all"
x:autofilterrange="$B$1:$B$20"
这个是文本筛选。中间那块红色的部分是生成图表,图表部分位置更改,图表在excel中的位置会相应更改。
】
具体代码如下:
<html?xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
x\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>季度奖金分配报表</title>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>季度奖金分配报表</x:Name>
<x:WorksheetOptions>
<x:FrozenNoSplit/>
<x:SplitHorizontal>4</x:SplitHorizontal>
<x:TopRowBottomPane>4</x:TopRowBottomPane>
<x:SplitVertical>2</x:SplitVertical>
<x:LeftColumnRightPane>2</x:LeftColumnRightPane>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
<body leftmargin="0" topmargin="0" rightmargin="0" >
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<table width='95%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td align='center' colspan=28><font size='5'>季度奖金分配报表</font></td>
</tr>
<tr>
<td align='left' colspan=2>2005年3季度</td>
<td colspan=26> </td>
</tr>
</table>
</tr>
<tr>
<table width='95%' border='1' align='center' cellpadding='0' cellspacing='0'>
<tr bgcolor='99FF99'>
<td width='80' align='center'>全国</td>
<td width='150' align='center'>奖金总额</td>
<td width='150' align='center' colspan=3> </td>
<td width='640' align='center' colspan=16> </td>
<td width='80' align='center'>8575</td>
<td width='80' align='center'>7390.0</td>
<td width='80' align='center'> </td>
<td width='80' align='center'>10000</td>
<td width='80' align='center'>1.3532</td>
<td width='80' align='center' colspan=2> </td>
</tr>
</table>
</tr>
<tr>
<table width='95%' border='1' align='center' cellpadding='0' cellspacing='0'>
<tr bgcolor='99FF99'>
<td width='80' align='center' rowspan='54' nowrap>北区</td>
<td width='150' align='center' width='150' nowrap?x:autofilter="all"
x:autofilterrange="$B$1:$B$20"?>分销商</td>
<td width='50' align='center' nowrap>排名</td>
<td width='50' align='center' nowrap>积分</td>
<td align='center' nowrap>奖金系数</td>
<td align='center' colspan=4>K700c(0.0X)</td>
<td align='center' colspan=4>K508c(2.0X)</td>
<td align='center' colspan=4>S700c(0.0X)</td>
<td align='center' colspan=4>K750c(2.0X)</td>
<td width='80' align='center' nowrap>总销量</td>
<td width='80' align='center' nowrap>总单位X量</td>
<td align='center' nowrap>奖励系数量</td>
<td width='80' align='center' nowrap>实发奖金</td>
<td width='80' align='center' nowrap>单位X奖金</td>
<td align='center' nowrap>无系数奖金</td>
<td align='center' nowrap>排名奖金差额</td>
</tr>
<tr bgcolor='99FF99'>
<td align='center'> </td>
<td align='center' colspan=3> </td>
<td width='40' align='center' nowrap>7月</td>
<td width='40' align='center' nowrap>8月</td>
<td width='40' align='center' nowrap>9月</td>
<td width='40' align='center' nowrap>小计</td>
<td width='40' align='center' nowrap>7月</td>
<td width='40' align='center' nowrap>8月</td>
<td width='40' align='center' nowrap>9月</td>
<td width='40' align='center' nowrap>小计</td>
<td width='40' align='center' nowrap>7月</td>
<td width='40' align='center' nowrap>8月</td>
<td width='40' align='center' nowrap>9月</td>
<td width='40' align='center' nowrap>小计</td>
<td width='40' align='center' nowrap>7月</td>
<td width='40' align='center' nowrap>8月</td>
<td width='40' align='center' nowrap>9月</td>
<td width='40' align='center' nowrap>小计</td>
<td align='center' colspan=7> </td>
</tr>
<tr>
<td align='center'>山西艾森顶</td>
<td align='center'>1</td>
<td align='center'>83.06</td>
<td align='center'>1.5</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'>608</td>
<td align='center'>0</td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>608</font></td>
<td align='center'>16</td>
<td align='center'>0</td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>16</font></td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'><font color=BLUE>624</font></td>
<td align='center'>1216.0</td>
<td align='center'>1824.00</td>
<td align='center'><font color=RED>0</font></td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>0</font></td>
<td align='center'><font color=BLUE>0</font></td>
</tr>
<tr>
<td align='center'>山东松联</td>
<td align='center'>2</td>
<td align='center'>67.79</td>
<td align='center'>1.2</td>
<td align='center'>2132</td>
<td align='center'>0</td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>2132</font></td>
<td align='center'>800</td>
<td align='center'>0</td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>800</font></td>
<td align='center'>108</td>
<td align='center'>0</td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>108</font></td>
<td align='center'>1067</td>
<td align='center'>0</td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>1067</font></td>
<td align='center'><font color=BLUE>4107</font></td>
<td align='center'>3734.0</td>
<td align='center'>4480.80</td>
<td align='center'><font color=RED>0</font></td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>0</font></td>
<td align='center'><font color=BLUE>0</font></td>
</tr>
<tr>
<td align='center'>天津松联</td>
<td align='center'>3</td>
<td align='center'>63.08</td>
<td align='center'>1.0</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'>326</td>
<td align='center'>0</td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>326</font></td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'><font color=BLUE>326</font></td>
<td align='center'>652.0</td>
<td align='center'>652.00</td>
<td align='center'><font color=RED>0</font></td>
<td align='center'>0</td>
<td align='center'><font color=BLUE>0</font></td>
<td align='center'><font color=BLUE>0</font></td>
</tr>
<tr>
<td align='center'>北京志翔达利</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
</tr>
<tr>
<td align='center'>北京中鸿建</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
</tr>
<tr>
<td align='center'>北京中邮普泰</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
</tr>
<tr>
<td align='center'>北京健坤</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
</tr>
<tr>
<td align='center'>北京松联</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
</tr>
<tr>
<td align='center'>北京索尼</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
</tr>
<tr>
<td align='center'>天音新疆分公司</td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<!--[if gte vml 1]>
<v:shape id="_x0000_s1027" type="#_x0000_t201" style='position:absolute;
margin-left:7.5pt;margin-top:.75pt;width:339.75pt;height:199.5pt;z-index:1'
fillcolor="window [78]" strokecolor="windowText [77]" o:insetmode="auto">
<v:fill color2="windowText [77]"/>
<o:lock v:ext="edit" rotation="t" text="t"/>
<x:ClientData ObjectType="Chart">
<x:WebChart>
<x:Scaling>
<x:ScaleID>0</x:ScaleID>
<x:Orientation>MinMax</x:Orientation>
</x:Scaling>
<x:Scaling>
<x:ScaleID>1</x:ScaleID>
<x:Orientation>MinMax</x:Orientation>
</x:Scaling>
<x:Chart>
<x:Name>图表 5</x:Name>
<x:Options>
<x:SizeWithWindow/>
</x:Options>
<x:PageSetup>
<x:ChartSize>FullPage</x:ChartSize>
</x:PageSetup>
<x:Font>
<x:FontName>宋体</x:FontName>
<x:Size>9</x:Size>
<x:AutoScale/>
</x:Font>
<x:Left>0</x:Left>
<x:Top>0</x:Top>
<x:Width>6809</x:Width>
<x:Height>4005</x:Height>
<x:PlotArea>
<x:Interior>
<x:ColorIndex>14</x:ColorIndex>
<x:BGColorIndex>Neutral</x:BGColorIndex>
</x:Interior>
<x:Graph>
<x:Type>Column</x:Type>
<x:SubType>Clustered</x:SubType>
<x:Overlap>0</x:Overlap>
<x:ScaleID>0</x:ScaleID>
<x:ScaleID>1</x:ScaleID>
<x:Series>
<x:Index>0</x:Index>
<x:Caption>
<x:DataSource>-1</x:DataSource>
<x:Data>"test1111"</x:Data>
</x:Caption>
<x:Name>季度奖金分配报表</x:Name>
<x:Category>
<x:DataSource>0</x:DataSource>
<x:Data>季度奖金分配报表!$B$3:$B$5</x:Data>
</x:Category>
<x:Value>
<x:DataSource>0</x:DataSource>
<x:Data>季度奖金分配报表!$D$3:$D$5</x:Data>
</x:Value>
</x:Series>
<x:PlotVisible/>
</x:Graph>
<x:Axis>
<x:Placement>Bottom</x:Placement>
<x:AxisID>0</x:AxisID>
<x:ScaleID>0</x:ScaleID>
<x:CrossingAxis>1</x:CrossingAxis>
<x:Font>
<x:FontName>宋体</x:FontName>
<x:Size>9.25</x:Size>
<x:AutoScale/>
</x:Font>
<x:Number>
<x:SourceLinked/>
<x:BuiltInFormat>0</x:BuiltInFormat>
</x:Number>
<x:MajorTick>Inside</x:MajorTick>
<x:TickMarkSkip>1</x:TickMarkSkip>
<x:Type>Automatic</x:Type>
</x:Axis>
<x:Axis>
<x:Placement>Left</x:Placement>
<x:AxisID>1</x:AxisID>
<x:ScaleID>1</x:ScaleID>
<x:MajorGridlines/>
<x:CrossingAxis>0</x:CrossingAxis>
<x:CrossesAt>Minimum</x:CrossesAt>
<x:CrossBetween>Between</x:CrossBetween>
<x:Number>
<x:SourceLinked/>
<x:BuiltInFormat>0</x:BuiltInFormat>
</x:Number>
<x:MajorTick>Inside</x:MajorTick>
<x:Type>Value</x:Type>
</x:Axis>
</x:PlotArea>
<x:Legend>
<x:Placement>Right</x:Placement>
</x:Legend>
</x:Chart>
</x:WebChart>
</x:ClientData>
</v:shape><![endif]-->
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
<td align='center'> </td>
</tr>
<tr bgcolor='99FF99'>
<td align='center'>北区总量</td>
<td align='center' colspan=19> </td>
<td align='center'>5057</td>
<td align='center'>5602.0</td>
<td align='center'>6956.8</td>
<td align='center'>0</td>
<td align='center' colspan=3> </td>
</tr>
<tr bgcolor='99FF99'>
<td align='center'>单台奖金</td>
<td align='center' colspan=20> </td>
<td align='center'>1.3532</td>
<td align='center'>0.0</td>
<td align='center' colspan=4> </td>
</tr>
<tr bgcolor='99FF99'>
<td align='center'>北区总奖金</td>
<td align='center' colspan=22> </td>
<td align='center'><font color=RED>0</font></td>
<td align='center' colspan=3> </td>
</tr>
</table>
</tr>
<tr>
<table width='95%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr height=20>
<td> </td>
</tr>
</table>
</tr>
</table>
</tr>
</table>
</tr>
</table>
</body>
</html>