// create a text cursor from the cells XText interface
Reference< XTextCursor > xTextCursor = xText->createTextCursor();
// Get the property set of the cell’s TextCursor
Reference< XPropertySet > xTextCursorProps(xTextCursor,UNO_QUERY);
// Page Style name
//*** I add a intermediate variable because of Any type returned by getPropertyValue
Any pageStyleName2 = xTextCursorProps->getPropertyValue
(OUString::createFromAscii(“PageStyleName”));
OUString pageStyleName;
pageStyleName2 >>= pageStyleName ;
// Get the StyleFamiliesSupplier interface of the document
Reference< XStyleFamiliesSupplier > xSupplier(xTextDocument,UNO_QUERY);
// Use the StyleFamiliesSupplier interface to get the XNameAccess interface of the
// actual style families
Reference< XNameAccess > xFamilies(xSupplier->getStyleFamilies(),UNO_QUERY);
// Access the ‘PageStyles’ Family
Reference< XNameContainer > xFamily(xFamilies->getByName
(OUString::createFromAscii(“PageStyles”)),UNO_QUERY);
// Insert the newly created style into the PageStyles family
Reference< XStyle > xStyle(xFamily->getByName(pageStyleName),UNO_QUERY);
// Get the property set of the TextCursor
Reference< XPropertySet > xStyleProps(xStyle,UNO_QUERY);
Any lm, rm, bm;
lm<<=(short)1200; rm<<=(short)1200; bm<<=(short)1200;
xStyleProps->setPropertyValue(OUString::createFromAscii(“LeftMargin”),lm);
xStyleProps->setPropertyValue(OUString::createFromAscii(“RightMargin”),rm);
xStyleProps->setPropertyValue(OUString::createFromAscii(“BottomMargin”),bm);
因为对any类型的理解不深入,我不知道如何直接使用any变量,所以我用了三个临时any变量,见最后三行