apache-poi

Apache POI Currency Data Format

☆樱花仙子☆ 提交于 2019-12-06 01:59:49
问题 I try to convert numbers into european currency style with Apache POI HSSFDataFormat cf = workbook.createDataFormat(); currencyCellStyle = workbook.createCellStyle(); currencyCellStyle.setDataFormat(cf.getFormat("#.###,#0")); I have for example the number 2400 and 2.4 What I want is 2400,00 and 2,40 . But POI gives me 2400,0 and 2,40. When I try to change it to currencyCellStyle.setDataFormat(cf.getFormat("#.###,00")); I get the result 2400,00 and 2,400. Thats also not what I want. Is there a

Apache POI - JAVA - iterating over columns in excel

隐身守侯 提交于 2019-12-06 01:38:21
new to java here. I'm working on a code that reads excel files (looking at cells in columns) and then writes something that looks like the following tables: I have an excel file that looks like this: col1 col2 col3 col4 ----------------------------- row1 | 2,3,1 _ 1 w row2 | 3,2,7 _ 2 x row3 | _ _ 3 y row4 | 4,9 _ 4 z I'm writing some values (using XLWT) in column 2 that look like this: col1 col2 col3 col4 ----------------------------- row1 | 2,3,1 x,y,w 1 w row2 | 3,2,7 y,x 2 x row3 | _ _ 3 y row4 | 4,9 z 4 z Essentially, column 3 and column 1 are being compared, and if cell (1,1) has values

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

这一生的挚爱 提交于 2019-12-06 01:34:49
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 following code. MainDocumentPart mainDocumentPart = null; WordprocessingMLPackage docxFile =

xssf How to get anything as String

北战南征 提交于 2019-12-06 01:31:12
问题 I try to parse an excel file into XML using apache poi xssf. Now having a cell and not knowing what is in it I just want to get a String out of it. But when I use cell.getStringCellValue() it throws an exception, what is not very suprising since it is documented this way. So I build my way around that by checking weather it is a numeric or a text cell. But what to do with formula cells. They may contain numbers like = A2 + B2 What gives me the sum (e.g. 4) or a reference to another text = C2

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

狂风中的少年 提交于 2019-12-06 00:33:38
How can I update the page header of a .docx file using the Apache POI 3.7 API? 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 of them etc. It's all the same process then as editing the main document. Since your document is in .docx

POI: Unexpected record type org.apache.poi.hssf.record.HyperlinkRecord

狂风中的少年 提交于 2019-12-06 00:21:48
I am working on a simple task: Reading an Excel file and converting it to an object. Though, I am facing a problem in reading the Excel file (.xls) I will receive it from an external system (maybe they autogenerated it). If I open it and just do a simple save (with or without changing anything in the Excel file), my parser logic works fine. But if I don't edit and save the file and try to parse the original file as is, I get an exception at this line while loading the .xls file: HSSFWorkbook xlsWorkbook = new HSSFWorkbook(inputDocument); Below is the exception: java.lang.RuntimeException:

Adding shapes to Powerpoint slide using XSLF (Apache POI Project)

一笑奈何 提交于 2019-12-06 00:12:12
The apache POI project explains how to read a shape from a powerpoint slide http://poi.apache.org/slideshow/xslf-cookbook.html#GetShapes However, I can't find any doc on how to add a shape to a powerpoint slide using this part of the library. If I use an old powerpoint format (ppt as opposed to pptx), I can just use the hslf part of the libaray and do: SlideShow ppt = new SlideShow(); //add first slide Slide s1 = ppt.createSlide(); // create shapes./ java.awt.geom.GeneralPath path = new java.awt.geom.GeneralPath(); path.moveTo(100, 100); path.lineTo(200, 100); path.curveTo(50, 45, 134, 22, 78,

Getting error “Your InputStream was neither an OLE2 stream, nor an OOXML stream” when created file through apache POI

穿精又带淫゛_ 提交于 2019-12-05 23:59:26
I am trying to check if my excel file already exists. If it doesn't exists, I want to create a new one and if it exists I will delete it and create a new one. I wrote following program but I am getting error at line - workbook= WorkbookFactory.create(instream); The error is-> java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:89) at tryIng.main(tryIng.java:84) Here is a program -> try { String filePath= "C:/Users/pritik/Desktop/t1.xlsx"; File file = new File(filePath);

Apache POI Libraries error in Android Studio..?

微笑、不失礼 提交于 2019-12-05 23:58:24
I added 5 jar files of Apache POI so that I can save an text as .docx document but I can't run the application first I had 210 error in the grade now i have this error can someone please help me ..!? i followed this example https://www.tutorialspoint.com/apache_poi_word/apache_poi_word_quick_guide.htm apply plugin: 'com.android.application' android { compileSdkVersion 25 buildToolsVersion "25.0.0" defaultConfig { applicationId "com.example.mike.textword" minSdkVersion 19 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner

Insert image in column to excel using Apache POI

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 23:50:08
I'm trying to insert an image into a cell in excel. I've added pictures fine, but I still runs anywhere. I want to say that I want this column. You can set the row and column first then set the image. try { Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("MYSheet"); InputStream inputStream = new FileInputStream("path_to_image.jpg"); byte[] imageBytes = IOUtils.toByteArray(inputStream); int pictureureIdx = workbook.addPicture(imageBytes, Workbook.PICTURE_TYPE_PNG); inputStream.close(); CreationHelper helper = workbook.getCreationHelper(); Drawing drawing = sheet