apache-poi

Limiting cells to only numeric values in Apache POI

烂漫一生 提交于 2019-12-07 18:42:20
问题 We are using Apache POI library to create the excel sheets. How can we restrict the cells to accept only numeric values ? Is there any class that restricts to only numbers in Apache POI library ? Thanks Rama Krishna 回答1: Perhaps, I should have asked my question like how to add Data Validation in Excel using Apache POI. But here is the code to do so. I guess this can help someone. It worked for me. You need to be careful with Cell Range. XSSFWorkbook wb = new XSSFWorkbook(); XSSFSheet sheet =

Apache POI usage with Apache Felix

蓝咒 提交于 2019-12-07 18:21:31
问题 I'm trying to import Apache POI to Atlassian Jira Plugin for reading excel files. At the beginning, I started with adding just <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>${poi.version}</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>${poi.version}</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>${poi.version}<

how create a Word document from a template or existing document with Java?

谁都会走 提交于 2019-12-07 17:52:16
问题 I have a document template where some fields are static and others are dynamic. I need to replace some data (name, last name, salary) and generate the new file. What library do you recommend to do this? Is POI appropriate? I am working with Spring, Java EE6 and Oracle. 回答1: You can give Apache POI a try but the HWPF and XWPF part of POI which are required to manipulate word files are really complicated to use - you need to have at least a good understanding how a word file is structured!

Is there any Java library which supports both Microsoft office and Open Office?

心已入冬 提交于 2019-12-07 17:03:42
问题 As Apache POI supports Microsoft office and JExcelApi supports Open Office, is there any Java library which supports both Microsoft office and Open Office? Note: In the pom.xml file we are using either POI and JExcel utilities in order to fetch/read data from the Excel sheet in Microsoft office and Open Office respectively. So my question: Is there any library which supports both? 回答1: Aspose covers all of Microsofts formats, but it is not free and not open source. Regarding open source Java

Convert byteArray to XSSFWorkbook using Apache POI

偶尔善良 提交于 2019-12-07 16:57:57
问题 I am using Apache POI and I am trying to send a xlsx file as HTTP request and get it back as response. I am using jayway restassured for making HTTP requests. Here is the part of the code where I send the request File file = new File("path"); String response = given().multipart(file).when().post("URL").getBody().asString(); byte[] bytes = response.getBytes("ISO-8859-1"); InputStream stream = new ByteArrayOutputStream(bytes); try { XSSFWorkbook workbook = new XSSFWorkbook(stream); } catch

Detecting hidden cells in excel using apache poi

给你一囗甜甜゛ 提交于 2019-12-07 16:47:38
问题 We are using apache poi 3.8 to parse excels. We need to be able to detect (and skip) hidden rows as they tend to contain junk data in our usecases. It would seem this should work: row.isFormatted() && row.getRowStyle().getHidden() But there never appears to be any row-level formatting (getRowStyle() always returns null). As a last resort we thought checking cell styles might work: for (int i = 0; i < row.getLastCellNum(); i++) { Cell cell = row.getCell(i); if (cell != null && cell

In Apache POI 3.9 using autosizeColumn the image present on the same column getting stretched

亡梦爱人 提交于 2019-12-07 16:39:44
问题 I have an image and some text below the image in an excel sheet. when i am applying autoSizeColumn() to the column where text present the image is also getting streched . i am also setting the anchortype to 2 but this is not protecting the image to resize. I am posting some sample code here. public static void main(String[] args) { try{ XSSFWorkbook book = new XSSFWorkbook(); XSSFSheet sheet = book.createSheet("Test Sheet"); InputStream is = new FileInputStream("D:\\RPM_Eclipse_Workspaces\\B6

How to read docx file content in java api using poi jar

為{幸葍}努か 提交于 2019-12-07 16:17:02
问题 I have done reading doc file now i'm trying to read docx file content. when i searched for sample code i found many, nothing worked. check the code for reference... import java.io.*; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.extractor.XWPFWordExtractor; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.Document; import com.itextpdf.text.Paragraph; public class createPdfForDocx { public static void main(String[] args) { InputStream fs = null;

How to remove / delete the table from the TableList POI

人走茶凉 提交于 2019-12-07 16:10:30
问题 I am using a template docx file to fill the data on each table, but in some cases I don't want same table, is there anyway using which XWPFTable can be deleted / removed? 回答1: You can try int position = document.getPosOfTable( table ); document.removeBodyElement( position ); Here is an example, in which you provide a template file (with tables in it), the program deletes the first table and saves the document. import java.io.File; import java.io.FileInputStream; import java.io

How to create hyperlink to a filter on other sheet using Apache poi in Java?

主宰稳场 提交于 2019-12-07 15:30:37
I want to create a hyperlink from a field 'Name' on Sheet1 (Summary) to the AutoFilter on column 'Name' on Sheet2 (Details), in order to display the details of that particular name only on the Sheet2. I have imported : import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.ss.usermodel.CreationHelper; Hyperlink to filter on other sheet. I have done this using VB macro, but want to implement this using Java POI. I had troubles with Hyperlinks some time ago, and the quickest way to do that (I was in a hurry too!) is the following: row.createCell(cellIdx, HSSFCell.CELL_TYPE_FORMULA)