apache-poi

Apache POI Shift Row

大憨熊 提交于 2019-12-12 02:48:13
问题 I need a way to insert new cells and/or rows between pre-existing rows without deleting any of the rows. I tried using: public static void addRow(File f, int amount, int currentRow) throws Exception { FileInputStream file = new FileInputStream(f); XSSFWorkbook workbook = new XSSFWorkbook(file); XSSFSheet sheet = workbook.getSheetAt(0); sheet.shiftRows(currentRow, currentRow + amount, amount, true, true); file.close(); FileOutputStream out = new FileOutputStream(f); workbook.write(out); out

Apache POI how to apply Workbook Style to all Pivot Tables. how do i exclude sheets?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 02:44:54
问题 So i am working on a program which reads a text file and writes this data in an excel workbook. after the data is written i create pivot tables from the data. to get style in the pivot table i've set the whole workbook style which somewhy only applys to the sheets with the pivot tables and not the data sheets. now i want to exclude one sheet with pivot table from the workbook style. is there a way to exclude one sheet or set the style for the sheets which need it? code for workbook style: wb

Check if XWPFRun is highlighted

邮差的信 提交于 2019-12-12 02:44:23
问题 For Apache POI, I am reading Word documents, both doc and docx. The old CharacterRun for doc has an isHighlighted function that tells me if text is highlighted or not. Is there an equivalent function for XWPFRun for docx files? 回答1: After a lot of research and analysis, I was able to figure out there is a function in the CTRPr class. //p is the XWPFParagraph for (XWPFRun pRun : p.getRuns()) { CTRPr ctrpr = pRun.getCTR().getRPr(); if (ctrpr != null && ctrpr.isSetHighlight()) { //This is

Large Excel File - Upload and Import - Java

巧了我就是萌 提交于 2019-12-12 02:25:16
问题 all I want to upload and import a large excel files having more than one million records in to my Java program. I can easily import small files using Apache POI in to my system , but when i starts with large files application throws and out of memory error, i searched google and found many threads on so , i tried everything but could not get around of this. can anybody give me solution for my particular problem, import time is not an issue for me, right now also i can bear with performance

Null Pointer Exception in Apache poi

一曲冷凌霜 提交于 2019-12-12 02:14:29
问题 FileInputStream input=new FileInputStream(new File("TestCase.xls")); HSSFWorkbook workbook=new HSSFWorkbook(input); HSSFSheet sheet=workbook.getSheet("KeywordFramework"); System.out.println("i am in"); int rowNum = sheet.getLastRowNum() + 1; System.out.println(rowNum); int colNum = sheet.getRow(0).getLastCellNum(); System.out.println(colNum); String data [][] = new String[rowNum][colNum]; for(int i =1 ; i< rowNum;i++) { System.out.println("1"); HSSFRow row = sheet.getRow(i); for(int j = 0; j<

excel poi: apply foreground color to blank cells

廉价感情. 提交于 2019-12-12 02:13:50
问题 I want to use poi to set all cells of my excel file to a certain color. however, i keep on getting a nullpointer exception for blank cells. This is what i have so far: HSSFWorkbook workBook = new HSSFWorkbook(); HSSFCellStyle whiteFG = workBook.createCellStyle(); whiteFG.setFillForegroundColor(HSSFColor.AQUA.index); whiteFG.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); //each row has 20 columns int numColumns = 20; for (int colNum = 0 ; colNum < numColumns ; colNum++){ HSSFCell cell = row

Apache POI NoClassDefFoundError while reading excel files

耗尽温柔 提交于 2019-12-12 02:09:49
问题 I am attempting to run this code: public class ExcelSimpleTest { public static void main(String[] args) throws Exception { File f = new File("C:\\Users\\yaron\\Desktop\\Test.xlsx"); FileInputStream fis = new FileInputStream(f); XSSFWorkbook wb=new XSSFWorkbook(fis); Sheet sheet=wb.getSheetAt(0); System.out.println(sheet.getRow(0).getCell(0).getStringCellValue()); } } And am getting this error: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4

Text direction in apache poi

青春壹個敷衍的年華 提交于 2019-12-12 02:07:30
问题 How to make the text direction in Apache poi as Vertical. I tried Vertical alignment. I am not able to get the desired results. I don't want to rotate the text. Something like : T E X T 回答1: You have to create a cellStyle, where You have a method setRotation(short rotation). Subsequently apply the cellstyle to Your cell. docs, for setRotation https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFCellStyle.html#setRotation(short) 来源: https://stackoverflow.com/questions/24775688/text

How to split a .doc into several .doc using JAVA POI?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 02:02:08
问题 I am using POI to read .doc files, and I want to select some of the contents to form new .doc files. Specifically speaking, is it possible to write the content of a “paragraph” in the “range” to a new file? Thank you. HWPFDocument doc = new HWPFDocument(fs); Range range = doc.getRange(); for (int i = 0; i < range.numParagraphs(); i++) { //here I wish to write the content in a Paragraph //into a new .doc file "doc1""doc2" //instead of doc.write(pathName) that only write one .doc file. } 回答1:

HWPF-POI: inserting table in word with java

和自甴很熟 提交于 2019-12-12 01:55:19
问题 I want to create a table in Word with POI-HWPF (e.g. doc format). My example code is: Table table = document.getRange().insertTableBefore((short) 2, 2); The table is inserted, but I can't see it - as if the table has the width 0. Can anybody help me? 回答1: The file linked in this old bug report should give you an idea how to do it. So in essence: You probably need to add some content (i.e. a paragraph in a cell) so that Word has something to render. Here is the example code used in the bug