本文整理汇总了Java中net.sf.jxls.transformer.XLSTransformer.transformXLS方法的典型用法代码示例。如果您正苦于以下问题:Java XLSTransformer.transformXLS方法的具体用法?Java XLSTransformer.transformXLS怎么用?Java XLSTransformer.transformXLS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.jxls.transformer.XLSTransformer
的用法示例。
在下文中一共展示了XLSTransformer.transformXLS方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
@Override
public void render() {
if (beans.isEmpty()) {
buildBean();
}
response.setContentType(CONTENT_TYPE);
response.setHeader("Content-Disposition", "attachment;Filename=" + filename);
try {
OutputStream out = response.getOutputStream();
InputStream is = new BufferedInputStream(new FileInputStream(templetFile));
XLSTransformer transformer = new XLSTransformer();
Workbook workBook = transformer.transformXLS(is, beans);
workBook.write(out);
} catch (Exception e) {
throw new RenderException(e);
}
}
示例2: downloadReport
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
/**
* Gera um relatório com o nome e manifestações informados e efetua o download
*
* @param reportName Nome do relatório a ser gerado
* @param manifestacoes Lista de manifestações a serem exportadas para o relatório
* @throws Exception Caso aconteça qualquer tipo de exceção ao tentar gerar e baixar o relatório
*/
public static void downloadReport(String reportName, List<TbManifestacao> manifestacoes) throws Exception {
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.setContentType("application/force-download");
response.addHeader("Content-Disposition", String.format("attachment; filename=\"%s.xls\"", reportName));
// Converte a lista em um arquivo .xls
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream templateFile = classLoader.getResourceAsStream("/TemplateExtracaoDados.xls");
Map<String, List<ManifestacaoVO>> beans = new HashMap<String, List<ManifestacaoVO>>();
beans.put("data", ExtracaoHelper.convert(manifestacoes));
XLSTransformer transformer = new XLSTransformer();
Workbook workbook = transformer.transformXLS(templateFile, beans);
workbook.write(response.getOutputStream());
facesContext.responseComplete();
}
示例3: render
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
@Override
public void render() {
if (beans.isEmpty()) {
buildBean();
}
response.setContentType(CONTENT_TYPE);
response.setHeader("Content-Disposition",
"attachment;Filename=" + encodeChineseDownloadFileName(request, filename));
try {
OutputStream out = response.getOutputStream();
InputStream is = new BufferedInputStream(new FileInputStream(templetFile));
XLSTransformer transformer = new XLSTransformer();
Workbook workBook = transformer.transformXLS(is, beans);
workBook.write(out);
} catch (Exception e) {
throw new RenderException(e);
}
}
示例4: executeReport
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
protected Workbook executeReport() throws Exception {
if (template.getContent() != null) {
try (InputStream is = new ByteArrayInputStream(template.getContent())) {
XLSTransformer transformer = new XLSTransformer();
transformer.registerRowProcessor(new ExcelRowProcessor());
generateDataNamedMap(transformer);
if (template.getFixed() != null) {
int length = JSType.toInteger(template.getFixed().getMember("length"));
for (int i = 0; i < length; i++) {
transformer.markAsFixedSizeCollection(JSType.toString(template.getFixed().getSlot(i)));
}
}
return transformer.transformXLS(is, generated);
}
} else {
throw new Exception("Report template is absent.");
}
}
示例5: exportXls
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
@Override
public void exportXls(String schemaName, String mode) throws Exception {
String templateFileName = String.format("table-schema-%s.xls", mode);
String destFileName = String.format("%s-%s.xls",schemaName, mode);
List<Table> tableList = this.findAll(schemaName);
for (Table table : tableList){
List<Column> columns = this.findAllColumns(schemaName, table.getTable_name());
table.setColumnList(columns);
}
InputStream is = getClass().getClassLoader().getResourceAsStream(templateFileName);
Map beans = new HashMap();
beans.put("tables", tableList);
XLSTransformer transformer = new XLSTransformer();
org.apache.poi.ss.usermodel.Workbook workbook = transformer.transformXLS(is, beans);
OutputStream os = new BufferedOutputStream(new FileOutputStream(destFileName));
workbook.write(os);
is.close();
os.flush();
os.close();
}
示例6: downLoad
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
/**
* excel 下载
*/
@RequestMapping(value = "downLoad")
public void downLoad(HttpServletRequest request, HttpServletResponse response) throws Exception {
Workbook wb = null;
try {
logger.info(">>>>>>>>ReportViewController.downLoad start>>");
//=======================================数据
List<Map<String,Object>> datas = Lists.newArrayList();
Map<String,Object> data0 = Maps.newHashMap();
data0.put("date", "2017-01-01");
data0.put("date1", "2017-01-01");
Map<String,Object> data1 = Maps.newHashMap();
data1.put("shoujidai","100");
data1.put("daxuedai","100");
data1.put("zirandai","100");
data0.put("zidonghebishu",data1);
datas.add(data0);
//==========================================
//设置excel模板
Map<String, Object> templateParams = Maps.newHashMap();
XLSTransformer transformer = new XLSTransformer();
wb = transformer.transformXLS(App.class.getResourceAsStream("/xls/excel.xlsx"), templateParams);
Sheet billInfoSheet = wb.getSheet("sheet1");
//设置excel展示配置
ExcelExportSetting excelExportSetting = new ExcelExportSetting();
List<PoiCell> cellList = Lists.newArrayList();
//一行数据的第一列
cellList.add(new ExcelMergeCell("日期","date"));
cellList.add(new ExcelMergeCell("日期1","date1"));
//一行数据的第二个列合并单元格的
ExcelMergeCell excelMergeCell = new ExcelMergeCell("自动电核笔数","zidonghebishu",
Arrays.asList(new ExcelCell("大学贷","daxuedai"),
new ExcelCell("手机贷","shoujidai"),
new ExcelCell("自然贷","zirandai")));
cellList.add(excelMergeCell);
excelExportSetting.setHeaderRow(cellList);//设置表头
excelExportSetting.setDataList(datas);//设置数据
//写入excel
ExcelPoiHelp.poiWrite(wb, billInfoSheet, excelExportSetting);
//写入response
String outFile = "outputFile.xls";
response.reset();
response.addHeader("Content-Disposition", "attachment;filename="+ new String(outFile.getBytes()));
OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/vnd.ms-excel;charset=utf-8");
wb.write(toClient);
} catch (Exception e) {
e.printStackTrace();
} finally {
wb.close();
}
}
示例7: exportRoundAsXLS
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
public static File exportRoundAsXLS(Round round) throws Exception {
File file = new File("/round"+round.roundNumber+".xls");
Map<String , List<Game>> games = new HashMap<String, List<Game>>();
games.put("games", round.games);
XLSTransformer transformer = new XLSTransformer();
transformer.transformXLS(getXlsTemplatePath(), games, file.getPath());
return file;
}
示例8: testUseTemplate2
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
/**
* [Flow #-7-1] 공통 템플릿 사용 : 공통 템플릿을 사용하여 일관성을 유지함
* jXLS 사용
*/
@Test
public void testUseTemplate2() throws Exception {
StringBuffer sb = new StringBuffer();
StringBuffer sbResult = new StringBuffer();
sb.append(fileLocation).append("/template/").append("template2.xls");
sbResult.append(fileLocation).append("/").append("testUseTemplate2.xls");
try {
// 출력할 객체를 만든다.
List<PersonHourVO> persons = new ArrayList<PersonHourVO>();
PersonHourVO person = new PersonHourVO();
person.setName("Yegor Kozlov");
person.setId("YK");
person.setMon(5.0);
person.setTue(8.0);
person.setWed(10.0);
person.setThu(5.0);
person.setFri(5.0);
person.setSat(7.0);
person.setSun(6.0);
persons.add(person);
PersonHourVO person1 = new PersonHourVO();
person1.setName("Gisella Bronzetti");
person1.setId("GB");
person1.setMon(4.0);
person1.setTue(3.0);
person1.setWed(1.0);
person1.setThu(3.5);
person1.setSun(4.0);
persons.add(person1);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put("persons", persons);
XLSTransformer transformer = new XLSTransformer();
transformer.transformXLS(sb.toString(), beans, sbResult.toString());
//////////////////////////////////////////////////////////////////////////
// 검증
HSSFWorkbook wb = excelService.loadWorkbook(sbResult.toString());
HSSFSheet sheet = wb.getSheetAt(0);
Double[][] value = {
{5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},
{4.0, 3.0, 1.0, 3.5, null, null, 4.0}
};
for (int i = 0; i < 2; i++) {
HSSFRow row2 = sheet.getRow(i + 2);
for (int j = 0; j < 7; j++) {
HSSFCell cellValue = row2.getCell((j + 2));
if (cellValue.getCellType() == HSSFCell.CELL_TYPE_BLANK) continue;
log.debug("cellTot.getNumericCellValue() : " + cellValue.getNumericCellValue());
assertEquals(value[i][j], Double.valueOf(cellValue.getNumericCellValue()));
}
}
} catch (Exception e) {
log.error(e.toString());
throw new Exception(e);
} finally {
log.debug("testUseTemplate end....");
}
}
示例9: testUseTemplate2
import net.sf.jxls.transformer.XLSTransformer; //导入方法依赖的package包/类
/**
* [Flow #-7-1] 공통 템플릿 사용 : 공통 템플릿을 사용하여 일관성을 유지함
* jXLS 사용
*/
@Test
public void testUseTemplate2() throws Exception {
StringBuffer sb = new StringBuffer();
StringBuffer sbResult = new StringBuffer();
sb.append(fileLocation).append("/template/").append("template2.xlsx");
sbResult.append(fileLocation).append("/").append("testUseTemplate2.xlsx");
try {
// 출력할 객체를 만든다.
List<PersonHourVO> persons = new ArrayList<PersonHourVO>();
PersonHourVO person = new PersonHourVO();
person.setName("Yegor Kozlov");
person.setId("YK");
person.setMon(5.0);
person.setTue(8.0);
person.setWed(10.0);
person.setThu(5.0);
person.setFri(5.0);
person.setSat(7.0);
person.setSun(6.0);
persons.add(person);
PersonHourVO person1 = new PersonHourVO();
person1.setName("Gisella Bronzetti");
person1.setId("GB");
person1.setMon(4.0);
person1.setTue(3.0);
person1.setWed(1.0);
person1.setThu(3.5);
person1.setSun(4.0);
persons.add(person1);
Map<String, Object> beans = new HashMap<String, Object>();
beans.put("persons", persons);
XLSTransformer transformer = new XLSTransformer();
transformer.transformXLS(sb.toString(), beans, sbResult.toString());
//////////////////////////////////////////////////////////////////////////
// 검증
XSSFWorkbook wb = excelService.loadXSSFWorkbook(sbResult.toString());
XSSFSheet sheet = wb.getSheetAt(0);
Double[][] value = {
{5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},
{4.0, 3.0, 1.0, 3.5, null, null, 4.0}
};
for (int i = 0; i < 2; i++) {
XSSFRow row2 = sheet.getRow(i + 2);
for (int j = 0; j < 7; j++) {
XSSFCell cellValue = row2.getCell((j + 2));
if (cellValue.getCellType() == HSSFCell.CELL_TYPE_BLANK) continue;
log.debug("cellTot.getNumericCellValue() : " + cellValue.getNumericCellValue());
assertEquals(value[i][j], Double.valueOf(cellValue.getNumericCellValue()));
}
}
} catch (Exception e) {
log.error(e.toString());
throw new Exception(e);
} finally {
log.debug("testUseTemplate end....");
}
}