Tag: apache-poi

getting xmlvaluedisconnectedexception error when saving xlsx file java poi

save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String excelFilePath = “sample.xlsx”; FileInputStream inputStream = null; try { inputStream = new FileInputStream(new File(excelFilePath)); } catch (FileNotFoundException e1) { e1.printStackTrace(); } Workbook workbook = null; try { workbook = new XSSFWorkbook(inputStream); } catch (IOException e1) { e1.printStackTrace(); } //Sheet sheet = workbook.getSheetAt(0); for (int i = […]

HSSF cell style applied only after clicking it in Excel

As article states – created style applies only after i open created *.xls file and double click formatted cell. public HSSFWorkbook makeWorkbookExc(List<String[]> allValues, List<String> captions, Integer[] order, List<Integer> numTypeColumns,List<Integer> dateTypeColumns, final container container, final List<ErrorContainer> errors) { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFFont fontBold = workbook.createFont(); fontBold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); fontBold.setFontHeightInPoints((short) 11); HSSFCellStyle styleBold = workbook.createCellStyle(); styleBold.setFont(fontBold); HSSFFont […]

Convert Java date to Excel date results in one more day than actual, before March 1, 1900

I am using POI to export some data into an Excel file. I have some code to insert some date into Excel sheet cell as date (rather than text). I works fine for dates after 01/03/1900. However for dates before that, it results a dates one more day than actual day. //SOME CODE final HSSFDataFormat […]

Reading data and inputting it into a new Excel file using Java POI

I am Currently trying to read an excel file in java, modify it and then place it into a new excel file. At the minute im just trying to place the read data straight into a new file. My question is how would you get the content from cell.getContents() straight into the new file if […]

How to add default values to a excel cell if user do not enter any values using Java?

I am creating an excel sheet and writing data into it. And I will be reading that excel sheet in another program. Now user can update the data present into the excel sheet. But if user removes present data and don’t add any values in that cell then excel should add default values automatically. How […]

Excel rows with multiple lines in one

I’ve created a Workbook to show an excel with different contents. That excel has some rows that contain some lines each. The problem is the excel only has that format when I click in a specific row and I want the entire excel looks like that. This is my code: Workbook worbook = new HSSFWorkbook(); […]

Exit from reading file with apache poi xssf

I’m using apache poi xssf to read excel files and I need to stop the reading when I find a row without field “date” (from the third row I have for each row a field date and if it is empty I have to stop with the file reading). So I have this class that […]

Removing several blank lines in XLS using Apache POI HSSF with an incrementing loop

I need to remove several lines of an excel xls sheet. These lines always contain the same first cell thats why i check the first cell of all rows to find these rows SSFCell myCell = myRow.getCell(0); myCell.setCellType(Cell.CELL_TYPE_STRING); String foundString = myCell.getStringCellValue(); if(foundString.equals(searchString)){ foundRows.add(rowCount); } rowCount++; I then go on and “remove” those rows using […]

Is there a way to mark metadata as read only in Excel

We have a use case to generate Read-Only(such as the document Creation date or Number of characters) metadata for Msexcel file. But whatever metadata we generate using java(apache poi) is editable. I tried adding metadata in custom , but this also editable . Can some one hel me out in finding a way to mark […]

XSSFFont doesn't apply for all the cells Java POI

the XSSFFont object I used to apply Bold Font works for some cells and doesn’t work for the rest of them. Some cell is set to be bold in the code, but it is displayed as unbold in the excel file (the bold button is highlighted in the excel, but the cell is not bold) […]

MS Excel Spreadsheet is the best Office Software, Excel VBA and Excel Formulas make Spreadsheet work faster.