Tag: apache poi

返回十进制而不是字符串(POI jar)

我需要阅读xls或xlsx表。 我成功地阅读了工作表,但它返回十进制值而不是字符串(例如:for 3 – 它返回3.0)。 我需要按原样读取单元格值。 所以我需要以字符串forms返回

尝试使用Apache poi制作简单的PDF文档

我看到互联网上充斥着人们抱怨apache的pdf产品,但我在这里找不到我的特殊用法。 我正在尝试用apache poi做一个简单的Hello World。 现在我的代码如下: public ByteArrayOutputStream export() throws IOException { //Blank Document XWPFDocument document = new XWPFDocument(); //Write the Document in file system ByteArrayOutputStream out = new ByteArrayOutputStream();; //create table XWPFTable table = document.createTable(); XWPFStyles styles = document.createStyles(); styles.setSpellingLanguage(“English”); //create first row XWPFTableRow tableRowOne = table.getRow(0); tableRowOne.getCell(0).setText(“col one, row one”); tableRowOne.addNewTableCell().setText(“col two, row one”); […]

如何避免Apache POI中的java.lang.NoSuchMethodError:org.apache.poi.util.IOUtils.copy(Ljava / io / InputStream; Ljava / io / OutputStream;)

我有一个代码,用于将水印添加到现有的.doc文件中。 以下是我到目前为止尝试过的代码 public static void main(String[] args) { try { XWPFDocument xDoc = new XWPFDocument(new FileInputStream(“test.doc”)); XWPFHeaderFooterPolicy xFooter = new XWPFHeaderFooterPolicy(xDoc); xFooter.createWatermark(“My Watermark”); } catch(Exception e) { e.printStackTrace(); } } 以下是我得到的 Exception in thread “main” java.lang.NoSuchMethodError: org.apache.poi.util.IOUtils.copy(Ljava/io/InputStream;Ljava/io/OutputStream;)V at org.apache.poi.util.PackageHelper.open(PackageHelper.java:50) at org.apache.poi.xwpf.usermodel.XWPFDocument.(XWPFDocument.java:71) at com.avi.Test.ReadDoc.main(Watermark.java:38)

从excel单元格中读取日期值作为String

我正在使用apache poi库来读取excel文件。 我在读密码单元时卡住了。 如果用户在密码单元格中提供日期作为密码,即16/05/2012。 我将此值读为“41045”,而值应为“16/05/2012”。 这是我的代码: cell = row.getCell(); // date in the cell password ’16/05/2012′ switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: cellValue = cell.getRichStringCellValue().getString(); break; case HSSFCell.CELL_TYPE_NUMERIC: if(cellCount == TEMPLATE_PASSWORD) {// if cell is password cell.setCellType(Cell.CELL_TYPE_STRING); cellValue = cell.getRichStringCellValue().getString(); // value read is 41045 and not “16/05/2012” } break; default: } 任何人都可以帮忙吗? 谢谢。

如何使用Apache POI检查excel单元格是否为空?

我正在使用Poi.jar从excel表中获取输入,并想知道如何检查单元格是否为空。 现在我使用下面的代码。 cell = myRow.getCell(3); if (cell != null) { cell.setCellType(Cell.CELL_TYPE_STRING); //System.out.print(cell.getStringCellValue() + “\t\t”); if (cell.getStringCellValue() != “”) depend[p] = Integer.parseInt(cell.getStringCellValue()); } }

Apache POI解析错误

我知道这个问题经常被问到,但找不到合适的解决方案。 在工作时 XWPFDocument xdoc = new XWPFDocument(srcFile); 要么 XSSFWorkbook workbook = new XSSFWorkbook(srcFile); 我总是得到以下错误: Exception in thread “main” java.lang.IllegalAccessError: tried to access method org.apache.poi.util.POILogger.log(ILjava/lang/Object;)V from class org.apache.poi.openxml4j.opc.PackageRelationshipCollection at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.parseRelationshipsPart(PackageRelationshipCollection.java:313) at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.(PackageRelationshipCollection.java:163) at org.apache.poi.openxml4j.opc.PackageRelationshipCollection.(PackageRelationshipCollection.java:131) at org.apache.poi.openxml4j.opc.PackagePart.loadRelationships(PackagePart.java:561) at org.apache.poi.openxml4j.opc.PackagePart.(PackagePart.java:109) at org.apache.poi.openxml4j.opc.PackagePart.(PackagePart.java:80) at org.apache.poi.openxml4j.opc.PackagePart.(PackagePart.java:125) at org.apache.poi.openxml4j.opc.ZipPackagePart.(ZipPackagePart.java:78) at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:243) at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:684) at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:275) at org.apache.poi.util.PackageHelper.open(PackageHelper.java:37) at org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:266) 人们建议打开PackageRelationshipCollection试。 但这没有多大帮助。 […]

如何使用Apache POI读取所有单元格值?

我想使用Apache POI从excel表中读取所有单元格值并将其存储到一维字符串数组中。是否可以逐行读取excel中的数据并从每个单元格中提取值? 请帮我解决这个问题。 谢谢

无法设置填充颜色Apache POI Excel工作簿

我一遍又一遍地扫描了这个论坛并尝试了这里提到的所有方法,但仍然无法让Apache POI更改以填充我的Excel文档的背景颜色。 这是我的代码: errorOccured = true; XSSFCellStyle cs = workbook.createCellStyle(); cs.setFillBackgroundColor(IndexedColors.RED.getIndex()); row.getCell(0).setCellStyle(cs); 你知道为什么这不起作用吗? 将row.getCell(0)填充为红色(背景色)的正确方法是什么? 谢谢!

使用Apache POI在Excel文件中获取列的名称

如何使用Apache POI在Excel文件中获取列名,以确保按预期排序列。

使用Apache POI生成Excel下拉列表时的限制

我正在尝试生成带有一些validation的excel文件,我已经阅读了poi dev指南来实现它。 在实现过程中,我得到了一个exception( String literals in formulas can’t be bigger than 255 characters ASCII )。 POI将所有下拉选项连接成’0’消除字符串并检查其长度并给我exception。 🙁 我正在使用最新版本的POI 3.8 beta 5。 我的代码是: try { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(“new sheet”); HSSFRow row = sheet.createRow((short) 0); //CellRangeAddressList from org.apache.poi.ss.util package CellRangeAddressList addressList = new CellRangeAddressList(0, 0, 0, 0); DVConstraint dvConstraint = DVConstraint.createExplicitListConstraint(getCountries()); […]