112 lines
3.6 KiB
C++
112 lines
3.6 KiB
C++
#include <cstdlib> // For std::putenv
|
|
#include <cstring> // For std::strdup
|
|
|
|
#include <QFileDialog>
|
|
#include <QString>
|
|
|
|
#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 "GemerateFinalReport.h"
|
|
#include "CloseCurrentReport.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
|
|
{
|
|
GemerateFinalReport::GemerateFinalReport()
|
|
{
|
|
}
|
|
//test1::~Test1()
|
|
//{
|
|
//}
|
|
|
|
void GemerateFinalReport::actionSlot_GemerateFinalReport()
|
|
{
|
|
|
|
QString _dir = QString("C:/");
|
|
QString _conSuffix = QString("*.docx");
|
|
|
|
QString _title = QString("Gemerate Final Report");
|
|
QString _defaultName = GenerateReportBaseInstance->getCurrentReportName();
|
|
QString _selectNameFilter = "*.docx";
|
|
QString _filename = QFileDialog::getSaveFileName(nullptr, _title, _dir + _defaultName, _conSuffix, &_selectNameFilter);
|
|
if (_filename.isEmpty()) return;
|
|
else saveLibreOfficeDocumentAsDocx(_filename.toStdString());
|
|
}
|
|
|
|
void GemerateFinalReport::saveLibreOfficeDocumentAsDocx( const std::string& outputDocxPath)
|
|
{
|
|
auto _xComponent = GenerateReportBaseInstance->getTextDocument();
|
|
// 保存文档为docx格式
|
|
Reference<XStorable> xStorable(_xComponent, UNO_QUERY);
|
|
if (!xStorable.is()) {
|
|
std::cerr << "Failed to get XStorable interface." << std::endl;
|
|
return;
|
|
}
|
|
|
|
Sequence<PropertyValue> storeArgs(1);
|
|
storeArgs[0].Name = OUString("FilterName");
|
|
storeArgs[0].Value <<= OUString("MS Word 2007 XML");
|
|
|
|
OUString _outputPath = OUString("file:///") + OUString::createFromAscii(outputDocxPath.c_str());
|
|
try {
|
|
xStorable->storeToURL(
|
|
_outputPath,
|
|
// OUString("file:///F:/LibreofficeTest/export1.docx"),
|
|
storeArgs
|
|
);
|
|
std::cout << "Document successfully saved as docx format." << std::endl;
|
|
GenerateReport::CloseCurrentReport _crr;
|
|
_crr.closeReportExcute();
|
|
}
|
|
catch (const Exception& e) {
|
|
std::cerr << "Error saving document as docx format: " << e.Message << std::endl;
|
|
}
|
|
}
|
|
}
|