由于部分原因,只提供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

C++调用Libreoffice接口的更多相关文章

  1. WebApi接口 - 如何在应用中调用webapi接口

    很高兴能再次和大家分享webapi接口的相关文章,本篇将要讲解的是如何在应用中调用webapi接口:对于大部分做内部管理系统及类似系统的朋友来说很少会去调用别人的接口,因此可能在这方面存在一些困惑,希 ...

  2. C#动态调用WCF接口,两种方式任你选。

    写在前面 接触WCF还是它在最初诞生之处,一个分布式应用的巨作. 从开始接触到现在断断续续,真正使用的项目少之又少,更谈不上深入WCF内部实现机制和原理去研究,最近自己做一个项目时用到了WCF. 从这 ...

  3. python调用zabbix接口实现Action配置

    要写这篇博客其实我的内心是纠结的,老实说,我对zabbix的了解实在不多.但新公司的需求不容置疑,当我顶着有两个头大的脑袋懵懵转入运维领域时,面前摆着两百多组.上千台机器等着写入zabbix监控的需求 ...

  4. HttpClient Get/Post方式调用Http接口

    本节摘要:本节主要分别介绍如何用get方式.post方式向http接口发送数据. preparation 1. 项目环境如下: myeclipse6.5 .tomcat5.0.system:xp.JD ...

  5. Atitit 通过调用gui接口杀掉360杀毒 360卫士  qq保镖等难以结束的进程(javac# php )

    Atitit 通过调用gui接口杀掉360杀毒 360卫士  qq保镖等难以结束的进程(javac# php ) 1.1. 这些流氓软件使用操作系统os提供的普通api根本就杀不掉啊1 1.2. 使用 ...

  6. Java调用webservice接口方法

                             java调用webservice接口   webservice的 发布一般都是使用WSDL(web service descriptive langu ...

  7. php中创建和调用webservice接口示例

    php中创建和调用webservice接口示例   这篇文章主要介绍了php中创建和调用webservice接口示例,包括webservice基本知识.webservice服务端例子.webservi ...

  8. 调用c++接口类

    调用c++接口类 public class CarDeviceDll { /*对dll库进行一些初始化*/ [DllImport("IDI.dll")] public static ...

  9. android应用程序如何调用支付宝接口

    最近在做一个关于购物商城的项目,项目里面付款这块我选的是调用支付宝的接口,因为用的人比较多. 在网上搜索了以下,有很多这方面的教程,但大部分教程过于陈旧,而且描述的过于简单.而且支付宝提供的接口一直在 ...

随机推荐

  1. Redis泛泛而谈(详细2W字)

    本文适合于刚接触redis的,文章内容比较基础,大佬请绕道. 一.NoSQL入门和概述 Ⅰ-入门概述 1.为什么用NoSQL 1)单机MySQL的美好年代 在90年代,一个网站的访问量一般都不大,用单 ...

  2. 【Web前端HTML5&CSS3】08-盒模型补充

    笔记来源:尚硅谷Web前端HTML5&CSS3初学者零基础入门全套完整版 目录 盒模型补充及田径场实战 1. 盒子大小 2. 轮廓 3. 阴影 4. 圆角 圆 椭圆 盒模型补充及田径场实战 1 ...

  3. Docker系列——Grafana+Prometheus+Node-exporter服务器监控平台(一)

    在最近的博文中,都是介绍监控平台的搭建,其实并不难,主要是需要自己动手操作,实践一番就会了. 有天在想,云上的服务器,是不是也可以搭建一个监控平台,所以就捣鼓了一下,不过遗憾的是,使用阿里云开源的插件 ...

  4. head元素的内容

    一.head元素 head元素的内容用来向浏览器提供一些文档信息,此外还可以包含js脚本和css层叠样式单.head中一般包含title.meta.css.js等内容,head中元素的内容在浏览器中不 ...

  5. linux操作系统故障处理-ext4文件系统超级块损坏修复

    linux操作系统故障处理-ext4文件系统超级块损坏修复   背景 前天外面出差大数据测试环境平台有7台服务器挂了,同事重启好了五台服务器,但是还有两台服务器启动不起来,第二天回来后我和同事再次去机 ...

  6. 【转载】搭建本地yum源:以下是以centos7为例子

    搭建本地yum源:以下是以centos7为例子  1)首先需要安装 createrepo(需要一个可以使用源的机器,可以访问互联网)安装方法可以使用yum安装epel源 1 yum -y instal ...

  7. k8s运行容器之Job应用(6)

    容器按照持续运行的时间可分为两类:服务类容器和工作类容器. 服务类容器通常持续提供服务,需要一直运行,比如 http server,daemon 等.工作类容器则是一次性任务,比如批处理程序,完成后容 ...

  8. linux基础之基础命令一

    本节内容: 1. ls:列出当前目录下的文件和目录 -l: 长输出,显示文件的详细信息(-普通文本,d目录) -a: 显示所有文件,包括隐藏文件 -h: 人类易读(-lh) -d: 显示目录信息(-l ...

  9. Arduino+AS608指纹锁避坑记

    Arduino+AS608指纹锁避坑记 .title { text-align: center; margin-bottom: 0.2em } .subtitle { text-align: cent ...

  10. ISP_DPC坏点矫正

    ISP_DPC坏点矫正 1. 坏点介绍 图像坏点(Bad pixel) : 图像传感器上光线采集点(像素点)所形成的阵列存在工艺上的缺陷,或光信号进行转化为电信号的过程中出现错误,从而会造成图像上像素 ...