apache-poi

XWPF new paragraph in a table cell

杀马特。学长 韩版系。学妹 提交于 2019-12-14 03:03:26
问题 I am trying to create a simple table with one column. I create a new row and in each row a new paragraph. The problem is that each row starts with one empty line - I guess the new paragraph creates it. I was trying to set spacing before, indentation etc. with no success. for (int i=0; i<questions.size(); i++) { Question question = questions.get(i); XWPFTableRow row = table.getRow(i); XWPFTableCell cell = row.getCell(0); XWPFParagraph paragraph = cell.addParagraph(); XWPFRun run = paragraph

How to Generate DataXML in OpenXML for powerpoint in java

心已入冬 提交于 2019-12-14 02:49:42
问题 I have added one smart art shape in the Microsoft power point presentation slide. I have retrieved the data of that diagram in Java using apache POI. I want to generate my Own DataXML for that presentation from scratch using apache poi or any other free java API. How i can generate that DataXML. Presentation consists of hierarchy smart art object only . Following is the XML from which i want to generate the Data XML. <cds> <parent name="Hierarchy Parent"> <child id="1" name="Child 1"/> <child

Apache POI .getCell() error, java.lang.NullPointerException Cannot Read Cell if blank

馋奶兔 提交于 2019-12-14 02:18:52
问题 I have been having trouble recently with Apache POI's .getCell() method for Excel files. If I try to implement Cell newCell = sheet.getRow(rowNumber).getCell(columnNumber) or something similar, I always get the error Exception in thread "main" java.lang.NullPointerException at ExcelWriter.getWorkbook(ExcelWriter.java:80) at Gui2.<init>(Gui2.java:93) at Main.main(Main.java:24) which points to the line I am implementing the .getCell() method in if the cell is null. I have code that is supposed

Refresh Pivot Table with Apache POI

社会主义新天地 提交于 2019-12-14 00:22:05
问题 I'm currently working on a Java application that uses a template excel file that contains a pivot table. The template file also has a data sheet that seeds the pivot table. This data sheet is dynamically loaded in the java application through the Apache POI api. When I open the excel file I must refresh the Pivot table manually to get the data loaded correctly. Is there any way to refresh the Pivot table with the POI api so I don't have to manually do it? 回答1: You can simple activate an

How to let user download the data in database to an excel sheet file from web application in Java/Struts?

北战南征 提交于 2019-12-13 21:56:05
问题 I want to generate a report which includes an excel sheet which is generated from the data from the database . I am using Apache POI HSSF for creating the excel sheet file in the model. Now how to let the user download the file i have created ? 回答1: Just use a servlet. Feed response.getOutputStream() to POI HSSF to write the workbook to. Most important bit is the Content-Disposition response header. If you set it to attachment , then the browser will pop a Save As dialogue. response

Java- how to insert row in a db table after reading excel file

我怕爱的太早我们不能终老 提交于 2019-12-13 20:09:11
问题 I am able to read the excel file data from the below code, but I am unable to get the logic behind how to get Excel data in order to store in POJO class after reading the excel file. In short: I am confused how to send these read Excel data to my model class to be stored in my database table? The following code prints correctly the excel rows in my Eclipse console: .............. .............. public String execute() { try { String filePath=servletRequest.getSession().getServletContext()

java apache poi (part 2)

帅比萌擦擦* 提交于 2019-12-13 19:46:43
问题 cont. on java apache poi (part 1) Code ... while(rowIterator.hasNext()){ List<String> record = new ArrayList<String>(); row = (XSSFRow)rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); while(cellIterator.hasNext()){ cell = cellIterator.next(); cell.setCellType(Cell.CELL_TYPE_STRING); switch(cell.getCellType()){ case Cell.CELL_TYPE_STRING: record.add(cell.getStringCellValue()); break; case Cell.CELL_TYPE_NUMERIC: record.add(Double.toString (cell.getNumericCellValue()));

How to access cell value from pivot table from excel sheet using Apache POI?

筅森魡賤 提交于 2019-12-13 19:06:04
问题 How to access cell value from pivot table from excel sheet using Apache POI? I tried using XSSFPivotTable.getPivotTables, but not able to access cell value. Book1.xlsx is the excel workbook which has a pivot table on sheet Sheet1. FileInoutStream input = new FileInputStream(new File(Book1.xlsx)); XSSFWorkbook wb = new XSSFWorkbook(input); XSSFSheet sh = wb.getSheet("Sheet1"); XSSFPivotTable pt = sh.getPivotTables().get(0); Not able to access the cells in pt pivot table ahead of this. 回答1:

Add Custom XML Part using Apache POI

烂漫一生 提交于 2019-12-13 18:15:02
问题 What is the proper way to add custom XML Part to XLSX file using Apache POI? I have tried creating package part and add relation to workbook using the code below, but my newly added part is added as blank file because the workbook clears package parts in POIXMLDocument#prepareForCommit() . import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import

How to set nice float value using Apache POI?

隐身守侯 提交于 2019-12-13 17:09:37
问题 I'm trying to set a cell value to a nice float value. I want to set cell value to 5.2 , but I get 5.1999998093 instead. What would be a solution for this? Workbook workbook = new HSSFWorkbook(); Sheet worksheet = workbook.createSheet(); CellStyle style = workbook.createCellStyle(); style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.0")); int i = 0; worksheet.createRow(i + 1); worksheet.getRow(i + 1).createCell(0).setCellStyle(style); worksheet.getRow(i + 1).getCell(0).setCellValue(new