Mark,
Thank you for all of your assistance lately!
FYI - Another reason for the state of HWPF is that the original
developer of it was hired by Microsoft putting him under NDA and
unable to continue.
Help and clean up of the HWPF api is certainly welcome - XWPF work is
planned after 3.5-FINAL and it would be good to have the APIs in sync
in a similar way to HSSF/XSSF. Volunteers should make themselves known
on the Dev list.
Regards,
Dave
On Jun 11, 2009, at 9:09 AM, MSB wrote:
In HWPF's defence, I do have to say that the documentation is very
clear that
it is still in the early stages of development. Try not to forget
that when
work began, Microsoft kept all of the details about the OLE2CDF file
format
secret; this was well before they had been compelled to publish this
sort of
information and as a result, people had to reverse engineer the
format. The
original lead developer had to quit because - as I understand it -
he went
to work for a company that had signed a non disclosure agreement with
Microsoft and work on HWPF thus went into hiatus. This is most
likely why
some of the classes could do with re-factoring.
Having said that, if you really do want to do more detailed work on
Word
documents, and time is pressing then your best bet is to use
OpenOffice.
That application exposes an API that it refers to as UNO or Universal
Network Objects. It works a little like OLE in that you are able to
use code
to grab a reference to the application and call upon the services it
provides to manipulate Word documents if you use Writer,
spreadsheets if you
use Calc and so on.
The API is quite complex and the documentation not the best but it
is quite
easy to work with. Some time ago, I wrote a search and replace
routine and,
to give you some idea, it looks like this;
// The xTextRange object will hold the search item if it is
found
XTextRange textRange = null;
// The XSearchable object will provide support for searching
the
// document whilst the XSearcDescriptior makes it possible to
// define how the search should be performed.
XSearchable docSearcher = (XSearchable)
UnoRuntime.queryInterface(
XSearchable.class, this.wordDocument);
XSearchDescriptor searchDescriptor =
docSearcher.createSearchDescriptor();
// Additional search properties.
searchDescriptor.setPropertyValue("SearchCaseSensitive",
new Boolean(caseSensitive));
searchDescriptor.setPropertyValue("SearchWords",
new Boolean(searchWords));
// Set the search String
searchDescriptor.setSearchString(searchTerm);
// Call the findFirst() method on the XSearchable object. If
an item
is
// found that matches the search string then it will be
returned and
// if not then a null value will be returned. Assuming the
term is
// found, then instance of the java.lang.Object class will be
// returned encapsulating the XTextRange object......
Object foundText = docSearcher.findFirst(searchDescriptor);
if(foundText != null) {
// So, that Object must be cast to the correct type.
textRange = (XTextRange)
UnoRuntime.queryInterface(XTextRange.class, foundText);
// Call the setString() method to replace the searchTerm
with
the
// replacementText. The javadoc for the setString() method
indicated
// that formatting would be lost but this appears not to
be the
case.
textRange.setString(replacementText);
return(true);
} else {
// If the searchTerm was not found, null will be
returned. Post
// a message indicating that the search failed.
System.out.println("The search term " + searchTerm + "
was not
found.");
return(false);
}
and gives you some idea of how UNO works. Forgive all of the
comments, it
was to show another developer how UNO hung together.
Alternatively, you could offer to help develop HWPF further!!
Yours
Mark B
mstocker wrote:
mstocker <maxstocker <at> gmail.com> writes:
I have been using HWPF for developing a little tool that I need and
mostly
it
is working fine except for two problems.
1) I am seemingly unable to detect if a table has a border or not. I
don't
care what colour it is or how large it is or anything else "fancy"
just
to
know if it is there or not.
Well I think is doomed. I looked at the source for BorderCode and
nothing
good
is in there. Whatever the signal is for Word to draw a border
around a
table
is the values in BorderCode don't represent it because all I get is
zeros.
The
only thing that ever causes a change is using different border
colors.
As an aside, man, this API needs a clean-up, what +is+ up with all
the
private
final static variables that are never used? :blink:
I'm going to look inside TableCellDescriptor and see if there is
anything
good
in there. I don't know where else this information might be
although it
must
be somewhere...
2) Getting the colour used for a CharacterRun.
And from my further reading this also seems hopeless.
This is too bad. But I think I'm stuck unless I actually start
ripping
apart
the doc myself.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
--
View this message in context:
http://www.nabble.com/HWPF---table-borders-and-document-colors-tp23967926p23984341.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]