Fixes for comments

This commit is contained in:
Oleg Korshul
2023-04-21 00:42:32 +03:00
parent 33e6c14a04
commit ff75d14e29
4 changed files with 125 additions and 4 deletions

View File

@ -843,6 +843,8 @@ public:
nType = AVS_OFFICESTUDIO_FILE_IMAGE;
else if (L"png" == sType)
nType = AVS_OFFICESTUDIO_FILE_IMAGE;
else if (L"html" == sType)
nType = AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML_IN_CONTAINER;
bool bRet = m_pBuilder->SaveFile(nType, path);
*result = bRet ? VARIANT_TRUE : VARIANT_FALSE;

View File

@ -0,0 +1,119 @@
#include <iostream>
#include <comutil.h>
#include <atlcomcli.h>
#include <atlsafe.h>
#include <string>
#include "../../src/docbuilder_midl.h"
#ifdef _UNICODE
# pragma comment(lib, "comsuppw.lib")
#else
# pragma comment(lib, "comsupp.lib")
#endif
#define RELEASEINTERFACE(pinterface) \
{ \
if (NULL != pinterface) \
{ \
pinterface->Release(); \
pinterface = NULL; \
} \
}
#define EMPTY_PARAM ATL::CComVariant()
#define _B(x) _bstr_t(L##x)
int main(int argc, char *argv[])
{
// uncomment for debug js
//SetEnvironmentVariableA("V8_USE_INSPECTOR", "1");
CoInitialize(NULL);
IONLYOFFICEDocBuilder* pBuilder = NULL;
if (FAILED(CoCreateInstance(__uuidof(CONLYOFFICEDocBuilder), NULL, CLSCTX_ALL, __uuidof(IONLYOFFICEDocBuilder), (void**)&pBuilder)))
{
CoUninitialize();
return 1;
}
VARIANT_BOOL bRes;
pBuilder->Initialize();
pBuilder->OpenFile(_B("file.docx"), _B(""), &bRes);
//pBuilder->SaveFile(_B("html"), _B("D:/FILES/images.html"), &bRes);
IONLYOFFICEDocBuilderContext* pContext = NULL;
pBuilder->GetContext(&pContext);
IONLYOFFICEDocBuilderContextScope* pScope = NULL;
pContext->CreateScope(&pScope);
IONLYOFFICEDocBuilderValue* pGlobal = NULL;
pContext->GetGlobal(&pGlobal);
IONLYOFFICEDocBuilderValue* pApi = NULL;
pGlobal->GetProperty(_B("Api"), &pApi);
IONLYOFFICEDocBuilderValue* pDocument = NULL;
pApi->Call(_B("GetDocument"), EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, &pDocument);
IONLYOFFICEDocBuilderValue* pRanges = NULL;
pDocument->Call(_B("Search"), ATL::CComVariant("year"), EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, &pRanges);
if (pRanges)
{
VARIANT_BOOL vbIsArray = VARIANT_FALSE;
pRanges->IsArray(&vbIsArray);
if (VARIANT_TRUE == vbIsArray)
{
long nCount = 0;
pRanges->GetLength(&nCount);
if (0 < nCount)
{
IONLYOFFICEDocBuilderValue* pSearchRange = NULL;
pRanges->Get(0, &pSearchRange);
IONLYOFFICEDocBuilderValue* pComment = NULL;
pSearchRange->Call(_B("AddComment"), ATL::CComVariant("Comment Text"), ATL::CComVariant("Author"),
EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, &pComment);
IONLYOFFICEDocBuilderValue* pCommentID = NULL;
pComment->Call(_B("GetId"), EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, EMPTY_PARAM, &pCommentID);
// get comment id.
// work with comment:
// https://api.onlyoffice.com/docbuilder/textdocumentapi/apidocument/getcommentbyid
// https://api.onlyoffice.com/docbuilder/textdocumentapi/apicomment
BSTR bsCommentId = NULL;
pCommentID->ToString(&bsCommentId);
SysFreeString(bsCommentId);
RELEASEINTERFACE(pCommentID);
RELEASEINTERFACE(pComment);
RELEASEINTERFACE(pSearchRange);
}
}
}
RELEASEINTERFACE(pRanges);
RELEASEINTERFACE(pDocument);
RELEASEINTERFACE(pApi);
RELEASEINTERFACE(pGlobal);
RELEASEINTERFACE(pScope);
RELEASEINTERFACE(pContext);
pBuilder->SaveFile(_B("docx"), _B("file.docx"), &bRes);
pBuilder->CloseFile();
pBuilder->Dispose();
RELEASEINTERFACE(pBuilder);
CoUninitialize();
return 0;
}

View File

@ -239,6 +239,8 @@ bool CV8RealTimeWorker::OpenFile(const std::wstring& sBasePath, const std::wstri
bIsBreak = !this->ExecuteCommand(L"Api.asc_nativeInitBuilder();");
if (!bIsBreak)
bIsBreak = !this->ExecuteCommand(L"Api.asc_SetSilentMode(true);");
if (!bIsBreak)
bIsBreak = !this->ExecuteCommand(L"Api.asc_showComments();");
LOGGER_SPEED_LAP("open");

View File

@ -164,11 +164,9 @@ public:
v8::V8::InitializeICU();
#endif
char* strEnv = std::getenv("V8_USE_INSPECTOR");
if (strEnv && std::strcmp(strEnv, "0"))
{
std::string sInspectorEnabled = NSSystemUtils::GetEnvVariableA(L"V8_USE_INSPECTOR");
if (!sInspectorEnabled.empty() && "0" != sInspectorEnabled)
m_bUseInspector = true;
}
}
void Dispose()