apache-poi

Apache POI merge cells from a table in a Word document

好久不见. 提交于 2019-12-05 19:15:45
I need to have a table with the cells on the first and second row merged. Something like this: Image of table (I can't post pics) http://i.stack.imgur.com/dAO6j.png I have been reviewing all the questions related to this topic and I have found some answers for applying grid span to the cells, but I couldn't find a real solution. Here is the code I have from examples obtained from google and from this site: XWPFDocument document = new XWPFDocument(); XWPFTable table = document.createTable(7, 2); fillTable(table); XWPFTableCell cellRow1 = table.getRow(0).getCell(0); XWPFTableCell cellRow2 =

Creating multiple sheets using Apache poi and servlets

China☆狼群 提交于 2019-12-05 19:05:31
When i am creating multiple sheets using Apache poi and servlets. It is creating the sheet but not writing the data to file. I am trying to write the first 1000 records to sheet1 and next 1000 to sheet2 through below code, but not working private void writeDataToExcelFile(String string, ArrayList<ArrayList<String>> excelData, OutputStream outputStream) { HSSFWorkbook myWorkBook = new HSSFWorkbook(); String sheetName = ""; sheetName = "Document-" + 0; HSSFSheet mySheet = myWorkBook.createSheet(); HSSFRow myRow = null; HSSFCell myCell = null; for (int rowNum = 0; rowNum < excelData.size();

How to create cell with multiple styles in excel using HSSFSheet Apache POI?

荒凉一梦 提交于 2019-12-05 19:04:25
I am creating a script for export document as excel. How to have cell value like " Name: Mark DOB: 11-11-2014" by merging few cells? What you need to do is create a RichTextString for your cell. That's the way of applying different formatting / styles to different parts of the same cell for display in Excel You'll want to review the POI "Working With Rich Text" example for more on how to use it, but broadly it'll be something like Cell cell = row.createCell(1); RichTextString rt = new XSSFRichTextString("The quick brown fox"); Font font1 = wb.createFont(); font1.setBoldWeight(Font.BOLDWEIGHT

generate excel in java

岁酱吖の 提交于 2019-12-05 18:40:34
I want to generate excel with enabling auto-filter option.For that I have create one template excel file by enabling auto-filter option but when I write something into that template excel file auto-filter option disabled again. Is there any solution to create excel file by enabling auto-filter option. Not sure if this is what you are looking for (and you don't really describe how you write the file today). "create excel file by enabling auto-filter option" doesn't really make sense to me. There is the Apache POI that I have used for generating excel files and it works pretty well. Is that was

How to insert a image in word document with Apache POI?

人盡茶涼 提交于 2019-12-05 18:21:10
I have this code: public class ImageAttachmentInDocument { /** * @param args * @throws IOException * @throws InvalidFormatException */ public static void main(String[] args) throws IOException, InvalidFormatException { XWPFDocument doc = new XWPFDocument(); FileInputStream is = new FileInputStream("encabezado.jpg"); doc.addPictureData(IOUtils.toByteArray(is), doc.PICTURE_TYPE_JPEG); XWPFParagraph title = doc.createParagraph(); XWPFRun run = title.createRun(); run.setText("Fig.1 A Natural Scene"); run.setBold(true); title.setAlignment(ParagraphAlignment.CENTER); FileOutputStream fos = new

Excel file created with apache poi (Java) can't be opened on Windows

ぃ、小莉子 提交于 2019-12-05 18:11:01
In my system, I have a class that creates an excel with some data. Basically I read all String values from a variable ArrayList> and write them in excel cells. public void writeData(Data data, int sheetNumber) throws EncryptedDocumentException, InvalidFormatException, IOException { org.apache.poi.ss.usermodel.Workbook workbook; try { workbook = WorkbookFactory.create(new File(path)); } catch (FileNotFoundException e) { workbook = new HSSFWorkbook(); } org.apache.poi.ss.usermodel.Sheet sheet; try { sheet = workbook.createSheet("Sheet" + sheetNumber); } catch (IllegalArgumentException e) { sheet

How to check a column is hidden or not in excel file using apache poi

久未见 提交于 2019-12-05 17:55:32
I am trying to parse a xls file using apache poi. Is it possible to check whether a column is hidden or not. How can I get the width of a particular column. Example: According to the post here it checks if the row is hidden or not. Similarly I want to check the width of a column ( or check if the column is hidden or not) you can set a column as hidden/unhidden by using sheet.setColumnHidden(int columnIndex, boolean hidden); e.g. sheet.setColumnHidden(2, true); // this will hide the column index 2 sheet.setColumnHidden(2, false); // this will unhide the column index 2 and the column is hidden

Embed document in xlsx file with POI

让人想犯罪 __ 提交于 2019-12-05 17:12:34
Is there any way to embed a document (e.g. pdf) in an xlsx file using Apache POI? It seems you can read embedded documents using workbook.getAllEmbedds() , but I can't find a way to insert any when writing a file. Reena This should help: similar question with answer User has created a patch for Apache poi with which you can include arbitary file into excel sheet patch link here Hope this helps. 来源: https://stackoverflow.com/questions/10280687/embed-document-in-xlsx-file-with-poi

How to get pptx slide notes text using apache poi?

送分小仙女□ 提交于 2019-12-05 17:02:59
So far I only have a working code for retrieving texts from ppt slide notes try { FileInputStream is = new FileInputStream("C:\\sample\\test.ppt"); SlideShow ppt = new SlideShow(is); Slide[] slide = ppt.getSlides(); for (int i = 0; i < slide.length; i++) { System.out.println(i); TextRun[] runs = slide[i].getNotesSheet().getTextRuns(); if (runs.length < 1) { System.out.println("null"); } else { for (TextRun run : runs) { System.out.println(" > " + run.getText()); } } } } catch (IOException ioe) { } But how do you retrieve text from pptx slide notes? After constant trial and error, found a

How to get Cell Reference using Cell?

隐身守侯 提交于 2019-12-05 15:23:04
I am using apache poi 3.11, from CellReference, I can get rowIndex and Column Index, using following code. CellReference cr = new CellReference("A1"); row = mySheet.getRow(cr.getRow()); cell = row.getCell(cr.getCol()); But my rowIndex and columnIndex are generated dynamically, how can I get CellReference using rowIndex and columnIndex? XSSFRow row = mySheet.getRow(rowIndex); XSSFCell cell = row.getCell(columnIndex); Create a CellReference instance using the CellReference(int pRow, int pCol) constructor of the CellReference class, and the formatAsString method of the created instance. You can