OpenOffice java api UNO 设置属性总结
时间:2010-10-15 来源:zab08
简单备份一些重要的属性设置的java代码 和 解决openOffice java 编程的方法:
一. 重要的属性设置的java代码
1) 设置不显示虚框。一般用来 解决利用表格进行布局 时候不显示虚框的问题。(虚框怎么设置参考4)
PropertyValue[] loadProps = new PropertyValue[1];
loadProps[0] = new PropertyValue();
// 是否显示虚框
loadProps[0].Name = "isRasterVisible";
loadProps[0].Value = new Boolean(true);
2) 设置字体名称(亚洲,还有其他),字体大小
xCursorProps.setPropertyValue("CharFontNameAsian", "新宋体");
xCursorProps.setPropertyValue("CharHeightAsian", new Float(10.5));
xCursorProps.setPropertyValue("CharFontName", "Arial");
xCursorProps.setPropertyValue("CharHeight", new Float(10.5));
3)设置行据为150mm
LineSpacing lineSpacing = new LineSpacing();
lineSpacing.Mode = LineSpacingMode.PROP;
lineSpacing.Height = 150;
xCursorProps.setPropertyValue("ParaLineSpacing", lineSpacing);
4)设置表格所有边框为虚框.
TableBorder tableBorder = new TableBorder();
tableBorder.IsBottomLineValid = true;
tableBorder.IsLeftLineValid = true;
tableBorder.IsRightLineValid = true;
tableBorder.IsTopLineValid = true;
tableBorder.IsHorizontalLineValid = true;
tableBorder.IsVerticalLineValid = true;
xTableProps.setPropertyValue("TableBorder", tableBorder);
5)设置表格中字体的是否是黑体, 对齐方式。
xCellCursorProps.setPropertyValue("CharWeightAsian", new Float(0.0));
xCellCursorProps.setPropertyValue("CharWeight", new Float(0.0));
// 左对齐
xCellCursorProps.setPropertyValue("ParaAdjust", com.sun.star.style.ParagraphAdjust.LEFT);
6) 设置段落对齐方式为两端对齐
XPropertySet xWordProps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, xWordCursor);
xWordProps.setPropertyValue("ParaAdjust",
com.sun.star.style.ParagraphAdjust.BLOCK);
(ps: 段落的对齐方式,所以要划分好doc中的段落)
二.解决openOffice java 编程的方法
枚举吧,首先要看官方手册,明白了大致怎么个代码流程就可以打开doc,设置属性,然后goolge,baidu.