全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2463
推到 Plurk!
推到 Facebook!

請問有人用過delphi寫一找出execl or word的「摘要資訊」裡的內容?

答題得分者是:axsoft
maggie
一般會員


發表:6
回覆:12
積分:3
註冊:2002-03-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-10 10:31:20 IP:139.223.xxx.xxx 未訂閱
請問各位大大.... 不曉得有沒有人試過去用delphi寫出..將excel or word的檔案讀進來..然後可以直接取得它「摘要資訊」裡面的資料.. 它是在「檔案」/「摘要資訊」.. 請問有這方面的property嗎? 請各位大大幫忙一下..小的感激不盡~謝謝
maggie
一般會員


發表:6
回覆:12
積分:3
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-01-14 14:00:45 IP:139.223.xxx.xxx 未訂閱
sorry..不知道大家是否因為我表達的不清楚,才沒回答嗎?? 那我再陳述一次好了..麻煩大家幫忙..謝謝.. 我想做的是將excel or word的檔案選出來後,可以取得到它的「摘要資訊」,這個「摘要資訊」就是一般我們在用excel or word檔案時,在功能列的檔案裡面就有這個項目...我想取得的就是這裡面的(標題、主旨、作者、主管...之類的項目)...是不是有什麼office的屬性可供使用呢?? 還是有其他的方法可達到我的結果..請各位大大幫幫忙..拜託了...
delphiwww
資深會員


發表:145
回覆:363
積分:368
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-01-14 14:39:41 IP:202.145.xxx.xxx 未訂閱
請問你要什麼資料?
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-01-14 16:43:02 IP:61.218.xxx.xxx 未訂閱
引言: sorry..不知道大家是否因為我表達的不清楚,才沒回答嗎?? 那我再陳述一次好了..麻煩大家幫忙..謝謝.. 我想做的是將excel or word的檔案選出來後,可以取得到它的「摘要資訊」,這個「摘要資訊」就是一般我們在用excel or word檔案時,在功能列的檔案裡面就有這個項目...我想取得的就是這裡面的(標題、主旨、作者、主管...之類的項目)...是不是有什麼office的屬性可供使用呢?? 還是有其他的方法可達到我的結果..請各位大大幫幫忙..拜託了...
這還有個方法: dosfile.dll是由Vc寫給VB用的,可用Delphi call dll 達成您的目標! 裡面有VB的範例. 下載: ftp://ftp.cyf-kr.edu.pl/pub/mirror/Microsoft/SoftLib/MSLFILES/DSOFILE.EXE Readme.txt for Dsofile.exe SUMMARY ======= Dsofile.exe is a self-extracting executable that provides an in-process ActiveX DLL for Visual Basic programmers to use in order to read or modify the Document Summary Properties for an OLE Structured Storage file. Because Word, Excel, and PowerPoint use OLE Structured Storage to save their files to disk, this DLL lets programmers view and change document properties without the need to open the document in Office. MORE INFORMATION ================ The following files are included with Dsofile.exe: FileName Size ------------------------------ Dsofile.dll 35 KB FilePropDemo.vbp 1 KB FilePropDemo.vbw 1 KB FileProp.frm 18 KB FileProp.frx 1 KB You have a royalty-free right to use, modify, reproduce and distribute the Dsofile.dll and Visual Basic Sample Application (and/or any modified version) in any way you find useful, provided that you agree that Microsoft has no warranty, obligations or liability for these files. NOTE: THE Dsofile.DLL AND ASSOCIATED VISUAL BASIC SAMPLE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. Document Properties -------------------- Every OLE compound document has the ability to store additional information about the document in persistent property sets, collectively called the Document Summary Properties. These property sets are managed by COM/OLE so third-party clients can read this information without the aid of the main application responsible for the file. To aid developers interested in reading document properties, Microsoft has provided two interfaces to manage property sets: IPropertySetStorage and IPropertyStorage. However, Visual Basic programmers cannot use these interfaces directly because the interfaces are not Automation-compatible. To resolve this problem, Visual Basic developers can now use the included ActiveX DLL to read/write to the most common property sets used in OLE compound documents (particularly those used by Office applications). NOTE: Dsofile.dll uses IPropertySetStorage and IPropertyStorage internally. These interfaces were defined after the initial release of Windows 95, so Windows 95 users must have one of the following installed on their system for the DLL to work properly: - Internet Explorer 4.01 (or later). - or - - The DCOM95 Patch. Available for free download at the following Web site: http://www.microsoft.com/com/dcom/dcom1_2/dcom1_2.asp A trappable error will be raised if the system does not support IPropertySetStorage or IPropertyStorage. OLE File Property Reader ------------------------ Dsofile.dll reads and writes to both standard and custom properties from any OLE Structured Storage file. This includes (but is not limited to) Word documents, Excel workbooks, and PowerPoint presentations. Due to its size and speed, the DLL can be much more efficient than trying to Automate Office to read document properties. To use the Property Reader, you need to register Dsofile.dll on your system (see below). Once registered, the component can be used by both late and early bound clients. To set an early bound reference in Visual Basic, use the References dialog (Project|References) and select the item: "DS: OLE Document Properties 1.0 Object Library." If the item is not listed in the dialog, use the Browse button to find the DLL. Dsofile.dll has only one creatable object, DSOleFile.PropertyReader. This object provides access to document properties through a single method, GetDocumentProperties. PropertyReader is a top level object and is marked GlobalMultiUse, so you do not need to explicitly create the object to use it. You can call GetDocumentProperties directly if you have already set a reference to the DLL in the References dialog. However, to save resources at run-time, it is recommended that you explicitly create and destroy a PropertyReader object when needed. If you allow Visual Basic to implicitly create the object, it will not be released until your application terminates. GetDocumentProperties takes the name of an OLE Structured Storage file and returns a DocumentProperties object that you can then Automate to read or modify property values. DocumentProperties provides access to the most common summary information used by Office applications. When the object is created, the specified file is open for exclusive access. If the file is in use by another application when you try to open it, you get a trappable error telling you that the file is locked. The DocumentProperties object contains a collection of the custom properties associated with the file. Each custom property has a unique name and is accessible in the collection by that name. You can add or remove individual properties and also enumerate through the entire collection using Visual Basic's For Each syntax. When calling GetDocumentProperties, the PropertyReader will first attempt to open the document for both read and write access. If the file has been marked read-only or is located on an NT share that provides just Read access, the PropertyReader will try to open the document in read access. When open for read-only, you cannot change values for any of the properties. To test whether the document is read-only, use the IsReadOnly method on the DocumentProperties object returned from GetDocumentProperties. The method returns True if the document is read-only. NOTE: Dsofile.dll was written specifically for use by Visual Basic programmers, but it can be used from any COM-aware language. In addition to the standard Automation errors, Dsofile.dll can return one of the following custom error messages when something goes wrong: &H80040201 You need DCOM installed on Windows 95 to run this program. &H80040202 The file you have selected is not an OLE document. &H80040203 The file is currently open and cannot be read. &H80040204 This property can only be called on Word or Excel documents. Another common error is: Permission denied (Error 70) which occurs when attempting to modify a property in a read-only document. Steps to Setup and Test the DLL ------------------------------- Included is a Visual Basic sample application that demonstrates using the Dsofile.dll to read and write document properties. Before you can run the sample you need to do the following: 1. Register Dsofile.dll on your system. To do this, copy Dsofile.dll to your system path and then type "regsvr32 dsofile.dll" (without the quotation marks) in the Run dialog from the Start menu. 2. Open the project, FilePropDemo.vbp, in either Visual Basic 5.0 or Visual Basic 6.0. 3. Make sure that Dsofile.dll has been properly referenced by opening the Project|References dialog and selecting the DS: OLE Document Properties 1.0 Object Library. 4. Press the F5 key to run the project. You will be prompted for a compound document file to open. Select an appropriate file and its document properties are displayed. 聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]---
axsoft
版主


發表:681
回覆:1056
積分:969
註冊:2002-03-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-01-14 16:50:05 IP:61.218.xxx.xxx 未訂閱
C++的做法:
   #include 
   #include 
   #include 
   #include            // Dumps simple PROPVARIANT values.
   void DumpPropVariant(PROPVARIANT *pPropVar) {
      // Don't iterate arrays, just inform as an array.
      if(pPropVar->vt & VT_ARRAY) {
         printf("(Array)\n");
         return;
      }          // Don't handle byref for simplicity, just inform byref.
      if(pPropVar->vt & VT_BYREF) {
         printf("(ByRef)\n");
         return;
       }          // Switch types.
      switch(pPropVar->vt) {
      case VT_EMPTY:
         printf("(VT_EMPTY)\n");
         break;
      case VT_NULL:
         printf("(VT_NULL)\n");
         break;
      case VT_BLOB:
         printf("(VT_BLOB)\n");
         break;
      case VT_BOOL:
         printf("%s (VT_BOOL)\n",
         pPropVar->boolVal ? "TRUE/YES" : "FALSE/NO");
         break;
      case VT_I2: // 2-byte signed int.
         printf("%d (VT_I2)\n", (int)pPropVar->iVal);
         break;
      case VT_I4: // 4-byte signed int.
         printf("%d (VT_I4)\n", (int)pPropVar->lVal);
         break;
      case VT_R4: // 4-byte real.
         printf("%.2lf (VT_R4)\n", (double)pPropVar->fltVal);
         break;
      case VT_R8: // 8-byte real.
         printf("%.2lf (VT_R8)\n", (double)pPropVar->dblVal);
         break;
         case VT_BSTR: // OLE Automation string.
         {
            // Translate into ASCII.
            char dbcs[1024];
            char *pbstr = (char *)pPropVar->bstrVal;
            int i = wcstombs(
            dbcs, pPropVar->bstrVal, *((DWORD *)(pbstr-4)));
            dbcs[i] = 0;
            printf("%s (VT_BSTR)\n", dbcs);
         }
         break;
      case VT_LPSTR: // Null-terminated string.
         {
         printf("%s (VT_LPSTR)\n", pPropVar->pszVal);
         }
         break;
      case VT_FILETIME:
         {
            char *dayPre[] =
                         {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};                FILETIME lft;
            FileTimeToLocalFileTime(&pPropVar->filetime, &lft);                SYSTEMTIME lst;
            FileTimeToSystemTime(&lft, &lst);                printf("d:d.d %s, %s d/d/%d (VT_FILETIME)\n",
               1 (lst.wHour-1), lst.wMinute, lst.wSecond,
               (lst.wHour>=12) ? "pm" : "am",
               dayPre[lst.wDayOfWeek%7],
               lst.wMonth, lst.wDay, lst.wYear);
         }
         break;
      case VT_CF: // Clipboard format.
         printf("(Clipboard format)\n");             break;
      default: // Unhandled type, consult wtypes.h's VARENUM structure.
         printf("(Unhandled type: 0xlx)\n", pPropVar->vt);
         break;
      }
   }       // Dump's built-in properties of a property storage.
   void DumpBuiltInProps(IPropertySetStorage *pPropSetStg) {
      printf("\n==================================================\n");
      printf("BuiltInProperties Properties...\n");
      printf("==================================================\n");          IPropertyStorage *pPropStg = NULL;
      HRESULT hr;          // Open summary information, getting an IpropertyStorage.
      hr = pPropSetStg->Open(FMTID_SummaryInformation,
      STGM_READ | STGM_SHARE_EXCLUSIVE, &pPropStg);
      //hr = pPropSetStg->Open(FMTID_UserDefinedProperties,
         //STGM_READ | STGM_SHARE_EXCLUSIVE, &pPropStg);
      if(FAILED(hr)) {
         printf("No Summary-Information.\n");
         return;
      }
      // Array of PIDSI's you are interested in.
      struct pidsiStruct {
         char *name;
         long pidsi;
      } pidsiArr[] = {
         {"Title",            PIDSI_TITLE}, // VT_LPSTR
         {"Subject",          PIDSI_SUBJECT}, // ...
         {"Author",           PIDSI_AUTHOR},
         {"Keywords",         PIDSI_KEYWORDS},
         {"Comments",         PIDSI_COMMENTS},
         {"Template",         PIDSI_TEMPLATE},
         {"LastAuthor",       PIDSI_LASTAUTHOR},
         {"Revision Number",  PIDSI_REVNUMBER},
         {"Edit Time",        PIDSI_EDITTIME}, // VT_FILENAME (UTC)
         {"Last printed",     PIDSI_LASTPRINTED}, // ...
         {"Created",          PIDSI_CREATE_DTM},
         {"Last Saved",       PIDSI_LASTSAVE_DTM},
         {"Page Count",       PIDSI_PAGECOUNT}, // VT_I4
         {"Word Count",       PIDSI_WORDCOUNT}, // ...
         {"Char Count",       PIDSI_CHARCOUNT},             {"Thumpnail",        PIDSI_THUMBNAIL}, // VT_CF
         {"AppName",          PIDSI_APPNAME}, // VT_LPSTR
         {"Doc Security",     PIDSI_DOC_SECURITY}, // VT_I4
         {0, 0}
      };
      // Count elements in pidsiArr.
      int nPidsi = 0;
      for(nPidsi=0; pidsiArr[nPidsi].name; nPidsi  );          // Initialize PROPSPEC for the properties you want.
      PROPSPEC *pPropSpec = new PROPSPEC [nPidsi];
      PROPVARIANT *pPropVar = new PROPVARIANT [nPidsi];          for(int i=0; iReadMultiple(nPidsi, pPropSpec, pPropVar);          if(FAILED(hr)) {
         printf("IPropertyStg::ReadMultiple() failed w/error lx\n",
                hr);
      }
      else {
         // Dump properties.
         for(i=0; iRelease();       }       // Dump's custom properties of a property storage.
   void DumpCustomProps(IPropertySetStorage *pPropSetStg) {
      printf("\n==================================================\n");
      printf("Custom Properties...\n");
      printf("==================================================\n");          IPropertyStorage *pPropStg = NULL;
      HRESULT hr;
      IEnumSTATPROPSTG *pEnumProp;          // Open User-Defined-Properties, getting an IpropertyStorage.
      hr = pPropSetStg->Open(FMTID_UserDefinedProperties,
         STGM_READ | STGM_SHARE_EXCLUSIVE, &pPropStg);
      if(FAILED(hr)) {
         printf("No User Defined Properties.\n");
         return;
      }          // Get property enumerator.
      hr = pPropStg->Enum(&pEnumProp);
      if(FAILED(hr)) {
      pPropStg->Release();
         printf("Couldn't enumerate custom properties.\n");
         return;
      }          // Enumerate properties.
      STATPROPSTG sps;
      ULONG fetched;
      PROPSPEC propSpec[1];
      PROPVARIANT propVar[1];
      while(pEnumProp->Next(1, &sps, &fetched) == S_OK) {
         // Build a PROPSPEC for this property.
         ZeroMemory(&propSpec[0], sizeof(PROPSPEC));
         propSpec[0].ulKind = PRSPEC_PROPID;
         propSpec[0].propid = sps.propid;             // Read this property.             hr = pPropStg->ReadMultiple(1, &propSpec[0], &propVar[0]);
         if(!FAILED(hr)) {
            // Translate Prop name into ASCII.
            char dbcs[1024];
            char *pbstr = (char *)sps.lpwstrName;
            int i = wcstombs(dbcs, sps.lpwstrName,
                             *((DWORD *)(pbstr-4)));
            dbcs[i] = 0;                // Dump this property.
            printf("s: ", dbcs);
            DumpPropVariant(&propVar[0]);
         }
      }          // Release obtained interface.
      pEnumProp->Release();
      pPropStg->Release();       }       // Dump's custom and built-in properties of a compound document.
   void DumpProps(char *filename) {
      // Translate filename to Unicode.
      WCHAR wcFilename[1024];
      setlocale( LC_ALL, "" );
      int i = mbstowcs(wcFilename, filename, strlen(filename));
      setlocale( LC_ALL, "C" );
      wcFilename[i] = 0;          IStorage *pStorage = NULL;
      IPropertySetStorage *pPropSetStg = NULL;
      HRESULT hr;          // Open the document as an OLE compound document.
      hr = ::StgOpenStorage(wcFilename, NULL,
      STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);          if(FAILED(hr)) {
         if(hr == STG_E_FILENOTFOUND)
            printf("File not found.");
         else if(hr == STG_E_FILEALREADYEXISTS)
            printf("Not a compound file.");
         else
            printf("StgOpenStorage() failed w/error lx", hr);
         return;
      }          // Obtain the IPropertySetStorage interface.
      hr = pStorage->QueryInterface(
              IID_IPropertySetStorage, (void **)&pPropSetStg);
      if(FAILED(hr)) {
         printf("QI for IPropertySetStorage failed w/error lx", hr);
         pStorage->Release();
         return;
      }          // Dump properties.
      DumpBuiltInProps(pPropSetStg);
      DumpCustomProps(pPropSetStg);          // Release obtained interfaces.
      pPropSetStg->Release();
      pStorage->Release();
   }       // Program entry-point.
   void main(int argc, char **argv) {
      // Validate arguments.
      if(argc != 2) {
         printf("- OLE Document Property Viewer\n");
         printf("- Usage: %s filename", argv[0]);
         return;
      }          // Pass filename to the subroutine.
      DumpProps(argv[1]);
   }
聯盟----Visita網站http://www.vista.org.tw ---[ 發問前請先找找舊文章 ]---
maggie
一般會員


發表:6
回覆:12
積分:3
註冊:2002-03-13

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-01-14 16:58:36 IP:139.223.xxx.xxx 未訂閱
引言: 請問你要什麼資料?
其實我要的就是「摘要資訊」裡面所有的欄位,雖然一般只有作者有出現資訊, 所以我想做的就是當欄位內有資料時,就秀出來,沒有資料,那我也可以把它新增進去,就是這樣.. 看似簡單..卻是我的大難題了... 謝謝你....
系統時間:2024-06-26 7:54:27
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!