C++调用Libreoffice接口
作者:互联网
由于部分原因,只提供cpp文件,其中代码还需要优化
- 其中主要涉及了Excel的创建
- Sheet页的增加、删除、重命名
- 表格的合并
- 表格背景、边框部分属性的设置
- 表格内字体部分属性设置
- 表格内容的读取和插入(其中插入操作还需要优化)
- 缺点:有部分代码重复,还需要整合
- 缺点:创建Libreoffice的进程后,没有释放,只能在后期根据Linux的命令进行释放,其中并没有提供Windows释放的代码
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include <iostream>
#include <osl/file.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XTitle.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
#include <com/sun/star/sheet/XCellRangesQuery.hpp>
#include <com/sun/star/sheet/CellFlags.hpp>
#include <com/sun/star/sheet/XSheetOperation.hpp>
#include <com/sun/star/table/TableBorder.hpp>
#include <com/sun/star/table/XColumnRowRange.hpp>
#include <com/sun/star/table/XMergeableCell.hpp>
#include <com/sun/star/table/XMergeableCellRange.hpp>
#include <com/sun/star/table/CellRangeAddress.hpp>
#include <com/sun/star/table/XCell.hpp>
#include <com/sun/star/table/CellHoriJustify.hpp>
#include <com/sun/star/table/CellVertJustify.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/Color.hpp>
#include <com/sun/star/util/XMergeable.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/sheet/XCellRangeData.hpp>
#include <com/sun/star/registry/RegistryValueType.hpp>
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::UNO_QUERY;
using zgis::QCxExcel;
QCxExcel::QCxExcel()
{
m_pInstance = NULL;
m_pComponent = NULL;
}
QCxExcel::~QCxExcel() { ReleaseAplication(); }
bool QCxExcel::CreateAplication(bool bVisible, bool bDispAlert)
{
try {
Reference< ::com::sun::star::uno::XComponentContext > rComponentContext( ::cppu::bootstrap() );
if ( !rComponentContext.is() ) { return false; }
Reference< ::com::sun::star::lang::XMultiComponentFactory > rFactory( rComponentContext->getServiceManager() );
if ( rFactory.is() )
{
Reference< XInterface > rInstance( rFactory->createInstanceWithContext( "com.sun.star.frame.Desktop", rComponentContext ) );
if ( rInstance.is() ) {
rInstance->acquire();
m_pInstance = rInstance.get();
}
}
return ( NULL != m_pInstance );
} catch ( ... ) { return false; }
}
void QCxExcel::ReleaseAplication()
{
if ( NULL != m_pInstance )
{
static_cast< XInterface * >( m_pInstance )->release();
m_pInstance = NULL;
if ( !system( "soffice_pid=$(pidof soffice.bin); if [ $soffice_pid ]; then kill $soffice_pid > /dev/null 2>&1; fi" ) )
return;
}
}
void * QCxExcel::OpenWorkBook( const QString & strExcelPath )
{
try {
::rtl::OUString sURL( "private:factory/scalc" );
if ( !strExcelPath.isEmpty() ) // file:///home
{
QString str = "file://" + strExcelPath;
sal_Char * s = str.toUtf8().data();
sURL = ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8);
}
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lArguments(1);
lArguments[0].Name = "Hidden";
lArguments[0].Value <<= true;
Reference< ::com::sun::star::frame::XComponentLoader > rComponentLoader( static_cast< XInterface * >( m_pInstance ), UNO_QUERY );
if ( rComponentLoader.is() )
{
Reference< ::com::sun::star::lang::XComponent > rComponent( rComponentLoader->loadComponentFromURL( sURL, "_blank", 0, lArguments ) );
if ( rComponent.is() ) {
rComponent->acquire();
m_pComponent = rComponent.get();
}
}
return m_pComponent;
} catch ( ... ) { return NULL; }
}
void * QCxExcel::CreateWorkBook() { return OpenWorkBook( QString() ); }
QString QCxExcel::GetTitel()
{
try {
Reference< ::com::sun::star::frame::XTitle > mTitle( static_cast< ::com::sun::star::lang::XComponent * >( m_pComponent ), UNO_QUERY );
return ( !mTitle.is() ) ? "" :
::rtl::OUStringToOString( mTitle->getTitle(), RTL_TEXTENCODING_UTF8 ).pData->buffer;
} catch ( ... ) { return ""; }
}
void QCxExcel::UpdateTitel( const QString & strTitle )
{
if ( strTitle.isEmpty() ) return;
try {
Reference< ::com::sun::star::frame::XTitle > mTitle( static_cast< ::com::sun::star::lang::XComponent * >( m_pComponent ), UNO_QUERY );
sal_Char * s = strTitle.toUtf8().data();
if ( mTitle.is() ) mTitle->setTitle( ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8) );
} catch ( ... ) {}
}
void QCxExcel::Save( void * pWorkBook )
{
if ( NULL == pWorkBook ) return;
SaveAs( pWorkBook, QString() );
}
void QCxExcel::SaveAs( void * pWorkBook, const QString & strExcelPath )
{
if ( NULL == pWorkBook ) return;
try {
Reference< ::com::sun::star::frame::XStorable > rStorable( static_cast< ::com::sun::star::lang::XComponent * >( m_pComponent ), UNO_QUERY );
if ( rStorable.is() && ! strExcelPath.isEmpty() )
{
QString excelPath = strExcelPath + ".xlsx";
sal_Char * s = excelPath.toUtf8().data();
::rtl::OUString ustrFileURL = ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8 );
::osl::FileBase::getFileURLFromSystemPath( ustrFileURL, ustrFileURL );
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lArguments( 2 );
lArguments[0].Name = "Overwrite";
lArguments[0].Value <<= true;
lArguments[1].Name = "FilterName";
lArguments[1].Value <<= ::rtl::OUString( "MS Excel 97" );
// rStorable->storeAsURL( ustrFileURL, lArguments )
rStorable->storeToURL( ustrFileURL, lArguments ); // Still open the old file
return;
}
rStorable->store();
} catch ( ... ) {}
}
bool QCxExcel::IsOpend() { return ( NULL != m_pInstance ); }
void QCxExcel::Close( void * pWorkBook )
{
m_pComponent = static_cast< ::com::sun::star::lang::XComponent * >( pWorkBook );
if ( NULL != m_pComponent ) {
::com::sun::star::lang::XComponent * pComponent = static_cast< ::com::sun::star::lang::XComponent * >( m_pComponent );
pComponent->dispose();
pComponent->release();
m_pComponent = NULL;
}
}
void * QCxExcel::GetSheets( void * pWorkBook )
{
if ( NULL == pWorkBook ) return NULL;
try {
Reference< ::com::sun::star::sheet::XSpreadsheetDocument > rSheetDoc(
static_cast< ::com::sun::star::lang::XComponent * >( pWorkBook ), UNO_QUERY );
Reference< ::com::sun::star::sheet::XSpreadsheets > rSheets( rSheetDoc->getSheets() );
if ( rSheets.is() ) rSheets->acquire();
return rSheets.get();
} catch ( ... ) { return NULL; }
}
int QCxExcel::GetSheetCount( void * pWorkBook )
{
if ( NULL == pWorkBook ) return 0;
try {
::com::sun::star::sheet::XSpreadsheets * rSheets = static_cast< ::com::sun::star::sheet::XSpreadsheets * >( GetSheets( pWorkBook ) );
Reference< ::com::sun::star::container::XIndexAccess > rIndexAccess( rSheets, UNO_QUERY );
rSheets->release();
return rIndexAccess.is() ? rIndexAccess->getCount() : 0;
} catch ( ... ) { return 0; }
}
void * QCxExcel::GetSheet( void * pWorkBook, int nCount )
{
if ( NULL == pWorkBook ) return NULL;
try {
::com::sun::star::sheet::XSpreadsheets * rSheets = static_cast< ::com::sun::star::sheet::XSpreadsheets * >( GetSheets( pWorkBook ) );
Reference< ::com::sun::star::container::XIndexAccess > rIndexAccess( rSheets, UNO_QUERY );
rSheets->release();
if ( !rIndexAccess.is() ) return NULL;
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet( rIndexAccess->getByIndex( nCount - 1 ), ::com::sun::star::uno::UNO_QUERY );
if ( rSheet.is() ) rSheet->acquire();
return rSheet.get();
} catch ( ... ) { return NULL; }
}
QString QCxExcel::GetSheetName( void * pSheet )
{
if ( NULL == pSheet ) return "";
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
Reference< ::com::sun::star::container::XNamed > rNamed( rSheet, ::com::sun::star::uno::UNO_QUERY );
return rNamed.is() ? ::rtl::OUStringToOString( rNamed->getName(), RTL_TEXTENCODING_UTF8 ).pData->buffer : "";
} catch ( ... ) { return ""; }
}
void QCxExcel::UpdateSheetName( void * pSheet, const QString & strName )
{
if ( NULL == pSheet ) return;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
Reference< ::com::sun::star::container::XNamed > rNamed( rSheet, UNO_QUERY );
sal_Char * s = strName.toUtf8().data();
if ( rNamed.is() ) rNamed->setName( ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8) );
} catch ( ... ) {}
}
void * QCxExcel::AddSheet( void * pWorkBook, const QString & strSheetName )
{
if ( NULL == pWorkBook ) return NULL;
try {
::com::sun::star::sheet::XSpreadsheets * rSheets = static_cast< ::com::sun::star::sheet::XSpreadsheets * >( GetSheets( pWorkBook ) );
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet;
if ( NULL != rSheets )
{
sal_Char * s = strSheetName.toUtf8().data();
::rtl::OUString sheetName = ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8);
rSheets->insertNewByName( sheetName, GetSheetCount( pWorkBook ) + 1 );
rSheet.set( rSheets->getByName( sheetName ), UNO_QUERY );
rSheets->release();
}
if ( rSheet.is() ) rSheet->acquire();
return rSheet.get();
} catch ( ... ) { return NULL; }
}
void QCxExcel::DeleteSheet( void * pWorkBook, int nCount )
{
if ( NULL == pWorkBook ) return;
using ::com::sun::star::sheet::XSpreadsheets;
using ::com::sun::star::sheet::XSpreadsheet;
try {
::com::sun::star::sheet::XSpreadsheets * rSheets = static_cast< ::com::sun::star::sheet::XSpreadsheets * >( GetSheets( pWorkBook ) );
if ( NULL != rSheets )
{
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( GetSheet( pWorkBook, nCount ) ), UNO_QUERY );
sal_Char * s = GetSheetName(rSheet.get()).toUtf8().data();
rSheets->removeByName( ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8) );
rSheet->release();
rSheets->release();
}
} catch ( ... ) {}
}
void * QCxExcel::GetUsedrange( void * pSheet )
{
if ( NULL == pSheet ) return NULL;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
Reference< ::com::sun::star::sheet::XCellRangesQuery > rCellRangeQuery( rSheet, UNO_QUERY );
Reference< ::com::sun::star::sheet::XSheetCellRanges > rSheetCellRanges(
rCellRangeQuery->queryContentCells( ::com::sun::star::sheet::CellFlags::VALUE
| ::com::sun::star::sheet::CellFlags::STRING
| ::com::sun::star::sheet::CellFlags::STYLES
| ::com::sun::star::sheet::CellFlags::OBJECTS
| ::com::sun::star::sheet::CellFlags::HARDATTR
| ::com::sun::star::sheet::CellFlags::FORMATTED
| ::com::sun::star::sheet::CellFlags::FORMULA
| ::com::sun::star::sheet::CellFlags::EDITATTR
| ::com::sun::star::sheet::CellFlags::DATETIME
| ::com::sun::star::sheet::CellFlags::ANNOTATION), UNO_QUERY );
if ( rSheetCellRanges.is() ) rSheetCellRanges->acquire();
return rSheetCellRanges.get();
} catch ( ... ) { return NULL; }
}
QList< QVariantList > QCxExcel::GetUsedrangeVal( void * pSheet )
{
if ( NULL == pSheet ) return QList< QVariantList >();
try {
::com::sun::star::sheet::XSheetCellRanges * rSheetCellRanges =
static_cast< ::com::sun::star::sheet::XSheetCellRanges * >( GetUsedrange( pSheet ) );
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
QList< QVariantList > cellList;
if ( NULL != rSheetCellRanges && rSheet.is() )
{
::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress > sCellRangeAddress( rSheetCellRanges->getRangeAddresses() );
rSheetCellRanges->release();
::sal_Int32 rLen = sCellRangeAddress.getLength();
::sal_Int32 sRow = sCellRangeAddress[0].StartRow;
::sal_Int32 eRow = 0;
::sal_Int32 sColumn = sCellRangeAddress[0].StartColumn; // default startcolumn
::sal_Int32 eColumn = sCellRangeAddress[rLen - 1].EndColumn; // default endcolumn
for ( int i = 0; i < rLen; i++ )
{
::sal_Int32 nsRow = sCellRangeAddress[i].StartRow;
::sal_Int32 neRow = sCellRangeAddress[i].EndRow;
sRow = ( sRow < nsRow ) ? sRow : nsRow;
eRow = ( eRow > neRow ) ? eRow : neRow;
}
Reference< ::com::sun::star::sheet::XCellRangeData > rCellRangeData(rSheet->getCellRangeByPosition(
sColumn, sRow, eColumn, eRow),
UNO_QUERY);
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >> rCells =
rCellRangeData->getDataArray();
sRow = 0;eRow = rCells.getLength(); sColumn = 0; eColumn=rCells[0].getLength();
for ( int nRow = sRow; nRow < eRow; ++nRow ) {
QVariantList columnList;
std::cout << std::endl;
for ( int nColumn = sColumn; nColumn < eColumn; ++nColumn )
{
QString s = QString();
::com::sun::star::uno::Any aValue = rCells[nRow][nColumn];
if (aValue.getValueTypeName() == "double")
{
double value = 0;
aValue >>= value;
s = QString("%1").arg(value);
}
else
{
::rtl::OUString str;
aValue >>= str;
s = QString::fromUtf8(::rtl::OUStringToOString(
str, RTL_TEXTENCODING_UTF8).pData->buffer);
}
columnList.append(s);
}
cellList.append( columnList );
} }
return cellList;
} catch ( ... ) { return QList<QVariantList>(); }
}
QVariantList QCxExcel::GetUsedRowValues( void * pSheet, int nRow, int nStartCol, int nEndCol)
{
if ( NULL == pSheet ) return QVariantList();
nRow -= 1;
nStartCol -= 1;
nEndCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
QVariantList rowList;
if( rSheet.is() ) {
for ( int nColumn = nStartCol; nColumn <= nEndCol; ++nColumn )
{
Reference< ::com::sun::star::table::XCell > rCell = rSheet->getCellByPosition( nColumn, nRow );
QString s = QString();
if ( rCell.is() ) {
switch ( rCell->getType() ) {
case ::com::sun::star::table::CellContentType_VALUE:
rowList.append( rCell->getValue() );
break;
case ::com::sun::star::table::CellContentType_TEXT:
s = QString::fromUtf8(::rtl::OUStringToOString(
rCell->getFormula(), RTL_TEXTENCODING_UTF8).pData->buffer);
if (s.left(1) == "'" && s.mid(1).toDouble())
s.remove(0, 1);
rowList.append(s);
break;
default:
rowList.append(QString());
break;
} }
else
rowList.append( QVariant() );
} }
return rowList;
} catch ( ... ) { return QVariantList(); }
}
QVariantList QCxExcel::GetUsedColValues( void * pSheet, int nCol, int nStartRow, int nEndRow)
{
if ( NULL == pSheet ) return QVariantList();
nCol -= 1;
nStartRow -= 1;
nEndRow -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
QVariantList columnList;
if ( rSheet.is() )
{
for ( int nRow = nStartRow; nRow <= nEndRow; ++nRow )
{
Reference< ::com::sun::star::table::XCell > rCell = rSheet->getCellByPosition( nCol, nRow );
QString s = QString();
if ( rCell.is() ) {
switch ( rCell->getType() ) {
case ::com::sun::star::table::CellContentType_VALUE:
columnList.append( rCell->getValue() );
break;
case ::com::sun::star::table::CellContentType_TEXT:
s = QString::fromUtf8(::rtl::OUStringToOString(
rCell->getFormula(), RTL_TEXTENCODING_UTF8).pData->buffer);
if (s.left(1) == "'" && s.mid(1).toDouble())
s.remove(0, 1);
columnList.append(s);
break;
default:
columnList.append(QString());
break;
} }
else
columnList.append( QVariant() );
} }
return columnList;
} catch ( ::com::sun::star::uno::Exception & e ) { return QVariantList(); }
}
void QCxExcel::SetUsedrangeVal( void * pSheet, int nStartRow, int nStartCol, QList<QList<QVariant>> *pList)
{
if ( NULL == pSheet || NULL == pList ) return;
nStartRow -= 1;
nStartCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
if ( ! rSheet.is() || pList->isEmpty() ) return ;
::sal_Int32 eRow = pList->count() + nStartRow;
::sal_Int32 eColumn = pList->first().count() + nStartCol;
for ( int nRow = nStartRow; nRow < eRow; ++nRow )
{
QList< QVariant > rowList = pList->at( nRow - nStartRow );
for ( int nColumn = nStartCol; nColumn < eColumn; ++nColumn )
{
Reference< ::com::sun::star::table::XCell > rCell = rSheet->getCellByPosition( nColumn, nRow );
QVariant cell = rowList.at( nColumn - nStartCol );
QString str = "";
sal_Char * s = NULL;
switch ( cell.type() ) {
case QVariant::Invalid:
rCell->setFormula( ::rtl::OUString() );
break;
case QVariant::Int:
rCell->setValue( cell.toInt() );
break;
case QVariant::Double:
rCell->setValue( cell.toDouble() );
break;
case QVariant::String:
str = cell.toString();
if (str.toDouble() && str.contains('E', Qt::CaseInsensitive)) {
int index = str.indexOf('E', 0, Qt::CaseInsensitive);
Reference< ::com::sun::star::text::XText > rText( rCell, UNO_QUERY );
Reference< ::com::sun::star::text::XTextCursor > rCursor = rText->createTextCursor();
s = str.left(index).toUtf8().data();
rCursor->setString( ::rtl::OUString(s, index, RTL_TEXTENCODING_UTF8));
rCursor->goRight(index, false);
s = str.mid(index).toUtf8().data();
rCursor->setString( ::rtl::OUString(s, str.length() - index, RTL_TEXTENCODING_UTF8));
//rCell->setFormula( ::rtl::OUString(s, str.length() - index, RTL_TEXTENCODING_UTF8) );
}
else {
s = str.toUtf8().data();
rCell->setFormula( ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8) );
}
break;
default:
str = cell.toString();
s = str.toUtf8().data();
rCell->setFormula( ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8) );
break;
} } }
} catch ( ... ) {}
}
void * QCxExcel::GetRows( void * pUsedrange )
{
if ( NULL == pUsedrange ) return NULL;
try {
Reference< ::com::sun::star::table::XColumnRowRange > rColumnRowRange(
static_cast< ::com::sun::star::sheet::XSheetCellRanges * >( pUsedrange ), UNO_QUERY );
if ( ! rColumnRowRange.is() ) rColumnRowRange->getRows()->acquire();
return rColumnRowRange->getRows().get();
} catch ( ... ) { return NULL; }
}
void * QCxExcel::GetCols( void * pUsedrange )
{
if ( NULL == pUsedrange ) return NULL;
try {
Reference< ::com::sun::star::table::XColumnRowRange > rColumnRowRange(
static_cast< ::com::sun::star::sheet::XSheetCellRanges * >( pUsedrange ), UNO_QUERY );
if ( ! rColumnRowRange.is() ) rColumnRowRange->getColumns()->acquire();
return rColumnRowRange->getColumns().get();
} catch ( ... ) { return NULL; }
}
void QCxExcel::GetRangeCol( void * pUsedrange, int &nStartCol, int &nColCount )
{
if ( NULL == pUsedrange ) return;
try {
Reference< ::com::sun::star::sheet::XSheetCellRanges > rSheetCellRanges(
static_cast< ::com::sun::star::sheet::XSheetCellRanges * >( pUsedrange ), UNO_QUERY );
::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress > rCellRangeAddress(
rSheetCellRanges->getRangeAddresses() );
rSheetCellRanges->release();
if ( ! rCellRangeAddress.hasElements() ) return;
nColCount = rCellRangeAddress.getLength();
::sal_Int32 nLength = rCellRangeAddress.getLength();
::sal_Int32 nEndCol = 0;
nStartCol = rCellRangeAddress[0].StartColumn;
for ( int i = 0; i < nLength; ++i )
{
::sal_Int32 sCol = rCellRangeAddress[i].StartColumn;
::sal_Int32 eCol = rCellRangeAddress[i].EndColumn;
nStartCol = ( nStartCol < sCol ) ? nStartCol : sCol;
nEndCol = ( nEndCol > eCol ) ? nEndCol : eCol;
}
nColCount = nEndCol - nStartCol + 1;
nStartCol += 1;
} catch ( ... ) {}
}
void QCxExcel::GetRangeRow( void * pUsedrange, int &nStartRow, int &nRowCount )
{
if ( NULL == pUsedrange ) return;
try {
Reference< ::com::sun::star::sheet::XSheetCellRanges > rSheetCellRanges(
static_cast< ::com::sun::star::sheet::XSheetCellRanges * >( pUsedrange ), UNO_QUERY );
if ( rSheetCellRanges.is() )
{
::com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress > rCellRangeAddress(
rSheetCellRanges->getRangeAddresses() );
rSheetCellRanges->release();
if ( ! rCellRangeAddress.hasElements() ) return;
::sal_Int32 nLength = rCellRangeAddress.getLength();
::sal_Int32 nEndRow = 0;
nStartRow = rCellRangeAddress[0].StartRow;
for ( int i = 0; i < nLength; ++i )
{
::sal_Int32 sRow = rCellRangeAddress[i].StartRow;
::sal_Int32 eRow = rCellRangeAddress[i].EndRow;
nStartRow = ( nStartRow < sRow ) ? nStartRow : sRow;
nEndRow = ( nEndRow > eRow ) ? nEndRow : eRow;
}
nRowCount = nEndRow - nStartRow + 1;
nStartRow += 1;
}
} catch ( ... ) {}
}
void QCxExcel::GetCol( void * pSheet, int &nStartCol, int &nColCount )
{
if ( NULL == pSheet ) return;
GetRangeCol( GetUsedrange( pSheet ), nStartCol, nColCount );
}
void QCxExcel::GetRow( void * pSheet, int &nStartRow, int &nRowCount )
{
if ( NULL == pSheet ) return;
GetRangeRow( GetUsedrange( pSheet ), nStartRow, nRowCount );
}
void QCxExcel::SetRangeLx( void * pSheet, int nStartRow, int nStartCol, int nEndRow, int nEndCol, QVariant lxVal )
{
if ( NULL == pSheet ) return;
nStartRow -= 1;
nStartCol -= 1;
nEndRow -= 1;
nEndCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
if ( ! rSheet.is() ) return;
Reference< ::com::sun::star::beans::XPropertySet > rProperty( rSheet->getCellRangeByPosition(
nStartCol, nStartRow, nEndCol, nEndRow),
UNO_QUERY );
::com::sun::star::uno::Any aStyle;
// Result, Result2, Default, Heading, Heading1
//aStyle <<= ::rtl::OUString::createFromAscii("");
//rProperty->setPropertyValue("CellStyle", aStyle);
} catch ( ... ) {}
}
void * QCxExcel::GetCell( void * pSheet, int nRow, int nCol )
{
if ( NULL == pSheet ) return NULL;
nRow -= 1;
nCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
if ( ! rSheet.is() ) return NULL;
Reference< ::com::sun::star::table::XCell > rCell = rSheet->getCellByPosition( nCol, nRow );
if ( rCell.is() ) rCell->acquire();
return rCell.get();
} catch ( ... ) { return NULL; }
}
void * QCxExcel::MergeCells( void * pSheet, int nStartRow, int nStartCol, int nEndRow, int nEndCol )
{
if ( NULL == pSheet ) return NULL;
nStartRow -= 1;
nStartCol -= 1;
nEndRow -= 1;
nEndCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
Reference< ::com::sun::star::table::XCellRange > rCellRange( rSheet, UNO_QUERY );
if ( ! rCellRange.is() ) return NULL;
Reference< ::com::sun::star::util::XMergeable > rMergeable(
rCellRange->getCellRangeByPosition( nStartCol, nStartRow, nEndCol, nEndRow ), UNO_QUERY );
if ( rMergeable.is() )
{
rMergeable->merge( true );
rMergeable->acquire();
}
return rMergeable.get();
} catch ( ... ) { return NULL; }
}
void QCxExcel::UnMergeCells( void * pSheet, int nStartRow, int nStartCol, int nEndRow, int nEndCol )
{
if ( NULL == pSheet ) return;
nStartRow -= 1;
nStartCol -= 1;
nEndRow -= 1;
nEndCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
Reference< ::com::sun::star::table::XCellRange > rCellRange( rSheet, UNO_QUERY );
if ( ! rCellRange.is() ) return;
Reference< ::com::sun::star::util::XMergeable > rMergeable(
rCellRange->getCellRangeByPosition( nStartCol, nStartRow, nEndCol, nEndRow ), UNO_QUERY );
if ( rMergeable.is() )
rMergeable->merge( false );
} catch ( ... ) {}
}
bool QCxExcel::IsMergeCells( void * pSheet, int & nStartRow, int & nStartCol, int & nEndRow, int & nEndCol )
{
if ( NULL == pSheet ) return false;
nStartRow -= 1;
nStartCol -= 1;
nEndRow -= 1;
nEndCol -= 1;
try {
::com::sun::star::sheet::XSpreadsheet * rSheet = static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet );
for ( int nRow = nStartRow; nRow <= nEndRow; ++nRow )
{
for ( int nColumn = nStartCol; nColumn <= nEndCol; ++nColumn )
{
Reference< ::com::sun::star::util::XMergeable > rMergeable(
rSheet->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ), UNO_QUERY );
if ( rMergeable.is() )
if ( rMergeable->getIsMerged() )
{
nStartRow = nRow + 1;
nStartCol = nColumn + 1;
// wait
return true;
}
}
}
return false;
} catch ( ... ) { return false; }
}
bool QCxExcel::ContainMergeCells( void * pSheet, int nStartRow, int nStartCol, int nEndRow, int nEndCol)
{
if ( NULL == pSheet ) return false;
nStartRow -= 1;
nStartCol -= 1;
nEndRow -= 1;
nEndCol -= 1;
try {
::com::sun::star::sheet::XSpreadsheet * rSheet = static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet );
for ( int nRow = nStartRow; nRow <= nEndRow; ++nRow )
for ( int nColumn = nStartCol; nColumn <= nEndCol; ++nColumn )
{
Reference< ::com::sun::star::util::XMergeable > rMergeable(
rSheet->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ), UNO_QUERY );
if ( rMergeable.is() && rMergeable->getIsMerged() )
return true;
}
return false;
} catch ( ... ) { return false; }
}
QVariant QCxExcel::GetCellVal( void * pSheet, int nRow, int nCol )
{
if ( NULL == pSheet ) return QVariant();
nRow -= 1;
nCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
QVariant cellValue;
if ( rSheet.is() )
{
Reference< ::com::sun::star::table::XCell > rCell = rSheet->getCellByPosition( nCol, nRow );
if ( rCell.is() ) {
switch ( rCell->getType() ) {
case ::com::sun::star::table::CellContentType_VALUE:
cellValue.setValue( rCell->getValue() );
break;
case ::com::sun::star::table::CellContentType_MAKE_FIXED_SIZE:
break;
default:
cellValue.setValue( QString::fromUtf8( ::rtl::OUStringToOString(
rCell->getFormula(), RTL_TEXTENCODING_UTF8 ).pData->buffer ) );
break;
}
}
}
return cellValue;
} catch ( ::com::sun::star::uno::Exception & e ) { return QVariant(); }
}
QVariant QCxExcel::GetCellVal( void * pCell )
{
if ( NULL == pCell ) return QVariant();
QVariant cellValue;
Reference< ::com::sun::star::table::XCell > rCell(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rCell.is() ) {
switch ( rCell->getType() ) {
case ::com::sun::star::table::CellContentType_VALUE:
cellValue.setValue( rCell->getValue() );
break;
case ::com::sun::star::table::CellContentType_MAKE_FIXED_SIZE:
break;
default:
cellValue.setValue( QString::fromUtf8( ::rtl::OUStringToOString(
rCell->getFormula(), RTL_TEXTENCODING_UTF8 ).pData->buffer ) );
break;
}
}
return cellValue;
}
QFont QCxExcel::GetCellFont( void * pCell )
{
if ( NULL == pCell ) return QFont();
try {
Reference< ::com::sun::star::beans::XPropertySet > rPropertySet(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
QFont cellFont;
if ( rPropertySet.is() )
{
::rtl::OUString fontName("");
float charHeight = 0;
float charWeight = 0;
::com::sun::star::awt::FontSlant fontSlant;
rPropertySet->getPropertyValue( "CharFontName" ) >>= fontName;
rPropertySet->getPropertyValue( "CharHeight" ) >>= charHeight;
rPropertySet->getPropertyValue( "CharWeight" ) >>= charWeight;
rPropertySet->getPropertyValue( "CharPosture" ) >>= fontSlant;
cellFont.setStyleName( ::rtl::OUStringToOString( fontName, RTL_TEXTENCODING_UTF8 ).pData->buffer );
cellFont.setPixelSize( (int)charHeight );
cellFont.setBold( charWeight - 100 );
cellFont.setItalic( fontSlant );
}
return cellFont;
} catch ( ... ) { return QFont(); }
}
double QCxExcel::GetCellFontSize( void * pSheet, int nRow, int nCol )
{
if ( NULL == pSheet ) return 0;
nRow -= 1;
nCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
float charHeight = 0;
if ( rSheet.is() )
{
Reference< ::com::sun::star::table::XCell > rCell = rSheet->getCellByPosition( nCol, nRow );
Reference< ::com::sun::star::beans::XPropertySet > rPropertySet( rCell, ::com::sun::star::uno::UNO_QUERY );
if ( rPropertySet.is() )
rPropertySet->getPropertyValue( "CharHeight" ) >>= charHeight;
}
return (double)charHeight;
} catch ( ... ) { return 0; }
}
double QCxExcel::GetCellHeight( void * pCell )
{
if ( NULL == pCell ) return 0;
try {
Reference< ::com::sun::star::table::XColumnRowRange > rColumnRowRange(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( ! rColumnRowRange.is() ) return 0;
Reference< ::com::sun::star::beans::XPropertySet > rPropertySet( rColumnRowRange->getRows(), UNO_QUERY );
long cellHeight = 0;
if ( rPropertySet.is() )
rPropertySet->getPropertyValue( "Height" ) >>= cellHeight;
return (double)cellHeight;
} catch ( ... ) { return 0; }
}
double QCxExcel::GetCellWidth( void * pCell )
{
if ( NULL == pCell ) return 0;
try {
Reference< ::com::sun::star::table::XColumnRowRange > rColumnRowRange(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( ! rColumnRowRange.is() ) return 0;
Reference< ::com::sun::star::beans::XPropertySet > rPropertySet( rColumnRowRange->getColumns(), UNO_QUERY );
long cellWidth = 0;
if ( rPropertySet.is() )
rPropertySet->getPropertyValue( "Width" ) >>= cellWidth;
return (double)cellWidth;
} catch ( ... ) { return 0; }
}
double QCxExcel::GetHeight( void * pSheet, int nStartRow, int nEndRow )
{
if ( NULL == pSheet ) return 0;
nStartRow -= 1;
nEndRow -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
long rowsHeight = 0;
for ( int nRow = nStartRow; nRow <= nEndRow; ++nRow )
rowsHeight += GetCellHeight( rSheet->getCellByPosition( 0, nRow ).get() );
return (double)rowsHeight;
} catch ( ... ) { return 0; }
}
double QCxExcel::GetWidth( void * pSheet, int nStartCol, int nEndCol )
{
if ( NULL == pSheet ) return 0;
nStartCol -= 1;
nEndCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
long rowsWidth = 0;
for ( int nColumn = nStartCol; nColumn <= nEndCol; ++nColumn )
rowsWidth += GetCellWidth( rSheet->getCellByPosition( nColumn, 0 ).get() );
return (double)rowsWidth;
} catch ( ... ) { return 0; }
}
void QCxExcel::SetCellVal( void * pSheet, int nRow, int nCol, QVariant value )
{
if ( NULL == pSheet ) return;
nRow -= 1;
nCol -= 1;
try {
Reference< ::com::sun::star::sheet::XSpreadsheet > rSheet(
static_cast< ::com::sun::star::sheet::XSpreadsheet * >( pSheet ), UNO_QUERY );
if ( rSheet.is() )
{
Reference< ::com::sun::star::table::XCell > rCell = rSheet->getCellByPosition( nCol, nRow );
if ( rCell.is() ) {
QString str = value.toString();
sal_Char * s = NULL;
if (str.toDouble() && str.contains('E', Qt::CaseInsensitive)) {
int index = str.indexOf('E', 0, Qt::CaseInsensitive);
Reference< ::com::sun::star::text::XText > rText( rCell, UNO_QUERY );
Reference< ::com::sun::star::text::XTextCursor > rCursor = rText->createTextCursor();
s = str.left(index).toUtf8().data();
rCursor->setString( ::rtl::OUString(s, index, RTL_TEXTENCODING_UTF8));
rCursor->goRight(index, false);
s = str.mid(index).toUtf8().data();
rCursor->setString( ::rtl::OUString(s, str.length() - index, RTL_TEXTENCODING_UTF8));
}
else {
s = str.toUtf8().data();
rCell->setFormula( ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8) );
}
}
}
} catch ( ... ) {}
}
void QCxExcel::SetCellVal( void * pCell, const QVariant & value )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::table::XCell > rCell(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rCell.is() ) {
QString str = value.toString();
sal_Char * s = NULL;
if (str.toDouble() && str.contains('E', Qt::CaseInsensitive)) {
int index = str.indexOf('E', 0, Qt::CaseInsensitive);
Reference< ::com::sun::star::text::XText > rText( rCell, UNO_QUERY );
Reference< ::com::sun::star::text::XTextCursor > rCursor = rText->createTextCursor();
s = str.left(index).toUtf8().data();
rCursor->setString( ::rtl::OUString(s, index, RTL_TEXTENCODING_UTF8));
rCursor->goRight(index, false);
s = str.mid(index).toUtf8().data();
rCursor->setString( ::rtl::OUString(s, str.length() - index, RTL_TEXTENCODING_UTF8));
}
else {
s = str.toUtf8().data();
rCell->setFormula( ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8) );
}
}
} catch ( ... ) {}
}
void QCxExcel::SetCellHeight( void * pCell, int nHeight )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::table::XColumnRowRange > rColumnRowRange(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( !rColumnRowRange.is() ) return;
Reference< ::com::sun::star::beans::XPropertySet > rPropertySet( rColumnRowRange->getRows(), UNO_QUERY );
::com::sun::star::uno::Any anyHeight;
if ( rPropertySet.is() )
{
anyHeight <<= nHeight;
rPropertySet->setPropertyValue( "Height", anyHeight );
}
} catch ( ... ) {}
}
void QCxExcel::SetCellWidth( void * pCell, int nWidth )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::table::XColumnRowRange > rColumnRowRange(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( ! rColumnRowRange.is() ) return;
Reference< ::com::sun::star::beans::XPropertySet > rPropertySet( rColumnRowRange->getColumns(), UNO_QUERY );
::com::sun::star::uno::Any anyWidth;
if ( rPropertySet.is() )
{
anyWidth <<= nWidth;
rPropertySet->setPropertyValue( "Width", anyWidth );
}
} catch ( ... ) {}
}
void QCxExcel::SetCellHAlignment( void * pCell, int nType )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::beans::XPropertySet > rProperty(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rProperty.is() )
{
::com::sun::star::uno::Any aValue;
switch ( nType ) {
case -4131: aValue <<= ::com::sun::star::table::CellHoriJustify_LEFT; break;
case -4180: aValue <<= ::com::sun::star::table::CellHoriJustify_CENTER; break;
case -4152: aValue <<= ::com::sun::star::table::CellHoriJustify_RIGHT; break;
default: aValue <<= ::com::sun::star::table::CellHoriJustify_STANDARD; break;
}
rProperty->setPropertyValue( "HoriJustify", aValue );
}
} catch ( ... ) {}
}
void QCxExcel::SetCellVAlignment( void * pCell, int nType )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::beans::XPropertySet > rProperty(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rProperty.is() )
{
::com::sun::star::uno::Any aValue;
switch ( nType ) {
case -4160: aValue <<= ::com::sun::star::table::CellVertJustify_TOP; break;
case -4180: aValue <<= ::com::sun::star::table::CellVertJustify_CENTER; break;
case -4107: aValue <<= ::com::sun::star::table::CellVertJustify_BOTTOM; break;
default: aValue <<= ::com::sun::star::table::CellVertJustify_STANDARD; break;
}
rProperty->setPropertyValue( "VertJustify", aValue );
}
} catch ( ... ) {}
}
void QCxExcel::SetCellWrapTex( void * pCell, bool bWrap )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::beans::XPropertySet > rProperty(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rProperty.is() )
{
::com::sun::star::uno::Any aValue;
aValue <<= bWrap;
rProperty->setPropertyValue( "IsTextWrapped", aValue );
}
} catch ( ... ) {}
}
void QCxExcel::ClearCell( void * pCell )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::sheet::XSheetOperation > rSheetOperation(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rSheetOperation.is() )
rSheetOperation->clearContents( ::com::sun::star::sheet::CellFlags::VALUE
| ::com::sun::star::sheet::CellFlags::STYLES
| ::com::sun::star::sheet::CellFlags::STRING
| ::com::sun::star::sheet::CellFlags::OBJECTS
| ::com::sun::star::sheet::CellFlags::HARDATTR
| ::com::sun::star::sheet::CellFlags::FORMULA
| ::com::sun::star::sheet::CellFlags::FORMATTED
| ::com::sun::star::sheet::CellFlags::EDITATTR
| ::com::sun::star::sheet::CellFlags::DATETIME
| ::com::sun::star::sheet::CellFlags::ANNOTATION );
} catch ( ... ) {}
}
void QCxExcel::SetCellBgColor( void * pCell, QColor color )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::table::XCell > rCell(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
Reference< ::com::sun::star::beans::XPropertySet > rProperty( rCell, ::com::sun::star::uno::UNO_QUERY );
if ( rProperty.is() )
{
::com::sun::star::util::Color fontColor = (( color.rgba() << 8 ) >> 8);
::com::sun::star::uno::Any aValue;
aValue <<= fontColor;
rProperty->setPropertyValue( "CellBackColor", aValue );
}
} catch ( ... ) {}
}
void QCxExcel::SetCellFont( void * pCell, QString strFontName, int nSize, bool bBold, bool bItalic )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::beans::XPropertySet > rPropertySet(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rPropertySet.is() )
{
sal_Char * s = strFontName.toUtf8().data();
::rtl::OUString fontName = ::rtl::OUString(s, strlen(s), RTL_TEXTENCODING_UTF8);
float charHeight = (float)nSize;
float charWeight = bBold ? 150 : 100;
::com::sun::star::awt::FontSlant fontSlant = bItalic ?
::com::sun::star::awt::FontSlant::FontSlant_ITALIC :
::com::sun::star::awt::FontSlant::FontSlant_NONE;
::com::sun::star::uno::Any aValue;
aValue <<= fontName; rPropertySet->setPropertyValue( "CharFontName", aValue );
aValue <<= charHeight; rPropertySet->setPropertyValue( "CharHeight", aValue );
aValue <<= charWeight; rPropertySet->setPropertyValue( "CharWeight", aValue );
aValue <<= fontSlant; rPropertySet->setPropertyValue( "CharPosture", aValue );
}
} catch ( ... ) {}
}
void QCxExcel::SetCellFontColor( void * pCell, QColor color )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::beans::XPropertySet > rProperty(
static_cast< ::com::sun::star::table::XCell * >( pCell ), ::com::sun::star::uno::UNO_QUERY );
if ( rProperty.is() )
{
::com::sun::star::util::Color fontColor = ( ( color.rgba() << 8 ) >> 8 );
::com::sun::star::uno::Any aValue;
aValue <<= fontColor; rProperty->setPropertyValue( "CharColor", aValue );
}
} catch ( ... ) {}
}
void QCxExcel::SetCellBord( void * pCell, const QColor & color )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::beans::XPropertySet > rProperty(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rProperty.is() )
{
::com::sun::star::util::Color lineColor = ( color.rgba() << 2 );
::com::sun::star::table::TableBorder tableBorder;
rProperty->getPropertyValue( "TableBorder" ) >>= tableBorder;
tableBorder.TopLine.Color = lineColor;
tableBorder.BottomLine.Color = lineColor;
tableBorder.LeftLine.Color = lineColor;
tableBorder.RightLine.Color = lineColor;
::com::sun::star::uno::Any aValue;
aValue <<= tableBorder;
rProperty->setPropertyValue( "TableBorder", aValue );
}
} catch ( ... ) {}
}
void QCxExcel::SetCellBold( void * pCell, bool bBold )
{
if ( NULL == pCell ) return;
try {
Reference< ::com::sun::star::beans::XPropertySet > rPropertySet(
static_cast< ::com::sun::star::table::XCell * >( pCell ), UNO_QUERY );
if ( rPropertySet.is() )
{
float charWeight = bBold ? 150 : 100;
::com::sun::star::uno::Any aValue;
aValue <<= charWeight; rPropertySet->setPropertyValue( "CharWeight", aValue );
}
} catch ( ... ) {}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
- 注意,还需要添加一个宏定义
#if defined(__linux__) && !defined(LINUX)
#define LINUX
#endif
标签:star,sun,void,接口,return,C++,sheet,Libreoffice,com 来源: https://www.cnblogs.com/xklsm/p/14968522.html