OpenOffice.org Code Snippets--Accessing document properties
2007-05-15 23:49
351 查看
Recently, I had the task to access document properties before converting a .xls Excel document to a .pdf document. Because , I couldn't find any code-snippets, I'm posting the code here, might be useful to other people.
Now, you'll notice the else if blocks, where I check for different document-types . Three document types are checked: TextDocument, SpreadSheets and DrawingDocument .
Code: |
Reference< XStyleFamiliesSupplier > xSupplier; Reference< XNameAccess > xFamilies; Reference< XNameContainer > xFamily; // set string for retrieval of OO styles OUString strPageStyleName( OUString::createFromAscii( "PageStyles") ); Reference< XSpreadsheetDocument > xSSDocument( xComponent, UNO_QUERY ); Reference< XTextDocument > xTextDocument( xComponent, UNO_QUERY ); Reference< XDrawPagesSupplier > xDrawPagesSupplier( xComponent, UNO_QUERY ); if ( xSSDocument.is() ) { xSupplier = Reference<XStyleFamiliesSupplier>( xSSDocument,UNO_QUERY ); } else if ( xTextDocument.is() ) { // TextDocuments xSupplier = Reference< XStyleFamiliesSupplier >( xTextDocument,UNO_QUERY ); } else if ( xDrawPagesSupplier.is() ) { // DrawingDocuments Reference< XDrawPages > xDrawPages = xDrawPagesSupplier->getDrawPages(); if ( xDrawPages.is() ) { // get the page count for standard pages int nPageCount = xDrawPages->getCount(); for( int i = 0; i < nPageCount; i++ ) { Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( i ), UNO_QUERY ); if ( xDrawPage.is() ) { Reference< XPropertySet > xStyleProps( xDrawPage, UNO_QUERY ); if ( xStyleProps.is() ) { Any Width = xStyleProps->getPropertyValue(OUString::createFromAscii("Width")); Any Height = xStyleProps->getPropertyValue(OUString::createFromAscii("Height")); //do changes xStyleProps->setPropertyValue(OUString::createFromAscii("Width"), Width); xStyleProps->setPropertyValue(OUString::createFromAscii("Height"), Height); } } } } } // process doc families if ( xSupplier.is() ) { xFamilies = Reference< XNameAccess >( xSupplier->getStyleFamilies(),UNO_QUERY ); if ( xFamilies.is() ) { xFamily = Reference< XNameContainer >( xFamilies->getByName( strPageStyleName ), UNO_QUERY ); if ( xFamily.is() ) { Sequence<OUString> rNames = xFamily->getElementNames(); // loop trough all page-properties and setup styles where needed for( int i = 0; i < rNames.getLength(); i++ ) { Reference< XStyle > xStyle( xFamily->getByName( rNames[i] ), UNO_QUERY ); if ( ! xStyle.is() ) continue; Reference< XPropertySet > xStyleProps(xStyle, UNO_QUERY); if ( ! xStyleProps.is() ) continue; Any Width = xStyleProps->getPropertyValue(OUString::createFromAscii("Width")); Any Height = xStyleProps->getPropertyValue(OUString::createFromAscii("Height")); // do changes here... xStyleProps->setPropertyValue(OUString::createFromAscii("Width"), Width); xStyleProps->setPropertyValue(OUString::createFromAscii("Height"), Height); } } } } |
相关文章推荐
- OpenOffice.org Code Snippets--Working with a Presentation Document in C++
- OpenOffice.org Code Snippets--Get and modify the current selection in calc (in C++)
- OpenOffice.org CODE
- The OOoBean offers methods that can be applied to all OpenOffice.org document types.
- Java跨平台将word转为pdf(结合Jodconverter 和OpenOffice.org)
- OpenOffice.org
- 将OpenOffice.org变成一个文档格式转换工具
- JDBC连接OpenOffice.org中的Base数据库
- [导入]又谈OpenOffice.org的乱码问题
- 仿百度文库方案[openoffice.org 3+swftools+flexpaper](八) 之 常见问题集FAQ
- Deploy OpenOffice.org using package managers
- [导入]用openoffice.org来修复因为excel2000的bug而导致无法打开的excel文档
- [导入]深入了解OpenOffice.org(三){作者:路广}
- 关于debian下Openoffice.org乱码、方块菜单
- kubuntu 5.10下 升级OpenOffice.org2.0.1对firefox的影响
- 深入了解OpenOffice.org(一)
- Java跨平台将word转为pdf(结合Jodconverter 和OpenOffice.org)
- 回应《OpenOffice.org与智能文档和电子出版》
- 安装openoffice.org,mplayer时碰到的问题
- OpenOffice.org 更新至 3.0.0