I have a header which I need to set on every page that is printed on a dynamic excel sheet.
Is there any way to get the page number ?
As from swamy's comment the solution is to get the HSSFHeader from the HSSFSheet
HSSFHeader header = sheet.getHeader();
Then you can set left, center and right text including font, font style, font size, page number, date, time etc.
Example
header.setCenter(HSSFHeader.font("Calibri", "regular") +
HSSFHeader.fontSize((short) 14) + "My " + HSSFHeader.startBold() + "Styled" +
HSSFHeader.endBold() + " Text with page number " + HSSFHeader.page());
Result
Related
I am using Apache POI SXSSF to generate xlsx document. The document uses Times New Roman sizes 9 and 11, and the default cell width and height have been changed. The question is how to calculate the height of the merged cells so that all the text fits (the height of the cell must be dynamically set according to the given text)? The server running the application does not have a display, and this code is running in the IBM Integration Bus.
The solution from How to get the needed height of a multi line rich-text field (any font, any font size) having defined width using Java? is not suitable. The server running the application is missing a display and the string int ppi = java.awt.Toolkit.getDefaultToolkit().getScreenResolution(); returns an exception, and manually picking the ppi value is also not possible. If there is a display, everything works correctly.
And is there any way to use the "align center selection" function somehow?
I found that centering a selection gives a similar result as merging multiple cells horizontally, but I couldn't find an answer anywhere on how to use this in Apache POI. As a result, experimentally, I found out that in order to achieve this effect, you need to do the following things:
Create CellStyle; specify setWrapText(true) and setAlignment(HorizontalAlignment.CENTER_SELECTION) for it
Apply the style created in step 1 to all cells that need to be merged
Specify the value in the first cell
Code example:
Font font = wb.createFont(); // where wb - is SXSSFWorkbook object
font.setFontName("Times New Roman");
font.setFontHeightInPoints((short) 11);
CellStyle style = wb.createCellStyle();
style.setFont(font);
style.setWrapText(true);
style.setAlignment(HorizontalAlignment.CENTER_SELECTION);
for (int i = 0; i <= endCellNum - firstCellNum; i++){ // where endCellNum - number of last cell of selection and firstCellNum is number of first cell of selection
Cell cell = curRow.createCell(firstCellNum + i);
cell.setCellStyle(cs);
if (i == 0){
firstCell = cell;
}
}
firstCell.setCellValue(value);
In my XPages application I am displaying a list of objects via the xp:repeat control.
I also use the xe:pagerAddRows control to add an X numbers of rows to the repeat control.
In the text of the xe:pagerAddRows control I want to display how many more items there are. Therefor I need to know the number of rows currently displayed in the repeat control.
How must I do this?
I am using this:
var text = strings["btn_show_more"]
var dv = getComponent('rptHistory');
return text + " (" + (dv.getRowCount() - dv.getRows()) + ")";
More on the add rows control can be read here https://xcellerant.net/2013/08/07/xpages-data-views-5-pager-add-rows-control/
I want the textview to add more line of code instead of changing/seting the text. The code below get called by a loop. The problem is only the last player's average score gets shown because the code changes the text per increment in loop and doesn't add the text below the previous text. I want each players average score to be displayed on the next line.
int average = playerTotalScore.get(player)/getRowSize();
textArea.setText(player + " average score: " + average);
Read out the current text value, append and set it:
String content = textArea.getText() + "\n" + player + " average score: " + average;
textArea.setText(content);
Hi
I am using following code to append text and I want to change the color of newly appended text how is it possible
if (strMessage.IndexOf("pvt|") == -1)
{
string[] temp = strMessage.Split(new string[] {"&^:^&"}, tringSplitOptions.None);
strMessage = temp[0] + "(" + DateTime.Now.ToString("HH:mm tt") + ")" + ":" + emp[1];
txtLog.AppendText(strMessage + "\r\n");
}
Please help..
Where is the text being displayed? It appears that it goes to a TextBox, but that's just an assumption.
Changing the color of individual chunks of text within a normal TextBox is not possible. You can change the entire TextBox's forecolor by setting its ForeColor property.
txtLog.ForeColor = Color.Red;
To change pieces of it individually, then you will need to use a different textbox, such as shown in the answer here.
Assuming that txtLog is a text file you would have to encode ascii control characters into stream and have an editor that read them. This link might help.
I have a report with a lot of formulas that translate the word "TRUE" into an "X" and "FALSE" into a blank space.
I use these to put an "X" in a checkbox.
Sometimes there is text after my checkbox. To avoid slight shifts to the left and right, I print the "X" and the " " in a fixed width font. It is very tedious to manually set the font for each field.
Is there a way to specify a display font from inside the formula?
Something like this would be nice:
DisplayFontName = "Courier New"; //wishful thinking
DisplayFontSize = 8; //wishful thinking
//this is the code I'm currently using
if Uppercase({table.somefield}) = "TRUE" then "X"
else " "
No, this is not possible. The context of a formula is the property for which the formula is set only. You cannot access properties of the whole object e.g. a field. Perhaps you could think about using two images suppressed by a formula depending on the value of your field. Then you would get rid of the font problem.
From what I remember, you can set the Font using formula field where you can write
if Uppercase({table.somefield}) = "TRUE" then "Courier New"