157 lines
4.2 KiB
C++
157 lines
4.2 KiB
C++
|
|
#include <cstdlib> // For std::putenv
|
|||
|
|
#include <cstring> // For std::strdup
|
|||
|
|
|
|||
|
|
#include <com/sun/star/frame/XComponentLoader.hpp>
|
|||
|
|
#include <com/sun/star/frame/XStorable.hpp>
|
|||
|
|
#include <com/sun/star/frame/XDesktop.hpp>
|
|||
|
|
#include <com/sun/star/frame/Desktop.hpp>
|
|||
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|||
|
|
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
|
|||
|
|
#include <com/sun/star/uno/XComponentContext.hpp>
|
|||
|
|
#include <com/sun/star/uno/Reference.hxx>
|
|||
|
|
#include <com/sun/star/uno/Sequence.hxx>
|
|||
|
|
#include <com/sun/star/uno/XInterface.hpp>
|
|||
|
|
#include <com/sun/star/uno/RuntimeException.hpp>
|
|||
|
|
#include <com/sun/star/uno/Exception.hpp>
|
|||
|
|
#include <com/sun/star/uno/Any.hxx>
|
|||
|
|
#include <com/sun/star/document/IndexedPropertyValues.hpp>
|
|||
|
|
#include <com/sun/star/beans/PropertyValue.hpp>
|
|||
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|||
|
|
#include <com/sun/star/text/XTextDocument.hpp>
|
|||
|
|
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
|
|||
|
|
#include <com/sun/star/sheet/XSpreadsheet.hpp>
|
|||
|
|
#include <com/sun/star/registry/XSimpleRegistry.hpp>
|
|||
|
|
#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
|
|||
|
|
#include <com/sun/star/bridge/XUnoUrlResolver.hpp>
|
|||
|
|
#include <cppuhelper/bootstrap.hxx>
|
|||
|
|
|
|||
|
|
#include <osl/mutex.hxx>
|
|||
|
|
#include <rtl/ustring.hxx>
|
|||
|
|
#include <iostream>
|
|||
|
|
#include <sal/main.h>
|
|||
|
|
#include <osl/file.hxx>
|
|||
|
|
#include <osl/process.h>
|
|||
|
|
#include <rtl/process.h>
|
|||
|
|
#include <rtl/ustrbuf.hxx>
|
|||
|
|
|
|||
|
|
#include "GenerateReportBase.h"
|
|||
|
|
|
|||
|
|
using namespace std;
|
|||
|
|
using namespace com::sun::star::uno;
|
|||
|
|
using namespace com::sun::star::lang;
|
|||
|
|
using namespace com::sun::star::beans;
|
|||
|
|
using namespace com::sun::star::bridge;
|
|||
|
|
using namespace com::sun::star::frame;
|
|||
|
|
using namespace com::sun::star::sheet;
|
|||
|
|
using namespace com::sun::star::registry;
|
|||
|
|
using namespace com::sun::star::text;
|
|||
|
|
using namespace rtl;
|
|||
|
|
|
|||
|
|
using com::sun::star::beans::PropertyValue;
|
|||
|
|
|
|||
|
|
using com::sun::star::text::XTextDocument;
|
|||
|
|
using com::sun::star::text::XText;
|
|||
|
|
using com::sun::star::text::XTextCursor;
|
|||
|
|
|
|||
|
|
namespace GenerateReport
|
|||
|
|
{
|
|||
|
|
GenerateReportBase* GenerateReportBase::m_instance = nullptr;
|
|||
|
|
|
|||
|
|
GenerateReportBase::GenerateReportBase()
|
|||
|
|
{
|
|||
|
|
m_XDesktop= css::uno::Reference<css::frame::XDesktop2>();
|
|||
|
|
}
|
|||
|
|
//GenerateReportBase::~GenerateReportBase()
|
|||
|
|
//{
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
GenerateReportBase* GenerateReportBase::getinstance()
|
|||
|
|
{
|
|||
|
|
if (m_instance == nullptr)
|
|||
|
|
{
|
|||
|
|
m_instance = new GenerateReportBase;
|
|||
|
|
}
|
|||
|
|
return m_instance;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
void GenerateReportBase::init(GenerateReport::MainWindow* mainWindow)
|
|||
|
|
{
|
|||
|
|
m_mainWindow = mainWindow;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void GenerateReportBase::initUno()
|
|||
|
|
{
|
|||
|
|
try {
|
|||
|
|
// 初始化组件上下文
|
|||
|
|
auto _strap = cppu::bootstrap();
|
|||
|
|
css::uno::Reference<css::uno::XComponentContext> xContext(_strap);
|
|||
|
|
if (!xContext.is()) {
|
|||
|
|
std::cerr << "无法初始化组件上下文" << std::endl;
|
|||
|
|
m_XDesktop = nullptr;
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
// 获取服务管理器
|
|||
|
|
css::uno::Reference<css::lang::XMultiComponentFactory> xServiceManager(xContext->getServiceManager());
|
|||
|
|
if (!xServiceManager.is()) {
|
|||
|
|
std::cerr << "无法获取服务管理器" << std::endl;
|
|||
|
|
m_XDesktop = nullptr;
|
|||
|
|
return ;
|
|||
|
|
}
|
|||
|
|
// 创建Desktop对象
|
|||
|
|
css::uno::Reference<css::frame::XDesktop2> xDesktop = css::frame::Desktop::create(xContext);
|
|||
|
|
if (!xDesktop.is()) {
|
|||
|
|
std::cerr << "无法创建Desktop对象" << std::endl;
|
|||
|
|
m_XDesktop = nullptr;
|
|||
|
|
return ;
|
|||
|
|
}
|
|||
|
|
m_XDesktop = xDesktop;
|
|||
|
|
}
|
|||
|
|
catch (cppu::BootstrapException e)
|
|||
|
|
{
|
|||
|
|
auto ttt = e.getMessage().pData;
|
|||
|
|
std::cerr << "异常抛出" << std::endl;
|
|||
|
|
m_XDesktop = nullptr;
|
|||
|
|
return ;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
GenerateReport::MainWindow* GenerateReportBase::getMainWindow()
|
|||
|
|
{
|
|||
|
|
return m_mainWindow;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
css::uno::Reference<css::frame::XDesktop2> GenerateReportBase::getDesktop()
|
|||
|
|
{
|
|||
|
|
return m_XDesktop;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void GenerateReportBase::setTextDocument(css::uno::Reference<css::text::XTextDocument> xTextDocument)
|
|||
|
|
{
|
|||
|
|
m_xTextDocument = xTextDocument;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
css::uno::Reference<css::text::XTextDocument> GenerateReportBase::getTextDocument()
|
|||
|
|
{
|
|||
|
|
return m_xTextDocument;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void GenerateReportBase::setCurrentReportName(QString reportName)
|
|||
|
|
{
|
|||
|
|
m_reportName = reportName;
|
|||
|
|
}
|
|||
|
|
QString GenerateReportBase::getCurrentReportName()
|
|||
|
|
{
|
|||
|
|
return m_reportName;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void GenerateReportBase::setCurrentReportNumber(int currentReportNum)
|
|||
|
|
{
|
|||
|
|
m_currentReportNum = currentReportNum;
|
|||
|
|
}
|
|||
|
|
int GenerateReportBase::getCurrentReportNumber()
|
|||
|
|
{
|
|||
|
|
return m_currentReportNum;
|
|||
|
|
}
|
|||
|
|
}
|