Esempio n. 1
0
void TestSnapshotSaver::TestSavesCustomProperties()
{
    const CStdString sDocWithNoProperties = GET_TEST_FILE_PATH( _T("No Properties.doc") );
    const CStdString sCopyOfDoc = GET_TEST_TEMP_PATH( _T("CopyFile.doc") );
    CStdString sDestFile = GET_TEST_TEMP_PATH( _T("ResultsFile.doc") );

    ::DeleteFile( sCopyOfDoc.c_str() );
    ::DeleteFile( sDestFile.c_str() );
    assertTest( ::CopyFile( sDocWithNoProperties.c_str(), sCopyOfDoc.c_str(), FALSE ) );

    CustomPropertyStorage propStorage( sCopyOfDoc );
    propStorage.SetProperty( _T("Safe"), _T("Init") );

    Word::_ApplicationPtr pApp;
    pApp.CreateInstance( __uuidof( Word::Application ) );

    try
    {
        const Word::_DocumentPtr pDocument = pApp->Documents->Open( &_variant_t( sCopyOfDoc ) );

        SnapshotSaver saver( pDocument );
        saver.Save( sDestFile );

        CustomPropertyStorage destStorage( sDestFile );
        assertMessage( destStorage.GetProperty( _T("Safe") ) == CStdString( _T("Init") ), _T("Custom properties should be persisted in the snapshotted document") );
        pApp->Quit();
    }
    catch(...)
    {
        pApp->Quit();
        throw;
    }
}
Esempio n. 2
0
void TestSnapshotSaver::TestSave()
{
    const CStdString sSourceFileName = CTestUtils::GetTestFileFolder() + _T("TestApplyChange_BinaryRead\\Synergy24TestDocuments\\FlagForFollowUp.doc");
    CStdString sDestFileName = CTestUtils::GetTestFileFolder() + _T("TestApplyChange_BinaryRead\\Synergy24TestDocuments\\rubbish.doc");

    ::DeleteFile( sDestFileName );
    assertFileNotExists( sDestFileName );

    Word::_ApplicationPtr pApp;
    pApp.CreateInstance( __uuidof( Word::Application ) );
    const Word::_DocumentPtr pDocument = pApp->Documents->Open( &_variant_t( sSourceFileName ) );

    try
    {
        SnapshotSaver snapshotSaver( pDocument );
        snapshotSaver.Save( sDestFileName );
    }
    catch(...)
    {
        pDocument->Close();
        pApp->Quit();
        throw;
    }

    pDocument->Close();
    pApp->Quit();

    assertFileExists( sDestFileName );
}
Esempio n. 3
0
//---------------------------------------------------------------------------
void WordMacros::RunMacros(string_t tempFile)
{
  Word::_ApplicationPtr app;
  if (FAILED(app.CreateInstance("Word.Application")))
  {
    string_t msg = "Невозможно запустить Microsoft Word. Возможно он не установлен на компьютере.";
    MessageBox(::GetActiveWindow(), msg , L"Ошибка", MB_OK | MB_ICONERROR | MB_APPLMODAL);
    return;
  }
  try
  {
    _variant_t tamp = (const wchar_t*)tempFile;
    Word::_DocumentPtr      doc  = app->Documents->Add(&tamp);
    VBIDE::_VBProjectPtr    vbp  = doc->VBProject;
    VBIDE::_VBComponentsPtr vbc  = vbp->VBComponents;
    VBIDE::_VBComponentPtr  item = vbc->Item(1);
    VBIDE::_CodeModulePtr   cm   = item->CodeModule;

    CreateRuningMacros();
    string_t name = "M" + string_t(aux::itoa(m_MacroCounter));


    cm->AddFromString((const wchar_t*)m_CurMacros);
    app->Run((const wchar_t*)name);
  }
  catch (_com_error & e)
  {
    _bstr_t desc = e.Description();
    string_t msg = "Невозможно открыть документ Microsoft Word:\n" + tempFile + "\n";
    if (desc.length())
      msg += std::wstring(desc);
    MessageBox(::GetActiveWindow(), msg , L"Ошибка", MB_OK | MB_ICONERROR | MB_APPLMODAL); 
  }
  catch (...)
  {
    string_t msg = "Невозможно открыть документ Microsoft Word:\n" + tempFile + "\nили проблема с макросами или не смогли открыть шаблон файла";
    MessageBox(::GetActiveWindow(), msg , L"Ошибка", MB_OK | MB_ICONERROR | MB_APPLMODAL);
  }
  app->Visible = VARIANT_TRUE;

  m_Macros = "";
  m_MacroCounter = 0;
  m_CurMacros = "";
}