Exemplo n.º 1
0
void ExcelControllerImpl08::DoSaveDocument(IDispatchPtr spDocument)
{	
   if (spDocument == 0)	
      throw Workshare::Com::ComException(_T("The excel document instance was null"), E_INVALIDARG);

   Excel::_WorkbookPtr pExcelDocument = spDocument;
   pExcelDocument->Save();
}
Exemplo n.º 2
0
IDispatchPtr ExcelControllerImpl08::DoOpenDocument(const CStdString& sDocumentPath, bool bReadOnly)
{  
   if(sDocumentPath.IsEmpty())
      throw Workshare::ArgumentException(_T("sDocumentPath"), _T("An empty filename is not allowed."));

   if(!::PathFileExists(sDocumentPath))
      throw Workshare::System::IO::FileNotFoundException(sDocumentPath, _T("Expected an existing excel workbook filename to open."));
   
   //TODO: (EW/WS) Refer to CloseDocument for a description of a latent defect which may be caused by the following line.
   SetScreenUpdating(false);
   Excel::_WorkbookPtr spDocument = FindOpenDocument(sDocumentPath);
   if(spDocument)
   {
      if (!bReadOnly)
      {
         if (spDocument->ReadOnly)
            throw Workshare::Com::ComException(_T("Failed to open a READ-ONLY document for write access."), E_FAIL);

         if (!spDocument->Saved)
            spDocument->Save();			
      }
   }
   else		
   {
      Excel::_ApplicationPtr spApplication = GetApplication();
	  spApplication->EnableEvents = VARIANT_FALSE;	//The events are on by default, so no need to store the original value
      LONG_PTR nNewDocumentCount = spApplication->Workbooks->Count + 1;
      try
      {
         _variant_t vtReadOnly = bReadOnly;         
         _variant_t vtUpdateLinks(false);
         spDocument = spApplication->Workbooks->Open(sDocumentPath.c_str(), vtUpdateLinks, vtReadOnly);

         WaitForWorkbookOpened(sDocumentPath);
      }
      catch (const Workshare::Com::ComException&)
      {
         if(nNewDocumentCount != spApplication->Workbooks->Count)
            throw;

         _variant_t vtCount(static_cast<long>(nNewDocumentCount));
         spDocument = spApplication->Workbooks->GetItem(&vtCount);
      }
   }

   DisableUnwantedOptions();
   spDocument->put_Saved(LocaleHelper::GetLocaleIDForInstalledExcel(spDocument), VARIANT_TRUE);

   return spDocument;   
}