文章編號: 305795 - 上次校閱: 2002年10月27日 - 版次: 1.0

如何: 匯入和匯出 XML],在 Excel 中

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。

在此頁中

全部展開 | 全部摺疊

結論

使用使用 Microsoft Excel 以手動方式和程式設計的方式匯入並設定格式的 XML 資料匯出此逐步教學指南。

XML 是 defacto 工業標準,可傳輸資料周圍網際網路。 Microsoft Excel 和 Microsoft Access 都支援匯入及匯出 XML 資料。

需求

您應該具備下列的知識:
  • Excel 的基本概念。
  • 程式設計概念。
  • XML 概念。

手動匯出 XML 資料

  1. 在 [檔案] 功能表上按一下 [另存]。
  2. 在 [存檔類型] 清單中,選取 XML 試算表
  3. 您的檔案名稱。如果要將檔案儲存到 Web 伺服器,包括地址。按一下 [儲存]。
如果有不支援這類的應用程式程式碼的 Visual Basic 的 XML 中的功能在活頁簿中會出現一則訊息,指出這。

以程式設計的方式匯出 XML 資料

  1. 在一個 Excel Visual Basic] 中的應用程式專案,插入新的模組。
  2. 在模組中建立呼叫 ExportXML 一個副程式。
  3. 輸入或貼上下列程式碼:
    ' <http://Myserver/Myfolder/xml filename.xml> represents the Web server 
    ' location and the name of the XML file you want to save. You can also 
    ' specify a folder on your hard disk rather than a URL.
    '
    ActiveWorkbook.SaveAs _
       Filename:="<http://Myserver/Myfolder/xml filename.xml>", _
       FileFormat:=xlXMLSpreadsheet
    					

以手動方式匯入 XML 資料

  1. 啟動 Excel,然後按一下 [在 [檔案] 功能表上的 [開啟舊檔]。
  2. 在 [檔案類型] 清單中,選取 XML 檔案
  3. 請選取您想要開啟,然後按一下 [開啟舊檔 的 XML 檔案。
  4. 如果檔案多個 XSL 樣式表將提示您選取其中一個樣式表。如果您想 appy 樣式表,請選取樣式表。或按一下 [取消] 以不選取 [樣式表。

以程式設計的方式匯入 XML 資料

  1. 在一個 Excel Visual Basic] 中的應用程式專案,插入新的模組。
  2. 在模組中建立稱為 ImportXML 一個副程式。
  3. 輸入或貼上下列程式碼:
    ' <http://Myserver/Myfolder/xml filename.xml> represents the Web server 
    ' location and the name of the XML file you want to save. You can also 
    ' specify a folder on your hard disk rather than a URL.
    '
    ' If the XML file references more than one style sheet,
    ' use the StyleSheets parameter to specify one or more style
    ' sheets. If you want to apply only one referenced style sheet, 
    ' specify the index number of that sheet reference in the document.
    ' If you want to apply multiple style sheets, enter all 
    ' the index numbers as members of an array, similar to this: 
    '
    ' Array(1, 2)
    '
    ' In this case, the first and second style sheets are referenced in 
    ' the XML file.
    '
    Workbooks.OpenXML "<http://Myserver/Myfolder/xml filename.xml>", _
    	<style sheet>
    
    					

正在確認它運作

  1. 建立 XML 檔案。
  2. 在 Excel 中執行程式碼。














這篇文章中的資訊適用於:
  • Microsoft Office XP Developer Edition
關鍵字:?
kbmt kbhowto kbhowtomaster KB305795 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:305795? (http://support.microsoft.com/kb/305795/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。