apache-poi

Adding Custom colours to Excel sheet using Apache POI

点点圈 提交于 2019-12-07 15:15:29
Can anyone explain how to add Custom colours either using (rgb values or hex values ) to an excelsheet sheet(either in foreground or background) using Cellstyle in Apche poi to a Excelsheet(XSSF Workbook)? Setting custom colors depends on the kind of Excel file (Office Open XML format *.xlsx vs. BIFF format *.xls ). And it might be different using different versions of apache poi because of deprecation. Using Office Open XML format *.xlsx we can simply set new colors using constructor of XSSFColor . In apache poi 4.0.0 XSSFColor(byte[] rgb, IndexedColorMap colorMap) can be used.

How to read word document and get parts of it with all styles using docx4j

那年仲夏 提交于 2019-12-07 14:32:38
问题 I am using docx4j to deal with word document formatting. I have one word document which is divided in number of tables. I want to read all the tables and if I find some keywords then I want to take those contents to another word document with all the formatting. My word document is as follow. Like from above I want to take content which is below Some Title. Here my keyword is Sample Text. So whenever Sample Text gets repeated, content needs to be fetched to new word document. I am using

Counting pages in a Word document

戏子无情 提交于 2019-12-07 13:56:06
问题 I'm trying to count pages from a word document with java. This is my actual code, i'm using the Apache POI libraries String path1 = "E:/iugkh"; File f = new File(path1); File[] files = f.listFiles(); int pagesCount = 0; for (int i = 0; i < files.length; i++) { POIFSFileSystem fis = new POIFSFileSystem(new FileInputStream(files[i])); HWPFDocument wdDoc = new HWPFDocument(fis); int pagesNo = wdDoc.getSummaryInformation().getPageCount(); pagesCount += pagesNo; System.out.println(files[i].getName

Java write Excel files with POI event model

一曲冷凌霜 提交于 2019-12-07 13:13:21
问题 Is it possible to create and write to a (new) excel file using the event driven API from POI? I've found examples on how to read with that API, but not how to write. thanks, Jeff 回答1: Here is one possibility, not very well written, though: http://www.docjar.org/html/api/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java.html I'm using a modified version of that, which does not require temporary files and is overall more efficient 回答2: Yes. Absolutely. Look at POI-XSSF and POI-HSSF http:/

Updating a .docx file's page header using Apache POI

 ̄綄美尐妖づ 提交于 2019-12-07 13:09:56
问题 How can I update the page header of a .docx file using the Apache POI 3.7 API? 回答1: First up, call getHeaderFooterPolicy() on your XWPFDocument, which returns a HeaderFooterPolicy. From that, you can identify the appropriate header for your page (eg Default, First Page etc) Once you have the appropriate XWPFHeader that you want to change, then you can go about editing it as any other document part. You can fetch the tables, the paragraphs etc, then remove them, add new ones, change the text

Creating multiple sheets using Apache poi and servlets

試著忘記壹切 提交于 2019-12-07 11:59:00
问题 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

Validation : how to check if the file being uploaded is in excel format? - Apache POI

こ雲淡風輕ζ 提交于 2019-12-07 11:58:27
Is there any way I can check if the file being uploaded is in excel format? I am using Apache POI library to read excel, and checking the uploaded file extension while reading the file. Code snippet for getting the extension String suffix = FilenameUtils.getExtension(uploadedFile.getName()); courtesy BalusC : uploading-files-with-jsf String fileExtension = FilenameUtils.getExtension(uploadedFile.getName()); if ("xls".equals(fileExtension)) { //rest of the code } I am sure, this is not the proper way of validation. Sample code for browse button <h:inputFileUpload id="file" value="#

How to get Cell Reference using Cell?

半腔热情 提交于 2019-12-07 10:29:29
问题 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); 回答1: Create a CellReference instance using the CellReference(int pRow, int

How to solve a NoSuchMethodError when using POI for doc files

∥☆過路亽.° 提交于 2019-12-07 09:31:59
问题 When I was trying to implement any code of the following File someFile = new File("D:\\arz.doc"); InputStream inputStrm = new FileInputStream(someFile); HWPFDocument wordDoc = new HWPFDocument(inputStrm); System.out.println(wordDoc.getText()); or: POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("D:\\arz.doc")); WordExtractor extractor = new WordExtractor(fs); String wordText = extractor.getText(); , the error message always comes out as following: Exception in thread “main” java

Apache POI merge cells from a table in a Word document

走远了吗. 提交于 2019-12-07 09:28:06
问题 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