How can i change text orientation in XWPFDocument? - java

I am working right now in producing word documents in java and i am using XWPFDocument of POI Apache. The final document must looks like this
http://sk.uploads.im/t/rtwvm.png
till no everything works fine, I created table, managed to merge cells but i can not find a way to change the text orientation in table cells. I simply want "Type 1" to be upward.
I only found a solution using cellStyle which seems to work only in excel and not in word, which i am using.

You probably need to create two documents in Word, one with the normal orientation and one with the changed one, then unzip them (.docx is actually a Zip-File) and analyze which xml-structure is responsible for this.
Then you can check if POI already offers higher level APIs for these or if you need to access the low-level POI classes via the getCTxxx() methods, e.g. XWPFTableCell.getCTTc() returns the underlying XML structure and allows you to do things that are not possible via the normal POI interfaces.

You can use something like: cell.getCTTc().getTcPr().addNewTextDirection().setVal(STTextDirection.BT_LR),
where the parameters are found in: STTextDirection.
The problem I couldn't solve yet is that the row height does not update automatically to the vertical text length, then the text is not completely showed. If you solve it, please, post here.

Related

Make existing PDF's in to templets - iText

I am trying to make some existing PDF's into templets.
Because these documents hold real data I am replaceing this data such as names and addrsss and making them into dummy place holders.
Examples
[[Name]]
[[Address1]]
When I alter the text via the iText version 5 library replace via a program I can use the template.
To speed things up I tried to use Adobe DC.
When using this method the template stops working.
Any ideas?
From what I understand of your question;
you have (or want to have) a template document
fill in the template with data from a program
turn this back into a pdf
You can easily achieve some of your goals with iText.
I suggest you look into http://developers.itextpdf.com/examples/form-examples/clone-filling-out-forms

Creating word document from a template using java

I want to create a word document which has a text part, checkboxes and tables in it. I want to create a template of this document and use the template to create a word document using java.
Can anyone please suggest me an easiest way to do the same. I tried doing xml mapping but it only works fine with text and tables. I am more concerned about the checkboxes in the word document.
Please help!
I had a play with a bound checkbox content control.
I found that Word updates the custom xml part when you check/uncheck the checkbox on the document surface, but that the checkbox doesn't automatically update when you change the value in the custom xml part outside word. Nor is it enough to update the checked state (w14:checkbox/w14:checked) outside Word 2010: it seems to be ignored.
In other words, unlike for bound text content controls, the update isn't bi-directional.
So to make this work, you'd need to apply the binding yourself (ie alter the sdtContent to be a checked or unchecked box).
In terms of Java implementations, docx4j 2.7.1 can apply bindings for text content controls, but would need a minor patch to insert the checked or unchecked box.
JDReports and Docmosis might help you. I think both can do what you require given the template requirement and output format.

POI dynamic templates

Can anyone tell me where do I find some useful documentation on handling copying rows, cells, columns from one excel file to another, using POI?
I need to insert in one blank excel file, 2 or more templates from other files, dynamic.
I also need to keep all the styles made for the group of cells that I copy. How can I do that? Nothing found on apache poi tutorial on this point.
I am using POI 3.0.1.
Thank you!
I assume the problem is data types and merged cells? It's easy enough to get and set styles and set values.
Depending on your use case, you might be able to take entire sheets from the original document, assemble the new document from those and tweak it to your liking. Even if you have to combine multiple source sheets into one target sheet, you might still be able to retrieve source rows and assemble the target document from those rows.
...that was me some time ago...
I never could copy from one excel file to another with the exact style, but I found a solution : I used multiple worksheets instead of multiple excel files, cause style has no problem in being copied from one sheet to another as long as it is in the same workbook.
I also migrated from POI3.0.1 to POI 3.6. Far much better.

Apache POI HSSF/XSSF - Evaluating Formulas That Don't Live In Cells

With a known formula extracted from a spreadsheet, is it possible to apply/evaluate the formula without having it reside in an actual cell?
I suppose one can create / locate a blank cell on the sheet (anyone have any ideas how this might be done efficiently?) and evaluate the formula this way, but is there a better way?
I'm not sure that POI is the way to do for this, given that it looks after creating/reading/writing spreadsheets. Have you looked at invoking the Excel COM object (via, say, JACOB), and running the formulas in Excel itself ?
Excel does let you evaluate a formula without it having to reside in a cell. You can do it via the old XLM macro language with EVALUATE or through the C API, and via VBA with Application.Evaluate or Worksheet.Evaluate.
Of course, that information might be of no help if all you have is the extracted formula and not access to Excel. If you know the formulas will be simple enough, I can see evaluating them yourself or with another tool (although I don't know of anything specific). In general, though, you will need not only access to Excel, but also the actual document the formulas are in, since a formula can call user-written VBA/XLL functions, use defined names, etc.

Format Java Code into Word / RTF

I need to format java code to put into a Word document. Are there any programs that will do this with keyword highlighting, etc. ?
When I copy/paste from my IDE (Eclipse), the formatting comes along for the ride.
You'll probably want to turn off "Mark Occurrences" first.
This is a late reply but since it's quite a specific requirement I'll post my comment anyway.
You can do this programmatically with Docmosis assuming you want the program to be running in Java (not just showing java in documents) and can install OpenOffice where the program runs. The process would be:
Create a doc or odt file that will
act as a template (setting fonts,
position, tables etc) and will have
a placeholder for where you want to
insert the code sample
Add docmosis to your java project
and write the code to initialise
Docmosis, register the template,
then render document with your
selected Java code.
Currently, Docmosis FieldRenderers
can underline or italicize your data
as it goes, but the rendering is
currently applied to the entire
field. So this wouldn't let you
have a single field for all your
java text and individually highlight
words, but there are a few other
tricks that you could employ to get
useful/interesting results (such as
splitting your data into separate
fields and letting Docmosis render
the fields differently).
The "java code" text that you specify as data will be inserted into your template using the font and layout properties in the template. The renderer will have a chance to override specific formatting.
You can just copy and then paste it to the word document. I am using OS X as well. I just works fine. I am uploading the screenshot of how it looks in word.
I'm using Easy Code Formatter as called out here: How do you display code snippets in MS Word preserving format and syntax highlighting?
It's an Office add-in. You can select multiple themes, enable / disable line numbering / highlight lines in rectangles. It allows you to select the coding style / and has a quick formatting button. Pretty neat.
Requires you to have Office 2013 or beyond.

Categories

Resources