apache-poi

Creating custom color styles for an XSSFWorkbook in Apache POI 4.0

流过昼夜 提交于 2019-12-22 08:29:27
问题 To apply a custom color for an XSSFWorkbook in Apache POI 3.7 and below the following was possible: java.awt.Color c = new java.awt.Color (1,2,3) XSSFCellStyle xcs = xssfWorkbook.createCellStyle(); XSSFFont headerFont = xssfWorkbook.createFont(); headerFont.setColor(new XSSFColor(c)); xcs.setFont(headerFont); cell.setCellStyle(xcs); In version 4.0 XSSFColor(java.awt.Color) got removed. It is still possible to achieve the same, just with additional 'hackery': XSSFColor xc = new XSSFColor(); xc

Read from excel file .xlsx using java Apache POI 3.9 Eclipse

萝らか妹 提交于 2019-12-22 06:46:24
问题 I am trying to read a file from a .xlsx file using java. But I still get errors. I already corrected the HSSF to XSSF so it is able to read past 2007 version of excel. The code crashes when instantiating the workbook. Here is the code: package excelread; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache

Multiple Styles to Excel Cell POI

99封情书 提交于 2019-12-22 06:46:12
问题 I want to apply colour to cell as well as Format Cell value(e.g. Date,Amount).But when I am applying two Cell Style only the last style is gets applied on cell. //before this colourCellStyle and dateCellStyle are the formatting style cell9 = row.createCell(9); cell9.setCellValue(getLoadDate()); cell9.setCellStyle(colourCellStyle); cell9.setCellStyle(dateCellStyle); 回答1: Multiple cell styles cannot be applied to a single Cell . The last cell style applied will overwrite any pre-existing cell

Exception using stix-fonts with openjdk?

夙愿已清 提交于 2019-12-22 06:42:34
问题 Problem happens while i try to create SXSSFWorkbook . Exception stacktrace : java.lang.ArrayIndexOutOfBoundsException: 0 at sun.font.CompositeFont.getSlotFont(CompositeFont.java:351) at sun.font.CompositeGlyphMapper.initMapper(CompositeGlyphMapper.java:81) at sun.font.CompositeGlyphMapper.<init>(CompositeGlyphMapper.java:62) at sun.font.CompositeFont.getMapper(CompositeFont.java:409) at sun.font.CompositeFont.canDisplay(CompositeFont.java:435) at java.awt.Font.canDisplayUpTo(Font.java:2063)

Apache POI autoSizeColumn() not working right [duplicate]

蹲街弑〆低调 提交于 2019-12-22 04:28:11
问题 This question already has answers here : Apache POI autoSizeColumn Resizes Incorrectly (8 answers) Closed 6 years ago . I am creating a program that writes information to an excel file using the apache poi. After I enter all of my data into the file I call the autoSizeColumn method on every column of the file. But it resizes the columns to the width of the last cell entered which is sometime not as big as the other cells in the column. I know I'm using it right and unfortunately I don't have

How to loop through all the rows and cells in an excel file

烈酒焚心 提交于 2019-12-22 03:56:15
问题 I want to use foreach to iterate through all the cells in my excel file in order to set a single foreground color. This is what I have so far. HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); sheet = wb.getSheetAt(0); for (HSSFRow myrow : sheet){ for (HSSFCell mycell : myrow){ //set foreground color here } } The problem is for the statements for (HSSFRow myrow : sheet) and for (HSSFCell mycell : myrow) I am getting: Can only iterate over an array or an

Java Apache POI newline characters are ignored when writing to XWPFTable cell

随声附和 提交于 2019-12-22 02:06:07
问题 Hoping someone might have some experience with this. I'm using Apache POI 3.8b4 to output a table in Word 2007 format. When I do something similar to the following: XWPFTableRow row = table.getRow(0); String text = "A\nB\nC\nD"; row.getCell(i).setText(text); all of my line breaks are ignored in the output in the table cell looks like A B C D Does anyone have any idea how to get it to properly display as A B C D Edit: The solution was the following: XWPFParagraph para = row.getCell(i)

difficulty sending Excel Workbook from Servlet

自古美人都是妖i 提交于 2019-12-22 01:43:11
问题 My project involves creating an HTML page that has a Table and placing a button on the page labelled "Export To Excel". The whole purpose is to convert the Table data into an Excel file that can be downloaded from the servlet. Using JQuery I had no problem collecting all the data from the Table and sending it off to the Servlet using the following code: $("#export").click(function(){ var head = JSON.stringify({ header: header }); var table = JSON.stringify({ data: data }); //Combine the two

Setting background custom color not working for XSSF in Apache POI

落花浮王杯 提交于 2019-12-22 01:06:23
问题 I wrote code which should create an Excel file (xlsx or xls) and set a custom background color to cell. When creating the xls file the background color works fine, but in case of xlsx the background color is not set to the right color. What is wrong in my code? public class PoiWriteExcelFile { static Workbook workbook; static Sheet worksheet; public static void main(String[] args) { try { String type = "xlsx"; //xls FileOutputStream fileOut = new FileOutputStream("D:\\poi-test." + type);

How to format a column instead of cell in POI hssf

折月煮酒 提交于 2019-12-22 00:35:47
问题 I'm facing an issue when opening a excel file with hundreds/thousands of rows of data, "Too Many Different Cell Formats" More info about the error http://excelzoom.com/2009/09/the-mystery-of-excels-too-many-different-cell-formats/ So I'm trying to format a column not a cell. The only way I can figure out how to format a column is by formating each individual cell; by implementing the code listed below. I would like to format a column instead of a row. I have hundreds/thousands of rows of data