org.apache.poi.hssf.usermodel.HSSFWorkbook.write()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(603)

本文整理了Java中org.apache.poi.hssf.usermodel.HSSFWorkbook.write()方法的一些代码示例,展示了HSSFWorkbook.write()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFWorkbook.write()方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFWorkbook
类名称:HSSFWorkbook
方法名:write

HSSFWorkbook.write介绍

[英]Write out this workbook to the currently open File via the writeable POIFSFileSystem it was opened as.

This will fail (with an IllegalStateException if the Workbook was opened read-only, opened from an InputStreaminstead of a File, or if this is not the root document. For those cases, you must use #write(OutputStream) or #write(File) to write to a brand new document.
[中]通过可写POIFSFS文件系统将此工作簿写入当前打开的文件。
如果工作簿是以只读方式打开的、从InputStream而不是文件打开的,或者这不是根文档,则此操作将失败(存在非法状态异常)。对于这些情况,必须使用#write(OutputStream)或#write(File)写入全新文档。

代码示例

代码示例来源:origin: org.apache.poi/poi

  1. System.out.print("reading " + filename + "...");
  2. FileInputStream is = new FileInputStream(filename);
  3. HSSFWorkbook wb = new HSSFWorkbook(is);
  4. try {
  5. System.out.println("done");
  6. String outputFile = filename.replace(".xls", "-saved.xls");
  7. System.out.print("saving to " + outputFile + "...");
  8. os = new FileOutputStream(outputFile);
  9. wb.write(os);
  10. } finally {
  11. os.close();

代码示例来源:origin: pentaho/pentaho-kettle

  1. private HSSFWorkbook createWorkbook( FileObject file ) throws Exception {
  2. HSSFWorkbook wb = null;
  3. OutputStream os = null;
  4. try {
  5. os = file.getContent().getOutputStream();
  6. wb = new HSSFWorkbook();
  7. wb.createSheet( SHEET_NAME );
  8. wb.write( os );
  9. } finally {
  10. os.flush();
  11. os.close();
  12. }
  13. return wb;
  14. }

代码示例来源:origin: stackoverflow.com

  1. HSSFWorkbook workbook = new HSSFWorkbook();
  2. HSSFSheet realSheet = workbook.createSheet("Sheet xls");
  3. HSSFSheet hidden = workbook.createSheet("hidden");
  4. for (int i = 0, length= countryName.length; i < length; i++) {
  5. String name = countryName[i];
  6. HSSFRow row = hidden.createRow(i);
  7. HSSFCell cell = row.createCell(0);
  8. cell.setCellValue(name);
  9. }
  10. Name namedCell = workbook.createName();
  11. namedCell.setNameName("hidden");
  12. namedCell.setRefersToFormula("hidden!$A$1:$A$" + countryName.length);
  13. DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden");
  14. CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
  15. HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint);
  16. workbook.setSheetHidden(1, true);
  17. realSheet.addValidationData(validation);
  18. FileOutputStream stream = new FileOutputStream("c:\\range.xls");
  19. workbook.write(stream);
  20. stream.close();

代码示例来源:origin: net.sf.taverna.t2.ui-components/results-view

  1. /**
  2. * Save the generated worksheet to a file
  3. *
  4. * @param file to save to
  5. * @throws FileNotFoundException
  6. * @throws IOException
  7. */
  8. void saveSheet(File file) throws IOException {
  9. FileOutputStream fos = new FileOutputStream(file);
  10. wb.write(fos);
  11. fos.close();
  12. }

代码示例来源:origin: org.apache.poi/poi-examples

  1. public void writeOut(String filename) throws IOException {
  2. try (FileOutputStream fileOut = new FileOutputStream(filename)) {
  3. wb.write(fileOut);
  4. }
  5. }

代码示例来源:origin: stackoverflow.com

  1. try {
  2. FileInputStream fileInput = new FileInputStream("sample.xls");
  3. BufferedInputStream bufferInput = new BufferedInputStream(fileInput);
  4. POIFSFileSystem poiFileSystem = new POIFSFileSystem(bufferInput);
  5. Biff8EncryptionKey.setCurrentUserPassword("password");
  6. HSSFWorkbook workbook = new HSSFWorkbook(poiFileSystem, true);
  7. HSSFSheet sheet = workbook.getSheetAt(0);
  8. HSSFRow row = sheet.createRow(0);
  9. Cell cell = row.createCell(0);
  10. cell.setCellValue("Hello World");
  11. FileOutputStream fileOut = new FileOutputStream(fname);
  12. workbook.writeProtectWorkbook(Biff8EncryptionKey.getCurrentUserPassword(), "");
  13. workbook.write(fileOut);
  14. } catch (Exception ex) {
  15. }

代码示例来源:origin: us.ihmc/ihmc-avatar-interfaces

  1. public void exportAndClose()
  2. {
  3. try
  4. {
  5. workbook.write(fileOutputStream);
  6. fileOutputStream.close();
  7. }
  8. catch (IOException e)
  9. {
  10. e.printStackTrace();
  11. }
  12. }

代码示例来源:origin: stackoverflow.com

  1. HSSFWorkbook hwb = new HSSFWorkbook();
  2. ...
  3. OutputStream outStream = response.getOutputStream();
  4. hwb.write(outputStream);
  5. ....

代码示例来源:origin: stackoverflow.com

  1. try {
  2. String filename = "C:/NewExcelFile.xls" ;
  3. HSSFWorkbook workbook = new HSSFWorkbook();
  4. HSSFSheet sheet = workbook.createSheet("FirstSheet");
  5. row.createCell(3).setCellValue("sankumarsingh@gmail.com");
  6. FileOutputStream fileOut = new FileOutputStream(filename);
  7. workbook.write(fileOut);
  8. fileOut.close();
  9. System.out.println("Your excel file has been generated!");

代码示例来源:origin: uk.org.mygrid.taverna.scufl/scufl-ui

  1. /**
  2. * Save the generated worksheet to a file
  3. *
  4. * @param file to save to
  5. * @throws FileNotFoundException
  6. * @throws IOException
  7. */
  8. void saveSheet(File file) throws FileNotFoundException, IOException {
  9. FileOutputStream fos = new FileOutputStream(file);
  10. wb.write(fos);
  11. fos.close();
  12. }
  13. }

代码示例来源:origin: org.apache.poi/poi-examples

  1. public static void main(String[] args) throws IOException {
  2. try (HSSFWorkbook wb = new HSSFWorkbook()) {
  3. try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {
  4. wb.write(fileOut);
  5. }
  6. }
  7. }
  8. }

代码示例来源:origin: com.jalalkiswani/jk-util

  1. /**
  2. * Write to.
  3. *
  4. * @param file
  5. * File
  6. * @throws IOException
  7. * Signals that an I/O exception has occurred.
  8. */
  9. public void writeTo(final File file) throws IOException {
  10. final OutputStream fout = new FileOutputStream(file);
  11. this.workbook.write(fout);
  12. fout.close();
  13. }

代码示例来源:origin: us.ihmc/DarpaRoboticsChallenge

  1. public void exportAndClose()
  2. {
  3. try
  4. {
  5. workbook.write(fileOutputStream);
  6. fileOutputStream.close();
  7. }
  8. catch (IOException e)
  9. {
  10. e.printStackTrace();
  11. }
  12. }

代码示例来源:origin: stackoverflow.com

  1. public void getReportData() throws IOException {
  2. HSSFWorkbook workbook = new HSSFWorkbook();
  3. HSSFSheet sheet = workbook.createSheet();
  4. HSSFRow row = sheet.createRow(0);
  5. HSSFCell cell = row.createCell(0);
  6. cell.setCellValue(0.0);
  7. FacesContext facesContext = FacesContext.getCurrentInstance();
  8. ExternalContext externalContext = facesContext.getExternalContext();
  9. externalContext.setResponseContentType("application/vnd.ms-excel");
  10. externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"my.xls\"");
  11. workbook.write(externalContext.getResponseOutputStream());
  12. facesContext.responseComplete();
  13. }

代码示例来源:origin: youseries/ureport

  1. private void doProduce(Report report, OutputStream outputStream,boolean withPaging,boolean withSheet) {
  2. CellStyleContext cellStyleContext=new CellStyleContext();
  3. HSSFWorkbook wb = new HSSFWorkbook();
  4. CreationHelper creationHelper=wb.getCreationHelper();
  5. Paper paper=report.getPaper();
  6. wb.write(outputStream);
  7. }catch(Exception ex){
  8. throw new ReportComputeException(ex);

代码示例来源:origin: stackoverflow.com

  1. HSSFWorkbook wb = new HSSFWorkbook();
  2. HSSFSheet sheet = wb.createSheet();
  3. HSSFRow row = sheet.createRow((short) 0);
  4. HSSFCell cell = row.createCell((short) 0);
  5. FileOutputStream out = new FileOutputStream("default_palette.xls");
  6. wb.write(out);
  7. out.close();
  8. out = new FileOutputStream("modified_palette.xls");
  9. wb.write(out);
  10. out.close();

代码示例来源:origin: stackoverflow.com

  1. HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(InputStream);
  2. FileOutputStream fileOut = new FileOutputStream("/outputfilepath.xls");
  3. embeddedWorkbook.write(fileOut);
  4. fileOut.close();

代码示例来源:origin: stackoverflow.com

  1. public static void main(String[] args) throws Exception {
  2. try (FileInputStream fis = new FileInputStream("./report_template.xls");
  3. FileOutputStream fos = new FileOutputStream("./dump.xls")) {
  4. HSSFWorkbook wb = new HSSFWorkbook(fis);
  5. wb.write(fos);
  6. }
  7. }

代码示例来源:origin: stackoverflow.com

  1. // Both HSSFWorkbook that is event based, and NPOIFSFileSystem that uses nio should use less memory
  2. HSSFWorkbook wb = WorkbookFactory.create(new NPOIFSFileSystem(new FileInputStream(pathToInputFile)));
  3. CellStyle[] cellStyles = createColorStyles(fd_files, Workbook wb);
  4. //...
  5. wb.write(new FileOutputStream(pathToOutputFile));

代码示例来源:origin: stackoverflow.com

  1. HSSFWorkbook hwb=new HSSFWorkbook();
  2. HSSFSheet sheet = hwb.createSheet("new sheet");
  3. hwb.write(baos);
  4. excelStream = new ByteArrayInputStream(baos.toByteArray());

相关文章

HSSFWorkbook类方法