本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.write方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFWorkbook.write方法的具体用法?Java HSSFWorkbook.write怎么用?Java HSSFWorkbook.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFWorkbook
的用法示例。
在下文中一共展示了HSSFWorkbook.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
HSSFWorkbook workbook = createWorkbook();
byte[] buffer;
try (ByteArrayOutputStream stream = new ByteArrayOutputStream(1024)) {
workbook.write(stream);
stream.flush();
buffer = stream.toByteArray();
}
Map<String, BoundaryPoint> boundaryPoints;
try (InputStream stream = new ByteArrayInputStream(buffer)) {
BoundaryPointXlsParser parser = new BoundaryPointXlsParser();
boundaryPoints = parser.parse(stream);
}
assertEquals(1, boundaryPoints.size());
BoundaryPoint point = boundaryPoints.get("BoundaryPoint FR-BE");
assertNotNull(point);
assertEquals("BoundaryPoint FR-BE", point.getName());
assertEquals(Country.FR, point.getBorderFrom());
assertEquals(Country.BE, point.getBorderTo());
}
示例2: writeXLSFile
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static void writeXLSFile() throws IOException {
HSSFWorkbook wbObj = new HSSFWorkbook();
HSSFSheet sheet = wbObj.createSheet(sheetName);
for (int row = 0; row < tableData.size(); row++) {
HSSFRow rowObj = sheet.createRow(row);
rowData = tableData.get(row);
for (int col = 0; col < rowData.size(); col++) {
HSSFCell cellObj = rowObj.createCell(col);
cellObj.setCellValue(rowData.get(col));
}
}
FileOutputStream fileOut = new FileOutputStream(excelFileName);
wbObj.write(fileOut);
wbObj.close();
fileOut.flush();
fileOut.close();
}
示例3: doGet
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
List<PollOption> results = null;
try {
Long pollId = (Long) req.getSession().getAttribute("pollID");
results = DAOProvider.getDao().getPollOptions(pollId);
} catch (Exception ex) {
results = new ArrayList<>();
}
HSSFWorkbook workbook = DBUtility.getXLS(results);
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition",
"attachment; filename=votingResults.xls");
workbook.write(resp.getOutputStream());
workbook.close();
}
示例4: doGet
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String definitionFile = req.getServletContext().getRealPath(
"/WEB-INF/glasanje-definicija.txt");
String resultFile = req.getServletContext().getRealPath(
"/WEB-INF/glasanje-rezultati.txt");
List<Band> results = ServerUtilty
.getResults(definitionFile, resultFile);
HSSFWorkbook workbook = ServerUtilty.getXLS(results);
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition",
"attachment; filename=votingResults.xls");
workbook.write(resp.getOutputStream());
workbook.close();
}
示例5: exportTables
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
private void exportTables(List<String> tables, final String fileName) throws Exception {
workbook = new HSSFWorkbook();
for (int i = 0; i < tables.size(); i++) {
if (!tables.get(i).equals("android_metadata")) {
HSSFSheet sheet = workbook.createSheet(tables.get(i));
createSheet(tables.get(i), sheet);
}
}
File file = new File(mExportPath, fileName);
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
fos.flush();
fos.close();
workbook.close();
database.close();
}
示例6: createExcel
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/** エクセル出力 */
@Execute(validator = false)
public String createExcel(){
ExcelDto dto = new ExcelDto();
dto.setMeetingName(partyDto.meetingName);
dto.setMemberList(partyDto.tMemberOn);
HSSFWorkbook wb = excelFpao.excelTemplate(dto);
httpServletResponse.setHeader(
"Content-Disposition",
"attachment; filename=" + partyDto.meetingName + System.currentTimeMillis() + ".xls");
try {
OutputStream out = httpServletResponse.getOutputStream();
wb.write(out);
out.close();
} catch (IOException e) {}
return null;
}
示例7: createExcel
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/** エクセル出力 */
@Execute(validator = false)
public String createExcel(){
ExcelDto dto = new ExcelDto();
dto.setMeetingName(partyDto.meetingName);
dto.setMemberList(partyDto.tMemberOn);
HSSFWorkbook wb = excelFpao.excelTemplate(dto);
httpServletResponse.setHeader(
"Content-Disposition",
"attachment; filename=" + partyDto.meetingName + System.currentTimeMillis() + ".xls");
try {
OutputStream out = httpServletResponse.getOutputStream();
wb.write(out);
out.close();
} catch (IOException e) {}
return null;
}
示例8: createExcel
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* 创建文件
* @param response
* @param workbook
* @param fileName
* @return boolean
* @throws Exception
*/
public static boolean createExcel(HttpServletResponse response,
HSSFWorkbook workbook, String fileName) throws Exception {
boolean flag = false;
try {
response.reset();
response.setHeader("Content-Disposition", "attachment;filename="
+ new String(fileName.getBytes(), "iso8859-1"));
ServletOutputStream out = response.getOutputStream();
workbook.write(out);
// 弹出下载对话框
out.flush();
out.close();
flag = true;
} catch (Exception e) {
logger.error(fileName + " :文件创建失败");
throw e;
}
return flag;
}
示例9: writeExcelFile
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static void writeExcelFile(File excelFile, HSSFWorkbook workbook)
throws Exception {
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
fos = new FileOutputStream(excelFile);
bos = new BufferedOutputStream(fos);
workbook.write(bos);
} catch (FileNotFoundException e) {
throw new InputException(e);
} finally {
if (bos != null) {
bos.close();
}
if (fos != null) {
fos.close();
}
}
}
示例10: write
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public void write(String src) throws IOException{
System.out.println(src);
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Resultats");
for (int i=0; i<size(); i++) {
HSSFRow row = sheet.createRow(i);
HSSFCell cell = row.createCell(0);
cell.setCellValue(get(i).area());
}
FileOutputStream fileOut;
fileOut = new FileOutputStream(src);
wb.write(fileOut);
fileOut.close();
}
示例11: createExcel
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
private void createExcel(OutputStream out, IDocument doc, WebInput wi)
throws IOException, ServletException {
this.setContentType("application/vnd.ms-excel");
HSSFWorkbook wb = new HSSFWorkbook();
DocInfo di = new DocInfo(IDocument.TYPE_MS_EXCEL);
try {
di.setExcelDocument(wb);
doc.createContent(wi, di);
wb.write(out);
} catch (Exception e) {
throw new ServletException(e);
} finally {
if (out != null) {
out.flush();
out.close();
out = null;
}
di = null;
doc = null;
wb = null;
}
}
示例12: writeExcelFile
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
public static void writeExcelFile(final File excelFile, final HSSFWorkbook workbook) throws Exception {
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
fos = new FileOutputStream(excelFile);
bos = new BufferedOutputStream(fos);
workbook.write(bos);
} catch (final FileNotFoundException e) {
throw new InputException(e);
} finally {
if (bos != null) {
bos.close();
}
if (fos != null) {
fos.close();
}
}
}
示例13: createExcel
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* 创建文件
* @param response
* @param workbook
* @param fileName
* @return boolean
* @throws Exception
*/
public static FileTransfer createExcel(HttpServletResponse response,
HSSFWorkbook workbook, String fileName) throws Exception {
boolean flag = false;
try {
response.reset();
response.setHeader("Content-Disposition", "attachment;filename="
+ new String(fileName.getBytes(), "iso8859-1"));
//ServletOutputStream out = response.getOutputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
workbook.write(buffer);
return new FileTransfer(fileName, "application/vnd.ms-excel", buffer.toByteArray());
// 弹出下载对话框
//out.flush();
//out.close();
//flag = true;
} catch (Exception e) {
logger.error(fileName + " :文件创建失败");
throw e;
}
//return flag;
}
示例14: exportInnertion
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
@Override
public void exportInnertion(OutputStream servletOut, List header,
List data) throws IOException {
if (header == null || header.isEmpty()) {
return;
}
HSSFWorkbook workbook = ExcelUtil.export(header, data);
workbook.write(servletOut);
}
示例15: doGet
import org.apache.poi.hssf.usermodel.HSSFWorkbook; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Integer a = null;
Integer b = null;
Integer n = null;
try {
a = Integer.valueOf(req.getParameter("a"));
b = Integer.valueOf(req.getParameter("b"));
n = Integer.valueOf(req.getParameter("n"));
} catch (Exception ex) {
req.getRequestDispatcher("/WEB-INF/pages/error.jsp").forward(req,
resp);
return;
}
if (!isValid(a) || !isValid(b) || n < 1 || n > 5) {
req.getRequestDispatcher("/WEB-INF/pages/error.jsp").forward(req,
resp);
return;
}
HSSFWorkbook workbook = getXLS(a, b, n);
resp.setContentType("application/vnd.ms-excel");
resp.setHeader("Content-Disposition", "attachment; filename=powers.xls");
workbook.write(resp.getOutputStream());
workbook.close();
}