apache-poi

get Date from Excel Sheet using POI

蹲街弑〆低调 提交于 2019-12-21 06:41:21
问题 I have get the date from excel sheet using POI using the below code, if (DateUtil.isCellDateFormatted(currentCell)) { Date date = currentCell.getDateCellValue(); cellValue = date.getDate() + "/" + (date.getMonth() + 1) + "/" + (1900 + date.getYear()); } By default the date format of excel sheet is MM/dd/yy. But if I make the month value is greater than 12 (i.e >= 13), the format is changed to dd/MM/yy. By the above code,If I give date as 10/11/2010, it gives month as 10 and date as 11. If I

get Date from Excel Sheet using POI

痴心易碎 提交于 2019-12-21 06:41:06
问题 I have get the date from excel sheet using POI using the below code, if (DateUtil.isCellDateFormatted(currentCell)) { Date date = currentCell.getDateCellValue(); cellValue = date.getDate() + "/" + (date.getMonth() + 1) + "/" + (1900 + date.getYear()); } By default the date format of excel sheet is MM/dd/yy. But if I make the month value is greater than 12 (i.e >= 13), the format is changed to dd/MM/yy. By the above code,If I give date as 10/11/2010, it gives month as 10 and date as 11. If I

Apache Poi excel remove blank rows

最后都变了- 提交于 2019-12-21 06:04:44
问题 I have an excel file with 3000 rows. I remove the 2000 (with ms excel app), but when i call the sheet.getLastRowNum() from code , it gives me 3000 (instead of 1000).. How can i remove the blank rows? I tried the code from here but it doesn't works.... 回答1: There are two ways for it: 1.) Without code : Copy the content of your excel and paste it in a new excel, and later rename is as required. 2.) With code (I did not find any functions for it so I created my own function): You need to check

How to read Excel cell having null values too in Java…?

北城以北 提交于 2019-12-21 04:36:13
问题 I'm using Apache POI 3.6. I've a column which is blank . I would like to be able to read it and then move to the next column. Even if I could resolve the NullPointerException problem I could not get to the next cell. Here's my code snippet : HSSFCell cell = row.getCell(c); String value = null; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: value = "FORMULA value=" + cell.getCellFormula(); break; case HSSFCell.CELL_TYPE_NUMERIC: value = "NUMERIC value=" + cell

Apache POI-HSSF distorts image size when adding picture into Excel cell

自作多情 提交于 2019-12-21 04:34:10
问题 I am adding a picture into a cell using Apache POI-HSSF. The image is 120x100 but no matter what I do and how I resize it, the Excel spreadsheet always shows it spanning multiple rows and distorts it to a much bigger height than width. How do I keep the original size? My code: InputStream is = new FileInputStream(getImageURL()); byte[] bytes = IOUtils.toByteArray(is); int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG); is.close(); //add a picture shape CreationHelper helper =

POI Auto Filter

我怕爱的太早我们不能终老 提交于 2019-12-21 03:37:35
问题 How do I use Apache POI to pre-define an auto-filter region in an Excel 2007 document? A small code example or link would be nice. 回答1: Save the first and the last cell from the filter area, and execute: sheet.setAutoFilter(new CellRangeAddress(firstCell.getRow(), lastCell.getRow(), firstCell.getCol(), lastCell.getCol())); For example, from the sheet below. >x (x, y) 0123456 0|--hhh--| h = header 1|--+++--| + = values 2|--+++--| - = empty fields 3|--+++--| 4|-------| fist cell will be the

Copying Excel Worksheets in POI

為{幸葍}努か 提交于 2019-12-21 03:33:07
问题 Does anyone know of a means to copy a worksheet from one workbook to another using POI? The Workbook class has a cloneSheet method, but there doesn't seem to be able to insert a cloned sheet into a new workbook? If there isn't an API to do this easily, does anyone have the code to copy all of the data (styles, column widths, data, etc) from one sheet to another? The jxls has methods to copy sheets, but they don't work when copying between workbooks. 回答1: i have implemented some functionality

Delete an excel sheet using Apache POI

我只是一个虾纸丫 提交于 2019-12-20 18:06:49
问题 I have to delete a sheet from the Excel file. Here's my code snippet : FileInputStream fileStream = new FileInputStream(destFile); POIFSFileSystem fsPoi = new POIFSFileSystem(fileStream); HSSFWorkbook workbook = new HSSFWorkbook(fsPoi); int index = 0; HSSFSheet sheet = workbook.getSheet("Setup"); if(sheet != null) { index = workbook.getSheetIndex(sheet); workbook.removeSheetAt(index); } return destFile; After this I'm getting exactly the same workbook which I passed, without the removal of

Delete an excel sheet using Apache POI

女生的网名这么多〃 提交于 2019-12-20 18:05:56
问题 I have to delete a sheet from the Excel file. Here's my code snippet : FileInputStream fileStream = new FileInputStream(destFile); POIFSFileSystem fsPoi = new POIFSFileSystem(fileStream); HSSFWorkbook workbook = new HSSFWorkbook(fsPoi); int index = 0; HSSFSheet sheet = workbook.getSheet("Setup"); if(sheet != null) { index = workbook.getSheetIndex(sheet); workbook.removeSheetAt(index); } return destFile; After this I'm getting exactly the same workbook which I passed, without the removal of

Apache POI HWPF - problem in convert doc file to pdf

我们两清 提交于 2019-12-20 14:05:13
问题 I am currently working Java project with use of apache poi. Now in my project I want to convert doc file to pdf file. The conversion done successfully but I only get text in pdf not any text style or text colour. My pdf file looks like a black & white. While my doc file is coloured and have different style of text. This is my code, POIFSFileSystem fs = null; Document document = new Document(); try { System.out.println("Starting the test"); fs = new POIFSFileSystem(new FileInputStream("