apache-poi

Apache POI Time Cell

这一生的挚爱 提交于 2019-12-12 12:26:11
问题 I need to detect, whether cell format is Date, Time or Datetime. My code is: if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { if (DateUtil.isCellDateFormatted(cell)) { if ( ??? ) return "Time"; else if ( ??? ) return "Date"; else return "Datetime"; } } I use ApachePOI 3.6 回答1: I don't see a built-in way to do this easily in POI. First, there doesn't seem to be a clear distinction between "Time", "Date", and "Datetime". The values are just stored as numbers and a format is applied to

Error creating cell with POI

随声附和 提交于 2019-12-12 10:48:16
问题 I do an export from Java to xls, i use POI library. My createCell Method: private Cell createCell(Row ligne, int col, String value, CellStyle style, HSSFWorkbook classeur) { //org.apache.poi.hssf.usermodel.HSSFOptimiser.optimiseCellStyles(classeur); CellStyle styleCell = classeur.createCellStyle(); styleCell.cloneStyleFrom(style); return createCell(ligne, col, value, styleCell); } protected Cell createCell(Row ligne, int col, String value, CellStyle style) { Cell cell = createCell(ligne, col,

How to generate RSID attributes correctly in Word .docx files using Apache POI?

只愿长相守 提交于 2019-12-12 10:46:29
问题 I have been using Apache POI to manipulate Microsoft Word .docx files — ie open a document that was originally created in Microsoft Word, modify it, save it to a new document. I notice that new paragraphs created by Apache POI are missing a Revision Save ID , often known as an RSID or rsidR . This is used by Word to identify changes made to a document in one session, say between saves. It is optional — users could turn it off in Microsoft Word if they want — but in reality almost everyone has

Duplicate Table Paragraphs in Docx created with Apache POI

旧街凉风 提交于 2019-12-12 10:26:55
问题 I'm using Apache POI in order to create a docx containing a table. In order to format the table, I'm adding paragraphs to the cell, using this method: private XWPFParagraph getTableParagraph(XWPFDocument document, XWPFParagraph paragraph, String text, boolean bold, boolean wrap, boolean allineaDx){ if (paragraph == null) paragraph = document.createParagraph(); XWPFRun p2run = paragraph.createRun(); p2run.setText(text); p2run.setFontSize(5); p2run.setBold(bold); if (wrap) paragraph.setWordWrap

How to delete contents of an Excel sheet in Java?

落花浮王杯 提交于 2019-12-12 09:56:44
问题 How to delete contents of an Excel sheet in an Excel workbook, using Java SE and Apache POI? 回答1: As mentioned in previous comments Sheet sheet = wb.getSheetAt(0); for (Row row : sheet) { sheet.removeRow(row); } this code throwing ConcurrentModificationException to me. So, I have modified the code and it's working fine. Here is the code: Sheet sheet = wb.getSheetAt(0); Iterator<Row> rowIte = sheet.iterator(); while(rowIte.hasNext()){ rowIte.next(); rowIte.remove(); } 回答2: I've found that

Getting null pointer exception in creating cell in Apache POI

做~自己de王妃 提交于 2019-12-12 09:14:55
问题 I am getting a null pointer error everytime I ran my code (below) and it points to the line specified with two asterisk. public void writeSomething(XSSFWorkbook wb){ for (String elem: listOfSheetNames){ if (elem.equals("Sheet2")){ sheet = wb.getSheet(elem); //sheet is of type XSSFSheet XSSFRow row = sheet.getRow(0); **XSSFCell cell = row.getCell(1); if (cell == null){ cell = row.createCell(1); cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellValue("Apple"); } } } } I am a new to apache

Writing image into pdf file in java

孤街醉人 提交于 2019-12-12 08:05:24
问题 I'm writing a code to convert Microsoft power-point(ppt) slides into images and to write the generated images into pdf file. Following code generates and writes the images into pdf file but the problem i'm facing is, when i write image into pdf file it's size is exceeding the pdf page size and i can view only 75% of the image rest is invisible. One more thing to notice here is, written images in pdf file look like zoomed or expanded. Take a look at the following snippet of code: for (int i =

Reading XLSB file with Apache POI

可紊 提交于 2019-12-12 06:37:44
问题 I am reading xlsb file with below code, but its printing as text, I want to get headers, data values for each cell to set to java objects. Which classes should I use. Thanks in advance. File file = null; OPCPackage pkg = null; XSSFEventBasedExcelExtractor ext = null; try { file = Paths.get("C:/Users/U574564/Ref/source/Q4_GL_Assignment v1.xlsb").toFile(); pkg = OPCPackage.open(file,PackageAccess.READ); ZipSecureFile.setMaxTextSize(110485766); ext = new XSSFBEventBasedExcelExtractor(pkg);

How can I call getter/setter for property marked with custom annotation?

时间秒杀一切 提交于 2019-12-12 06:20:01
问题 I am currently creating a custom marshalling tool for parsing an excel file. I would like to know how I can first find all properties with a custom annotation (this needs to take inheritance into account, so more than getDeclaredFields), then based on what method I am using call the corresponding getter or setter. Right now, I am just focusing on the setter. Current Code: private <T> T findAnnotations(Class<T> clazz) { T obj = null; Annotation[] annotations = clazz.getAnnotations(); for

“error: cannot find symbol” using Apache POI

浪尽此生 提交于 2019-12-12 06:19:40
问题 This is my code: import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.*; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class Reader { public static void read_excel() { File excel = new File ("C:\\Users\\Username\\Desktop\\java-Tools\\data.xlsx"); FileInputStream fis = new FileInputStream