I have a cell that should contain rather long text with multiple \n.
I'm using setWrapText(true) on a cell style object but it seems not working.
I still can only see the first line of a cell text.
Here is the code I'm using
CellStyle mainHeaderCellStyle = wb.createCellStyle();
mainHeaderCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
mainHeaderCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
mainHeaderCellStyle.setWrapText(true);
Cell headersCell = infoRow.createCell(cellIndex);
headersCell.setCellStyle(mainHeaderCellStyle);
headersCell.setCellValue(mainHeader);
But the header cell (colored in grey) is still like this
XLSX page with header
This is the text when I double click the cell
XLSX page with clicked header
deHaar answer is the correct one. Resizing row height helped to fix the problem.
The working code is this
Row infoRow = companyDataSheet.createRow(currentRowIndex++);
CellStyle mainHeaderCellStyle = wb.createCellStyle();
mainHeaderCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
mainHeaderCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
mainHeaderCellStyle.setWrapText(true);
Cell headersCell = infoRow.createCell(cellIndex);
headersCell.setCellStyle(mainHeaderCellStyle);
headersCell.setCellValue(mainHeader);
infoRow.setHeight((short) 2300);
Related
I'm using itext5 and when I set the border width for the table I get an issue like below:
This way I used to making the pdf cell:
PdfPCell cell = new PdfPCell(new Phrase("SUBSTATION",f));
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setColspan(2);
cell.setBorderWidth(2);
cell.setFixedHeight(30f);
table.addCell(cell);
and for the second cell should be under the complete border surrounded i used the following code:
cell.setBorderWidthLeft(2);
How can I modify this issue?
In Apache POI 4.0 I want to set an Excel cell background color like this :
IndexedColorMap colorMap = workbook.getStylesSource().getIndexedColors();
style.setFillForegroundColor(new XSSFColor(java.awt.Color.BLUE, colorMap).getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Row header = sheet.createRow(0);
header.createCell(0).setCellValue("Title");
header.getCell(0).setCellStyle(style);
.. but all I get are black cells. I've tried many things, but result is always the same.
How can I set the background color of an Excel cell in Apache POI 4.0 ?
Try to use below code for background style
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
I am trying to generate a pdf using Itext.where i need to build a table with header. But i am adding all the content on the page dyamically by iterating the list and adding the cells to the Table ,and finally adding table to the Document after the interation is done.
document.add(table);
My writer and document doesnt show me a updated page number if my content is moved on to the next page,until the table content is added to the document.I need to iterate and build the dynamic table where at the begining of the next page it should have the header of the table.I tried my level best following many approaches.But,I am unable to know when the content is moved on to next page in the middle of the iteration process.PDFWriter is showing me the page number before entering the loop.I need to get the updated pagenumber when ever the tables content goes on to next page.And i dont need this header to be on all pages.I need it only until the table content carries over.Please let me know which is the best way to handle this situation. Thanks
The other answer to this question isn't a real answer, it refers to an answer to another question. If that is actually the answer to this current question, the current question should have been marked as duplicate.
This being said, I think the answer is not entirely correct. I have written an example that produces something like this:
As you can see, there is no header on the first page, there is only a header on the second and third page that says "Table XYZ (Continued)". I even added a footer that says "Continue on next page". As you can see, this footer only appears at the moment the table is split. It isn't present on the last page. This wasn't asked in the question, and it is easy to remove from my code.
You can find the complete code sample here: SimpleTable5
These are the relevant parts:
PdfPTable table = new PdfPTable(5);
table.setWidthPercentage(100);
PdfPCell cell = new PdfPCell(new Phrase("Table XYZ (Continued)"));
cell.setColspan(5);
table.addCell(cell);
cell = new PdfPCell(new Phrase("Continue on next page"));
cell.setColspan(5);
table.addCell(cell);
table.setHeaderRows(2);
table.setFooterRows(1);
table.setSkipFirstHeader(true);
table.setSkipLastFooter(true);
for (int i = 0; i < 350; i++) {
table.addCell(String.valueOf(i+1));
}
document.add(table);
If you only want a header:
PdfPTable table = new PdfPTable(5);
table.setWidthPercentage(100);
PdfPCell cell = new PdfPCell(new Phrase("Table XYZ (Continued)"));
cell.setColspan(5);
table.addCell(cell);
table.setHeaderRows(1);
table.setSkipFirstHeader(true);
for (int i = 0; i < 350; i++) {
table.addCell(String.valueOf(i+1));
}
document.add(table);
The difference with your code, is that you add the following line to avoid that the header appears on the first page:
table.setSkipFirstHeader(true);
This is not mentioned in the answer to Repeat PdfPTable header in all the continuation pages using iText
I have got two doubts. I have created a word document with a table in Apache POI.
How to underline text?
XWPFRun rh = para.createRun();
rh.setText("Added to Watchlist");
rh.setBold(true);
I have created a text content and I have bolded it. How to underline it? I found a function rh.setUnderline
What is the parameter for rh.setUnderline()
how to hide table border in Apache POI?
XWPFTable table = doc.createTable(5, 5);
I want to hide the border of this table? How do I it?
You could try:
table.getCTTbl().getTblPr().unsetTblBorders();
For the first question, rh.setUnderline(UnderlinePatterns.SINGLE) or any other parameters depending on the underline style will work.
This is answer for how to set underline in text. You can try this:
XWPFParagraph subparacenter = document.createParagraph();
subparacenter.setAlignment(ParagraphAlignment.LEFT);
**XWPFRun subcenterRun = subparacenter.createRun();**
subcenterRun.setUnderline(UnderlinePatterns.SINGLE);
subcenterRun.setFontSize(11);
I have created Excel file using "HSSFWorkbook" in my project.
Whenever the user opens the Excel file it should display in "Page Layout" view i.e. the user should able to view entire page info including header, footer. However, I have tried in different ways but I couldn't do.
Its not much clear for me, but if you want to fit the entire sheet in one page then you should do something like:
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("format sheet");
PrintSetup ps = sheet.getPrintSetup();
sheet.setAutobreaks(true);
ps.setFitHeight((short)1);
ps.setFitWidth((short)1);