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

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

本文整理了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

System.out.print("reading " + filename + "...");
FileInputStream is = new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(is);
try {
  System.out.println("done");
    String outputFile = filename.replace(".xls", "-saved.xls");
    System.out.print("saving to " + outputFile + "...");
    os = new FileOutputStream(outputFile);
    wb.write(os);
  } finally {
    os.close();

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

private HSSFWorkbook createWorkbook( FileObject file ) throws Exception {
 HSSFWorkbook wb = null;
 OutputStream os = null;
 try {
  os = file.getContent().getOutputStream();
  wb = new HSSFWorkbook();
  wb.createSheet( SHEET_NAME );
  wb.write( os );
 } finally {
  os.flush();
  os.close();
 }
 return wb;
}

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

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet realSheet = workbook.createSheet("Sheet xls");
HSSFSheet hidden = workbook.createSheet("hidden");
for (int i = 0, length= countryName.length; i < length; i++) {
  String name = countryName[i];
  HSSFRow row = hidden.createRow(i);
  HSSFCell cell = row.createCell(0);
  cell.setCellValue(name);
 }
 Name namedCell = workbook.createName();
 namedCell.setNameName("hidden");
 namedCell.setRefersToFormula("hidden!$A$1:$A$" + countryName.length);
 DVConstraint constraint = DVConstraint.createFormulaListConstraint("hidden");
 CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0);
 HSSFDataValidation validation = new HSSFDataValidation(addressList, constraint);
 workbook.setSheetHidden(1, true);
 realSheet.addValidationData(validation);
 FileOutputStream stream = new FileOutputStream("c:\\range.xls");
 workbook.write(stream);
 stream.close();

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

/**
 * Save the generated worksheet to a file 
 * 
 * @param file to save to
 * @throws FileNotFoundException
 * @throws IOException
 */
void saveSheet(File file) throws IOException {
    FileOutputStream fos = new FileOutputStream(file);
    wb.write(fos);
    fos.close();
}

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

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

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

try {           
   FileInputStream fileInput = new FileInputStream("sample.xls");         
   BufferedInputStream bufferInput = new BufferedInputStream(fileInput);            
   POIFSFileSystem poiFileSystem = new POIFSFileSystem(bufferInput);            
   Biff8EncryptionKey.setCurrentUserPassword("password");            
   HSSFWorkbook workbook = new HSSFWorkbook(poiFileSystem, true);            
   HSSFSheet sheet = workbook.getSheetAt(0);           
   HSSFRow row = sheet.createRow(0);
   Cell cell = row.createCell(0);
   cell.setCellValue("Hello World"); 
   FileOutputStream fileOut = new FileOutputStream(fname);
   workbook.writeProtectWorkbook(Biff8EncryptionKey.getCurrentUserPassword(), "");
   workbook.write(fileOut);
 } catch (Exception ex) {
 }

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

public void exportAndClose()
{
 try
 {
   workbook.write(fileOutputStream);
   fileOutputStream.close();
 }
 catch (IOException e)
 {
   e.printStackTrace();
 }
}

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

HSSFWorkbook hwb = new HSSFWorkbook();
...
OutputStream outStream = response.getOutputStream();
hwb.write(outputStream);
....

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

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

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

/**
   * Save the generated worksheet to a file 
   * 
   * @param file to save to
   * @throws FileNotFoundException
   * @throws IOException
   */
  void saveSheet(File file) throws FileNotFoundException, IOException {
    FileOutputStream fos = new FileOutputStream(file);
    wb.write(fos);
    fos.close();
  }
}

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

public static void main(String[] args) throws IOException {
    try (HSSFWorkbook wb = new HSSFWorkbook()) {
      try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {
        wb.write(fileOut);
      }
    }
  }
}

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

/**
 * Write to.
 *
 * @param file
 *            File
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void writeTo(final File file) throws IOException {
  final OutputStream fout = new FileOutputStream(file);
  this.workbook.write(fout);
  fout.close();
}

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

public void exportAndClose()
{
 try
 {
   workbook.write(fileOutputStream);
   fileOutputStream.close();
 }
 catch (IOException e)
 {
   e.printStackTrace();
 }
}

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

public void getReportData() throws IOException {
  HSSFWorkbook workbook = new HSSFWorkbook();
  HSSFSheet sheet = workbook.createSheet();
  HSSFRow row = sheet.createRow(0);
  HSSFCell cell = row.createCell(0);
  cell.setCellValue(0.0);

  FacesContext facesContext = FacesContext.getCurrentInstance();
  ExternalContext externalContext = facesContext.getExternalContext();
  externalContext.setResponseContentType("application/vnd.ms-excel");
  externalContext.setResponseHeader("Content-Disposition", "attachment; filename=\"my.xls\"");

  workbook.write(externalContext.getResponseOutputStream());
  facesContext.responseComplete();
}

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

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

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

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = row.createCell((short) 0);
FileOutputStream out = new FileOutputStream("default_palette.xls");
wb.write(out);
out.close();
out = new FileOutputStream("modified_palette.xls");
wb.write(out);
out.close();

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

HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(InputStream);

FileOutputStream fileOut = new FileOutputStream("/outputfilepath.xls");
embeddedWorkbook.write(fileOut);
fileOut.close();

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

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

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

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

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

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

相关文章

微信公众号

最新文章

更多

HSSFWorkbook类方法