org.apache.poi.ss.usermodel.WorkbookFactory.create()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(2343)

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

WorkbookFactory.create介绍

[英]Creates the appropriate HSSFWorkbook / XSSFWorkbook from the given File, which must exist and be readable.
[中]从给定文件创建相应的HSSFWorkbook/XSSF工作簿,该文件必须存在且可读。

代码示例

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

/**
 * Creates a Workbook from the given NPOIFSFileSystem.
 *
 * @param root The {@link DirectoryNode} to start reading the document from
 *
 * @return The created Workbook
 *
 * @throws IOException if an error occurs while reading the data
 */
public static Workbook create(final DirectoryNode root) throws IOException {
  return create(root, null);
}

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

try {
  fs = new POIFSFileSystem(file, readOnly);
  return create(fs, password);
} catch(OfficeXmlFileException e) {
  IOUtils.closeQuietly(fs);

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

/**
 * Creates a HSSFWorkbook from the given NPOIFSFileSystem<p>
 *
 * Note that in order to properly release resources the
 * Workbook should be closed after use.
 *
 * @param fs The {@link POIFSFileSystem} to read the document from
 *
 * @return The created workbook
 *
 * @throws IOException if an error occurs while reading the data
 */
public static Workbook create(POIFSFileSystem fs) throws IOException {
  return create(fs, null);
}

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

case OLE2:
  POIFSFileSystem fs = new POIFSFileSystem(is);
  return create(fs, password);
case OOXML:
  return createXSSFWorkbook(is);

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

/**
 * Creates the appropriate HSSFWorkbook / XSSFWorkbook from
 *  the given File, which must exist and be readable.
 * <p>Note that in order to properly release resources the
 *  Workbook should be closed after use.
 *
 *  @param file The file to read data from.
 *
 *  @return The created Workbook
 *
 *  @throws IOException if an error occurs while reading the data
 *  @throws EncryptedDocumentException If the Workbook given is password protected
 */
public static Workbook create(File file) throws IOException, EncryptedDocumentException {
  return create(file, null);
}

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

/**
 * Creates the appropriate HSSFWorkbook / XSSFWorkbook from
 *  the given File, which must exist and be readable, and
 *  may be password protected
 * <p>Note that in order to properly release resources the
 *  Workbook should be closed after use.
 *
 *  @param file The file to read data from.
 *  @param password The password that should be used or null if no password is necessary.
 *
 *  @return The created Workbook
 *
 *  @throws IOException if an error occurs while reading the data
 *  @throws EncryptedDocumentException If the wrong password is given for a protected file
 */
public static Workbook create(File file, String password) throws IOException, EncryptedDocumentException {
  return create(file, password, false);
}

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

/**
 * Creates the appropriate HSSFWorkbook / XSSFWorkbook from
 *  the given InputStream.
 *
 * <p>Your input stream MUST either support mark/reset, or
 *  be wrapped as a {@link BufferedInputStream}!
 *  Note that using an {@link InputStream} has a higher memory footprint
 *  than using a {@link File}.</p>
 *
 * <p>Note that in order to properly release resources the
 *  Workbook should be closed after use. Note also that loading
 *  from an InputStream requires more memory than loading
 *  from a File, so prefer {@link #create(File)} where possible.
 *
 *  @param inp The {@link InputStream} to read data from.
 *
 *  @return The created Workbook
 *
 *  @throws IOException if an error occurs while reading the data
 *  @throws EncryptedDocumentException If the Workbook given is password protected
 */
public static Workbook create(InputStream inp) throws IOException, EncryptedDocumentException {
  return create(inp, null);
}

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

public PoiWorkbook( InputStream inputStream, String encoding ) throws KettleException {
 this.encoding = encoding;
 try {
  workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( inputStream );
 } catch ( Exception e ) {
  throw new KettleException( e );
 }
}

代码示例来源:origin: looly/hutool

/**
 * 创建或加载工作簿,只读模式
 * 
 * @param excelFile Excel文件
 * @param password Excel工作簿密码,如果无密码传{@code null}
 * @return {@link Workbook}
 */
public static Workbook createBook(File excelFile, String password) {
  try {
    return WorkbookFactory.create(excelFile, password);
  } catch (Exception e) {
    throw new POIException(e);
  }
}

代码示例来源:origin: looly/hutool

/**
 * 创建或加载工作簿,只读模式
 * 
 * @param excelFile Excel文件
 * @param password Excel工作簿密码,如果无密码传{@code null}
 * @return {@link Workbook}
 */
public static Workbook createBook(File excelFile, String password) {
  try {
    return WorkbookFactory.create(excelFile, password);
  } catch (Exception e) {
    throw new POIException(e);
  }
}

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

/**
 * Creates a Workbook from the given NPOIFSFileSystem, which may
 *  be password protected
 *
 *  @param fs The {@link POIFSFileSystem} to read the document from
 *  @param password The password that should be used or null if no password is necessary.
 *
 *  @return The created Workbook
 *
 *  @throws IOException if an error occurs while reading the data
 */
private static Workbook create(final POIFSFileSystem fs, String password) throws IOException {
  return create(fs.getRoot(), password);
}

代码示例来源:origin: looly/hutool

/**
 * 创建或加载工作簿
 * 
 * @param in Excel输入流
 * @param password 密码
 * @param closeAfterRead 读取结束是否关闭流
 * @return {@link Workbook}
 * @since 4.0.3
 */
public static Workbook createBook(InputStream in, String password, boolean closeAfterRead) {
  try {
    return WorkbookFactory.create(IoUtil.toMarkSupportStream(in), password);
  } catch (Exception e) {
    throw new POIException(e);
  } finally {
    if (closeAfterRead) {
      IoUtil.close(in);
    }
  }
}

代码示例来源:origin: looly/hutool

/**
 * 创建或加载工作簿
 * 
 * @param in Excel输入流
 * @param password 密码
 * @param closeAfterRead 读取结束是否关闭流
 * @return {@link Workbook}
 * @since 4.0.3
 */
public static Workbook createBook(InputStream in, String password, boolean closeAfterRead) {
  try {
    return WorkbookFactory.create(IoUtil.toMarkSupportStream(in), password);
  } catch (Exception e) {
    throw new POIException(e);
  } finally {
    if (closeAfterRead) {
      IoUtil.close(in);
    }
  }
}

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

try {
 npoifs = new NPOIFSFileSystem( excelFile );
 workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( npoifs );
} catch ( Exception ofe ) {
 try {
  opcpkg = OPCPackage.open( excelFile );
  workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( opcpkg );
 } catch ( Exception ex ) {
  workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( excelFile, password );
workbook = org.apache.poi.ss.usermodel.WorkbookFactory.create( internalIS, password );

代码示例来源:origin: zstackio/zstack

public ExcelReader(String base64Content) {
  byte[] decoded = Base64.getDecoder().decode(base64Content);
  InputStream input = new ByteArrayInputStream(decoded);
  try {
    Workbook workbook = WorkbookFactory.create(input);
    if (workbook.getNumberOfSheets() == 0) {
      workbook.createSheet();
    }
    sheet = workbook.getSheetAt(0);
    header = sheet.getPhysicalNumberOfRows() == 0 ? null : readRow(0);
  } catch (IOException | InvalidFormatException e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Procedure("apoc.load.xls")
@Description("apoc.load.xls('url','selector',{config}) YIELD lineNo, list, map - load XLS fom URL as stream of row values,\n config contains any of: {skip:1,limit:5,header:false,ignore:['tmp'],arraySep:';',mapping:{years:{type:'int',arraySep:'-',array:false,name:'age',ignore:false, dateFormat:'iso_date', dateParse:['dd-MM-yyyy']}}")
public Stream<XLSResult> xls(@Name("url") String url, @Name("selector") String selector, @Name(value = "config",defaultValue = "{}") Map<String, Object> config) {
  boolean failOnError = booleanValue(config, "failOnError", true);
  try (CountingInputStream stream = FileUtils.inputStreamFor(url)) {
    Selection selection = new Selection(selector);
    char arraySep = separator(config, "arraySep", DEFAULT_ARRAY_SEP);
    long skip = longValue(config, "skip", 0L);
    boolean hasHeader = booleanValue(config, "header", true);
    long limit = longValue(config, "limit", Long.MAX_VALUE);
    List<String> ignore = value(config, "ignore", emptyList());
    List<Object> nullValues = value(config, "nullValues", emptyList());
    Map<String, Map<String, Object>> mapping = value(config, "mapping", Collections.emptyMap());
    Map<String, Mapping> mappings = createMapping(mapping, arraySep, ignore);
    Workbook workbook = WorkbookFactory.create(stream);
    Sheet sheet = workbook.getSheet(selection.sheet);
    if (sheet==null) throw new IllegalStateException("Sheet "+selection.sheet+" not found");
    selection.updateVertical(sheet.getFirstRowNum(),sheet.getLastRowNum());
    Row firstRow = sheet.getRow(selection.top);
    selection.updateHorizontal(firstRow.getFirstCellNum(), firstRow.getLastCellNum());
    String[] header = getHeader(hasHeader, firstRow,selection, ignore, mappings);
    boolean checkIgnore = !ignore.isEmpty() || mappings.values().stream().anyMatch( m -> m.ignore);
    return StreamSupport.stream(new XLSSpliterator(sheet, selection, header, url, skip, limit, checkIgnore,mappings, nullValues), false);
  } catch (Exception e) {
    if(!failOnError)
      return Stream.of(new  XLSResult(new String[0], new Object[0], 0, true, Collections.emptyMap(), emptyList()));
    else
      throw new RuntimeException("Can't read XLS from URL " + cleanUrl(url), e);
  }
}

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

/**
 * Creates a Workbook from the given NPOIFSFileSystem.
 *
 * @param root The {@link DirectoryNode} to start reading the document from
 *
 * @return The created Workbook
 *
 * @throws IOException if an error occurs while reading the data
 */
public static Workbook create(final DirectoryNode root) throws IOException {
  return create(root, null);
}

代码示例来源:origin: edu.stanford.protege/mapping-master

public static Workbook loadWorkbookFromDocument(String location) throws Exception
  {
   return WorkbookFactory.create(new FileInputStream(location));
  }
}

代码示例来源:origin: org.paxml/PaxmlCore

public static void main(String[] args) throws Exception {
  File file = new File("C:\\Users\\niuxuetao\\Downloads\\Untitled spreadsheet.xls");
  Workbook wb1 = WorkbookFactory.create(file);
  Workbook wb2 = WorkbookFactory.create(file);
  ReadExcelTag tag = new ReadExcelTag();
  tag.setValue(file.getAbsolutePath());
  tag.setRange("A2:C");
  tag.setSheet("Sheet1");
  tag.afterPropertiesInjection(null);
  Object result = tag.doInvoke(null);
  System.out.println(result);
}

代码示例来源:origin: usc-isi-i2/Web-Karma

private void openWorkbook(InputStream is) throws InvalidFormatException, IOException {
  
  this.workbook = WorkbookFactory.create(is);
  this.evaluator = this.workbook.getCreationHelper()
      .createFormulaEvaluator();
  this.formatter = new DataFormatter(true);
}

相关文章