apache-poi

Using java.awt.image.BufferedImage for creating BIFF8 BITMAP record takes much time - Is there any better approach?

≡放荡痞女 提交于 2020-01-03 17:12:38
问题 So I am creating a HSSFSheet having a background bitmap set using apache poi and own low level code. The https://www.openoffice.org/sc/excelfileformat.pdf declares for the Record BITMAP, BIFF8 : Pixel data (array of height lines of the bitmap, from bottom line to top line, see below) ... In each line all pixels are written from left to right. Each pixel is stored as 3-byte array: the red, green, and blue component of the colour of the pixel, in this order. The size of each line is aligned to

writing a poi workbook to output stream is generating weird values

无人久伴 提交于 2020-01-03 10:04:45
问题 i am aiming to create an Excel file for the user to download via apache poi. I have this code in my servlet: protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // create a workbook , worksheet Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("MySheet"); CreationHelper createHelper = wb.getCreationHelper(); // Create a row and put some cells in it. Rows are 0 based. Row row = sheet.createRow((short)0); Cell cell =

How to resolve the java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook?

こ雲淡風輕ζ 提交于 2020-01-03 08:43:37
问题 I'm trying to read the xlsx file from asset folder. I received below exception, 05-16 10:12:05.613: E/AndroidRuntime(2915): FATAL EXCEPTION: main 05-16 10:12:05.613: E/AndroidRuntime(2915): java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook before this exception, I received some warnings also like, Could not find method org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument$Factory.parse, referenced from method org.apache.poi.xssf.usermodel.XSSFWorkbook

paragraph.getRuns() to separate a paragraph

☆樱花仙子☆ 提交于 2020-01-03 05:24:09
问题 When I use Apache poi to change the date of a contract automatically, i am very confused at the how dose paragraph.getRuns() separate a paragraph. I have the following paragraph 自 2014 年 10 月 1 日起至 2014 年 10 月 31 日止 I use the following code to see how many XWPFRun does paragraph.getRuns() return String currentParagraph = ""; for(XWPFRun xwpfRun : paragraph.getRuns()){ currentParagraph += xwpfRun.getText(0); System.out.println(currentParagraph); } I find the first five number are all a xwpfRun

How to find out what makes poi corrupt a xlsx / xlsm file

有些话、适合烂在心里 提交于 2020-01-03 02:48:25
问题 I have the issue that Apache POI "corrupted" a xlsm / xlsx file by just reading and writing it (e.g. with the following code) public class Snippet { public static void main(String[] args) throws Exception { String str1 = "c:/tmp/spreadsheet.xlsm"; String str2 = "c:/tmp/spreadsheet_poi.xlsm"; // open file XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(new File(str1))); // save file FileOutputStream out = new FileOutputStream(str2); wb.write(out); wb.close(); out.close(); } } Once you

Apache poi: remove Picture in XWPFDocument

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 02:25:31
问题 I'm writing an application that takes a .docx file with a bunch of empty paragraphs and tables and fills them programmatically using Apache POI with data from a db. The .docx model I've been provided with also has a serie of pictures in it: my problem is I'd like to remove the ones I don't need (again, programmatically). I see there is a method for adding pictures to a XWPFRun (addPicture()) but not one for removing them. Can this be done? How do you remove a picture from a .docx file with

How to create XSSFShape with no border outline of the shape?

戏子无情 提交于 2020-01-02 16:06:12
问题 In Apache POI 3.9 for HSSFShape class there is a constant 'HSSFShape.LINESTYLE_NONE' and if I apply it using shape.setLineStyle(HSSFShape.LINESTYLE_NONE) then I can create a shape with no border. But in XSSFShape I guess similar constant 'XSSFShape.LINESTYLE_NONE' or something like that is missing. Please help with some another way by which I can create a XSSFShape with no border outline.. 来源: https://stackoverflow.com/questions/21396330/how-to-create-xssfshape-with-no-border-outline-of-the

how to judge if the file is doc or docx in POI

廉价感情. 提交于 2020-01-02 14:52:20
问题 The title may be a little confusing. The simplest method must be judging by extension name just like: // is represents the InputStream if (filePath.endsWith("doc")) { WordExtractor ex = new WordExtractor(is); text = ex.getText(); ex.close(); } else if(filePath.endsWith("docx")) { XWPFDocument doc = new XWPFDocument(is); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); text = extractor.getText(); extractor.close(); } This works in most cases. But I have found that for certain file

Apache POI - JAVA - iterating over columns in excel

夙愿已清 提交于 2020-01-02 07:23: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

How to set image size is dynamically in poi word run.addPicture()?

我的未来我决定 提交于 2020-01-02 07:05:57
问题 XWPFDocument doc= new XWPFDocument(); InputStream a = someMethod(underConditions(inputimage)); paragraph.createRun().addPicture(a, Document.PICTURE_TYPE_PNG, "", Units.toEMU(20), Units.toEMU(20)); a.close(); doc.write(new FileOutputStream("CreateWordHeaderFooter.docx")); doc.close(); This is simple code for add a image in poi word. But InputStream a is different under different conditions. If inputimage is small Units.toEMU(20), Units.toEMU(20) is to big, and if inputimage is big Units.toEMU