Tag: apache poi

使用apache poi读取excel – Hashmap,ArrayList

嗨, 我想在Excel中使用列标题(使用Java)读取列值。 如图所示,假设我想要读取标题“城市”,列下的所有后续单元格,并显示它们。 我将如何做到这一点? 通过互联网看的例子,我发现大部分的例子迭代使用迭代器的行。 假设我有一个key的hashmap作为excel的头文件和后来的值存储在ArrayList中。 就像是 HashMap<String, ArrayList<String>> hashmap = new HashMap<String, ArrayList<String>>(); 我应该如何继续? 任何人都可以帮助我的代码和逻辑? 请不要将其标记为重复,我已经尝试过在stackoverflow和internet上search,但是其中大多数使用该行进行迭代。

在TomCat上运行的POI导致加载程序约束违规

我正在尝试使用Apache POI生成XSLX,但在尝试运行TomCat应用程序时出现此错误: HTTP Status 500 – javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving interface method "org.openxmlformats.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.copy()Lorg/apache/xmlbeans/XmlObject;" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/apache/poi/POIXMLProperties, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/openxmlformats/schemas/officeDocument/x2006/extendedProperties/PropertiesDocument, have different Class objects for the type ts.schemas.officeDocument.x2006.extendedProperties.PropertiesDocument.copy()Lorg/apache/xmlbeans/XmlObject; used in the signature 我正在使用POI 3.15。 POI JARs存储在通用的Tomcat7 / […]

如何使用apche POI在excel中只读专栏

我正在使用apache poi生成一个excel文件,而且我想只在该excel文件中使最后两列读取。 所以我尝试了poi的lockingfunction,但是它使得所有的单元只读,我想在最后两个只读。在这里,我发布了我迄今为止所做的 HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(); sheet.protectSheet("password"); HSSFRow row = null; HSSFCell cell = null; /* cell style for locking */ CellStyle lockedCellStyle = wb.createCellStyle(); lockedCellStyle.setLocked(true); /* cell style for editable cells */ CellStyle unlockedCellStyle = wb.createCellStyle(); unlockedCellStyle.setLocked(false); cell = row.createCell(columnNo); if (null != taskDiaryItem.getDueDate()) { SimpleDateFormat formater = […]

Apache-poi限制用户只select下拉列表的值

我怎样才能让用户只select下拉列表中的一个值,而不是在Excel工作表中input自己的值。 我正在使用Java库Apache-POI

Java将csv-String写入Excel

在我的程序中,我想写一个string* .xlsx string示例: A,B,C,d,E ,,楼\ NA,B,C,d,E ,,女,\ n 我想写一个如下所示的Excel文件: 我怎样才能做到这一点? private void createExcel() throws Exception { //Create blank workbook XSSFWorkbook workbook = new XSSFWorkbook(); //Create a blank sheet XSSFSheet spreadsheet = workbook.createSheet("Excel Sheet"); 我怎样才能从我的csvString创build行和列? //Write the workbook in file system FileOutputStream out = new FileOutputStream(new File("FilePath.xlsx")); workbook.write(out); out.close(); System.out.println("*.xlsx written successfully" ); } 我很感激任何帮助

使用Apache POI读取Excel,XML MAP元素名称

我有一个业务需求,我已经提供了与Excel映射到位的Excel文档(基本上使用Excel菜单选项开发人员 – >源,然后select一个XML文件和XML元素映射到Excel单元格)。 例如:单元格A2中的值被映射到xml元素“document_title”,B2被映射到“document_number”。 要求是以编程方式读取excel文档并searchXML元素的列表,并find映射的单元格和单元格的内容。 例如:searchxml元素“document_title”并查找该元素映射到的单元格(在上面提到的例子中,这是A2)并读取单元格的内容。 我已经尝试使用Apache POI的OPCP包和XSSFReader类,并尝试使用DOMParserparsing它,但无法实现这一点。 以下是源代码的修剪版本,有人可以帮助我在正确的方向。 public static void main( String[] args ) throws IOException { System.out.println( "reading excel" ); try { OPCPackage pkg = OPCPackage.open("D:\\test.xlsx"); XSSFReader r = new XSSFReader( pkg ); SharedStringsTable sst = r.getSharedStringsTable(); InputStream inp = r.getSheet("rId1"); InputSource inpSource = new InputSource(inp); DOMParser parser = new DOMParser(); parser.parse(inpSource); […]

导入Apache POI单元库

我正在写一个项目,结果应该保存到Excel文件( .xlsx )。 我在pom.xml添加了以下依赖项: <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.8-beta3</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.16-beta1</version> </dependency> 所有导入的库工作正常,如: import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; 除了与细胞有关的细胞外。 它必须有以下导入语句: import org.apache.poi.ss.usermodel.Cell; 但它不起作用。 我不知道是什么问题。

如何使用Apache POI在1或2张excel文件中查找特定的string?

我需要在1张excel中find一个特定的string(id,name)。 这是一个基本的需求。 之后,我们需要在几张Excel工作表上find一个用户,并复制用该代码标识的整个logging​​,并将其发送给框架中的一个JTable 。

使用StreamingOutput对象写入excel文件。 (java.lang.ClassCastException)

我有一个返回StreamingOutput对象的方法。 而我想把这个StreamingOutput对象写入excel文件。 而且我写了下面的代码,它给了我java.lang.ClassCastExceptionexception。 StreamingOutput stream = getStreamObject(); SXSSFWorkbook workBook = (SXSSFWorkbook) stream; //Exception occurs here FileOutputStream fileOut = new FileOutputStream("/save/excel/file/here"); workBook.write(fileOut); fileOut.flush(); fileOut.close(); 所以,请帮我解决这个问题。 先谢谢你。

无法使用Apache POI ss用户模型添加工作表

我试图添加表与Apache POI,但是我得到空指针exception,当我试图保存excel。不知道为什么发生这种情况,但数据更新到Excel发生完美。 发生exception:org.apache.poi.POIXMLException:java.lang.NullPointerException public XL_ReadWrite(String path) throws Exception{ this.path = path; try{ fin = new FileInputStream(path); workbook = WorkbookFactory.create(fin); sheet = workbook.getSheetAt(0); fin.close(); } catch(FileNotFoundException e){ throw new Exception("Exception occurred while finding the file : " + path + " while XLS initialize .Exception details : "+e.getMessage()); } catch(IOException e){ throw new Exception("I/O interrupted exception […]