ExcelUtils--excel报表模板引擎

本文介绍了一款基于POI的Excel操作工具——ExcelUtils,通过一个简单的Spring控制器示例展示了如何利用该工具将数据库中的数据导出为Excel文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

做过java的人应该都经历过将数据库中的数据导出到excel中的情况,

一般来说会使用poi或jxl等成型的工具,现在向大家推荐一款很好用的工具ExcelUtils,它是基于poi的。

ExcelUtils:an excel report template engine for Java

主站地址:http://excelutils.sourceforge.net

从网站上可以很容易的学习到ExcelUtils的使用方法,这里写一个简单的例子:

excel模板:/WEB-INF/xls/balance.xls

java:我使用的spring2.5基于注解的controller

import static com.netqin.common.GlobalNamingConstant.OPERATE_LIST;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.excelutils.ExcelException;
import net.sf.excelutils.ExcelUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.netqin.common.Sorter;
import com.netqin.common.annotation.UserOperateLog;
import com.netqin.function.settlement.model.BalanceApplyInfo;
import com.netqin.function.settlement.service.IChannelChargeService;
import com.netqin.web.SimpleBaseController;

@Controller
public class ChannelChargeController{

@Autowired
private IChannelChargeService channelChargeService;

/**
* 描述 : <结算报表导出excel>. <br>
* <p>
*
* @param bean
* @param model
* @param flog
* @return
*/
@RequestMapping("/settlement/export_excel.do")
@UserOperateLog(value = "报表导出", type = OPERATE_LIST)
public String handleExportExcel(BalanceApplyInfo bean, Model model,
int flog, HttpServletRequest request, HttpServletResponse response) {
List<BalanceApplyInfo> list = channelChargeService.selectAll(bean,
new Sorter(), null, flog);

ExcelUtils.addValue("list", list);

String config = "/WEB-INF/xls/balance.xls";
response.reset();
response.setContentType("application/vnd.ms-excel");
try {
ExcelUtils.export(request.getSession().getServletContext(), config,
response.getOutputStream());
} catch (ExcelException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return null;
}

}

值得注意的是,在使用#sum allusernum on ${list}进行汇总时,allusernum 的数据类型一定要是double的,否则不能进行汇总,这也许是ExcelUtils的bug.

Excel Report Builder<br>Excel Report 万能报表平台<br>Excel 使用WEB服务(webservice)访问远程数据库<br>使用本软件可以使你的应用系统(数据库)和excel相连。<br>可以把它嵌入到你的应用系统里,做为应用系统的外挂程序。<br>可以利用excel强大的编辑功能,随心所欲地开发出精美的报表。<br>本软件基于Web Service(Web服务)新技术,所以它支持web网络,<br>可以通过Internet访问远程数据。<br>只要你稍懂SQL,就可以在Excel Report 万能报表平台上设计报表。<br>通过设置字段,参数等信息来设计报表。<br>BI智能报表,支持透视表。<br>提供存储过程接口,便于用户二次开发。<br>有用户管理,报表权限的管理。<br>支持多语种。 <br>软件环境:<br> 客户端: Windows 2000及以上版本,Microsoft Office 2000及以上版本<br> 服务器端:Windows和Linux都可以,jsdk1.4,tomcat5<br> 数据库:支持Oracle, SQL Server 等数据库。<br>下载地址:<br> SQL Server SP3:<br>http://203.208.248.203:81/pan/Excel/sql2ksp3.exe<br>SQL Server SP4:<br>http://download.microsoft.com/download/9/b/f/9bff6646-2cdb-4069-ada0-548be9cb9338/SQL2000-KB884525-SP4-x86-CHS.EXE<br>报表安装包:<br>http://203.208.248.203:81/pan/Excel/j2sdk-1_4_2_06-windows-i586-p.exe<br>http://203.208.248.203:81/pan/Excel/jakarta-tomcat-5.0.27.exe<br><br><br>http://203.208.248.203:81/pan/Excel/Excel_Report_Setup.rar<br>联系方式:<br> http://pansoft.ik8.com<br> QQ: 10124900<br>MSN: bear_pan@hotmail.com<br>E_Mail: bear_pan@163.com<br><br><br>Excel Report Builder<br>Excel Report Builder is an easy and convenient tool for the creation and customization of reports which takes advantage of the formatting and presentation capabilities of Microsoft Excel. The program allows the rapid construction of reports.A GUI style design environment, which allows the user to design their reports visually inside MS Excel. Reports can be saved and then viewed and printed as pure Excel documents. <br>The reports are created and printed rapidly.In fact, it is by harnassing the power of Excel that gives Excel Report Builder these abilities.No technical knowledge is needed in order for the user to customise his or her own reports. <br><br>Key Features of the Database Report Builder for Excel include:<br> Report creation using Microsoft Excel<br> Get data through webservice,so you can get remote data <br> Support of the SQL-queries for the data sets creation<br> Calling of the stored procedures for the data sets creation<br> Creation of the reports with parameters<br> Work with the Microsoft Excel macros<br> Charts creation in a report<br><br>Software:<br> Client: Windows 2000 or above,Microsoft Office 2000 or above<br> Server: jsdk1.4,tomcat5<br> Database: Oracle or SQL Server <br>Download:<br>SQL Server SP3:<br>http://203.208.248.203:81/pan/Excel/sql2ksp3.exe<br>SQL Server SP4:<br>http://download.microsoft.com/download/9/b/f/9bff6646-2cdb-4069-ada0-548be9cb9338/SQL2000-KB884525-SP4-x86-CHS.EXE<br>Excel Report Builder:<br>http://203.208.248.203:81/pan/Excel/j2sdk-1_4_2_06-windows-i586-p.exe<br>http://203.208.248.203:81/pan/Excel/jakarta-tomcat-5.0.27.exe<br><br><br>http://203.208.248.203:81/pan/Excel/Excel_Report_Setup.rar<br><br><br>Contact:<br> http://pansoft.ik8.com <br> QQ: 10124900<br>MSN: bear_pan@hotmail.com<br>E_Mail: bear_pan@163.com<br><br>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值