how can I set paragraph property "Keep with next" in POI XWPF?
I tried to look for an example, but I did not find.
I would like to have a Title paragraph together with your "body" paragraph.
In Word, you can specify a property in Paragraph Dialog called "Keep with next".
How can I do it in POI XWPF?
You can set a paragraph to a style that includes Keep with next. For example the Heading# styles default to Keep with next.
Otherwise you will have to use the CT classes like this
CTP ctP = xwpfParagraph.getCTP();
CTPPr ctPPr = ctP.isSetPPr() ? ctP.getPPr() : ctP.addNewPPr();
CTOnOff keepNext = CTOnOff.Factory.newInstance();
keepNext.setVal(STOnOff.ON);
ctPPr.setKeepNext(keepNext);
Related
Does anyone know if it is possible to re-position (or set the height of) a footer using PHPWord?
I have a footer exactly as required in terms of text.
$footer = $section->addFooter();
$textrun = $footer->addTextRun();
$textrun->addText('My Footer Text');
However, what I'd like to achieve is to:
Reduce the height of the footer or set the distance from bottom of the page.
There in an option in Word365 called "Footer from bottom", there are also similar options in older versions of Word.
I've tried adjusting the page margins but these appear to be separate from the footer (and header) positioning.
I managed to find a solution by reviewing the GitHub repo.
This commit provides a solution: Added support for page header & page footer height
You can pass the attributes "headerHeight" & "footerHeight" when you create the section that contains your header and footer.
// Adding an empty Section to the document...
$section = $this->_phpWord->addSection(array(
'headerHeight' => 300,
'footerHeight' => 50)
);
$footer = $section->addFooter();
$textrun = $footer->addTextRun();
$textrun->addText('My Footer Text');
There are also some public methods for setting these values after you've created your section, these are: setFooterHeight() and setHeaderHeight().
$section->setHeaderHeight(300);
$section->setFooterHeight(50);
I want to generate different headers in first page and other pages in poi word, So I used XWPFHeaderFooterPolicy.FIRST and XWPFHeaderFooterPolicy.DEFAULT. when I using XWPFHeaderFooterPolicy.DEFAULT I can insert my header successfully, but when I change to XWPFHeaderFooterPolicy.FIRST, I cannot see there is a header in my first page, this is my code in below, what's wrong with it? thanks!
XWPFHeader header = headerFooterPolicy.createHeader(XWPFHeaderFooterPolicy.FIRST);
paragraph = header.createParagraph();
paragraph.setAlignment(ParagraphAlignment.LEFT);
run = paragraph.createRun();
run.setText("header");
There is nothing in that class to tell Word to display different first page headers. You will need the most recent version of POI, and then create the header from XWPFDocument using:
XWPFDocument.createHeader(HeaderFooterType.FIRST);
Otherwise you need to break into the CT classes and in the section properties set the titlePg property. I don't recommend this approach though as it is likely to change.
That there is a different header set for first page only, means not that this header will also be shown. In Word GUI there is a checkbox [x] Different First Page in Header & Footer Tools to achieve that.
And according Office Open XML Part 4 - Markup Language Reference there must a boolean XML element titlePg be set to determine that there is a title page present.
In actual final apache poi version 3.15 this XML element titlePg can only be set using underlying low level objects using doc.getDocument().getBody().getSectPr().addNewTitlePg();.
But apache poi version 3.16 Beta 2 has doc.createHeader(HeaderFooterType.FIRST); which sets titlePg flag in XML.
Complete example:
import java.io.*;
import org.apache.poi.wp.usermodel.*;
import org.apache.poi.xwpf.usermodel.*;
public class CreateWordHeaderFooterDifferent {
public static void main(String[] args) throws Exception {
XWPFDocument doc= new XWPFDocument();
// the body content
XWPFParagraph paragraph = doc.createParagraph();
XWPFRun run=paragraph.createRun();
run.setText("The Body:");
paragraph = doc.createParagraph();
run=paragraph.createRun();
run.setText("Lorem ipsum.... page 1");
paragraph = doc.createParagraph();
run=paragraph.createRun();
run.addBreak(BreakType.PAGE);
run.setText("Lorem ipsum.... page 2");
paragraph = doc.createParagraph();
run=paragraph.createRun();
run.addBreak(BreakType.PAGE);
run.setText("Lorem ipsum.... page 3");
// create first page header
XWPFHeader header = doc.createHeader(HeaderFooterType.FIRST);
paragraph = header.createParagraph();
paragraph.setAlignment(ParagraphAlignment.LEFT);
run = paragraph.createRun();
run.setText("The first page header:");
// create default page header
header = doc.createHeader(HeaderFooterType.DEFAULT);
paragraph = header.createParagraph();
paragraph.setAlignment(ParagraphAlignment.LEFT);
run = paragraph.createRun();
run.setText("The default page header:");
// create footer
XWPFFooter footer = doc.createFooter(HeaderFooterType.DEFAULT);
paragraph = footer.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
run = paragraph.createRun();
run.setText("Page ");
paragraph.getCTP().addNewFldSimple().setInstr("PAGE \\* MERGEFORMAT");
run = paragraph.createRun();
run.setText(" of ");
paragraph.getCTP().addNewFldSimple().setInstr("NUMPAGES \\* MERGEFORMAT");
doc.write(new FileOutputStream("CreateWordHeaderFooterDifferent.docx"));
}
}
But in my opinion the setting titlePg flag in XML automatically while HeaderFooterType.FIRST is created is not correct. Since Word can toggle between [x] Different First Page and [] Different First Page, apache poi should also be able to do so. So the setting the titlePg flag should be a method in XWPFDocument.
I want to put a transparent label on top of a sheet in Excel, so that I can take advantage of the MouseMove event of the label to "draw cells" (aka change their fill color and so on) by mouse click / drag / etc. - since I can't do that on the cells per se.
Now everything works just fine, except that I can't make the label transparent at runtime (aka in VBA) ... while by doing exactly the same thing in Design Mode works as expected. Specifically, I have the code (more or less):
Dim MapLabel As OLEObject
On Error Resume Next
Sheet2.OLEObjects("MapLabel").Delete
Set MapLabel = Sheet2.OLEObjects.Add("Forms.Label.1")
MapLabel.name = "MapLabel"
MapLabel.Placement = xlMoveAndSize
MapLabel.Object.Caption = ""
' Problem line below
MapLabel.Object.BackStyle = fmBackStyleTransparent
' Problem line above
MapLabel.Left = Sheet2.cells(2, 6).Left
MapLabel.Top = Sheet2.cells(2, 6).Top
MapLabel.Width = Sheet2.cells(2,6).Width * 10
MapLabel.Height = Sheet2.cells(2,6).Height * 10
So, in words, I first delete the label named 'MapLabel', then recreate it (the above code goes into a "init" Sub). All the code lines except the one marked produce the desired result. The marked one does set the BackStyle property of the label to fmBackStyleTransparent ... but it doesn't actually make the label transparent. This is frustrating, because it's the same approach that works flawlessly at design time!
Do you have a solution to this? I read about solving similar problems by declaring the label as MsForms.Label or as Control, but the sheet object doesn't have those properties, plus, there are far more label properties which can be set using the OLEObject than with the help of MsForms.Label or Control.
All you need to do after this line:
MapLabel.Object.BackStyle = fmBackStyleTransparent
put this line:
ActiveSheet.Shapes(MapLabel.Name).Fill.Transparency = 1
I hope I helped.
P.S. If you need explanation i will edit my answer.
I had the same problem as you but in Word. The solution for me was to do the following:
In design mode:
Right click on the object
Navigate to Switch to automatic form/Image > Wrapping > In front of the text
Add an empty picture to your label
The title of rows in table cells is set as follows.
var source = new MvxStandardTableViewSource(TableView, "TitleText FullName");
How is a subtitle text set along with the TitleText?
If you are using a standard cell type which has a subtitle, then you can use DetailText - see the property in MvxStandardTableViewCell.cs#L73
e.g.
var source = new MvxStandardTableViewSource(
TableView,
UITableViewCellStyle.Subtitle,
"MyCellId",
"TitleText FullName; DetailText Address");
Obviously the standard cell types are fairly limited in what they can display - for more advanced applications, it's best to switch to custom cell types. There are several articles and videos about how to do this - see http://mvvmcross.wordpress.com
Hi
I am new to AS3.0, and what I am trying is to style Label, TextInput from the properties section show to the right.
But I couldnt find any alignment, font-size etc options.
How to style these components at design time, instead of AS3.0 code.
In AS3.0 you can apply these styles to your components with some lines of code. This is an example from Adobe Help
var tf:TextFormat = new TextFormat();
tf.color = 0x333333;
tf.font = "Georgia";
tf.size = 24;
tf.align = "center";
tf.italic = true;
textInput.setStyle("textFormat", tf);
More info here: http://goo.gl/dNCxe