ข้ามไปที่เนื้อหาหลัก
การสนับสนุน
ลงชื่อเข้าใช้
ลงชื่อเข้าใช้ด้วย Microsoft
ลงชื่อเข้าใช้หรือสร้างบัญชี
สวัสดี
เลือกบัญชีอื่น
คุณมีหลายบัญชี
เลือกบัญชีที่คุณต้องการลงชื่อเข้าใช้

To import and export XML data in Excel, an XML Map that associates XML elements with data in cells to get the results you want will be useful. To create one, you need to have an XML schema file (.xsd) and an XML data file (.xml). After creating the XML Map, you can map XML elements the way you want.

เคล็ดลับ: You'll find more information about using XML with Excel in this overview of XML in Excel.

Locate or create XML schema and XML data files

If another database or application created an XML schema or XML data file, you might already have them available. For example, you might have a line-of-business application that exports data into these XML file formats, a commercial web site or web service that supplies these XML files, or a custom application developed by your IT department that automatically creates these XML files.

If you don’t have the necessary XML files, you can create them by saving the data you want to use as a text file. You can then use both Access and Excel to convert that text file to the XML files you need. Here’s how:

Access

  1. Import the text file you want to convert and link it to a new table.

    1. คลิก ไฟล์ > เปิด

    2. In the Open dialog box, select and open the database in which you want to create a new table.

    3. Click External Data > Text File, and follow the instructions for each step, making sure that you link the table to the text file.

      Access จะสร้างตารางใหม่และแสดงตารางนั้นในบานหน้าต่างนำทาง

  2. ส่งออกข้อมูลจากตารางที่เชื่อมโยงไปยังไฟล์ข้อมูลแบบ XML และไฟล์ XML Schema

    1. Click External Data > XML File (in the Export group).

    2. In the Export - XML File dialog box, specify the file name and format, and click OK.

  3. ออกจาก Access

Excel

  1. Create an XML Map based on the XML schema file you exported from Access.

    If the Multiple Roots dialog box appears, make sure you choose dataroot so you can create an XML table.

  2. Create an XML table by mapping the dataroot element. See Map XML elements for more information.

  3. Import the XML file you exported from Access.

หมายเหตุ: 

  • There are several types of XML schema element constructs Excel doesn't support. The following XML schema element constructs can't be imported into Excel:

  • <>ใดๆ     องค์ประกอบนี้ทำให้คุณสามารถรวมองค์ประกอบที่ไม่ได้ประกาศโดย Schema ได้

  • <>anyAttribute     องค์ประกอบนี้ทำให้คุณสามารถรวมแอตทริบิวต์ที่ไม่ได้ประกาศโดย Schema ได้

  • Recursive structures    A common example of a recursive structure is a hierarchy of employees and managers in which the same XML elements are nested several levels. Excel doesn't support recursive structures more than one level deep.

  • องค์ประกอบที่เป็นนามธรรม    องค์ประกอบเหล่านี้มีไว้เพื่อประกาศใน Schema แต่ไม่เคยใช้เป็นองค์ประกอบ องค์ประกอบที่เป็นนามธรรมขึ้นอยู่กับองค์ประกอบอื่นๆ ที่จะถูกแทนที่สําหรับองค์ประกอบที่เป็นนามธรรม

  • กลุ่มการทดแทน    กลุ่มเหล่านี้อนุญาตให้องค์ประกอบสลับกันได้ทุกที่ที่อ้างอิงองค์ประกอบอื่น องค์ประกอบระบุว่าเป็นสมาชิกของกลุ่มทดแทนขององค์ประกอบอื่นผ่านแอตทริบิวต์ <substitutionGroup>

  • เนื้อหาผสม    เนื้อหานี้ถูกประกาศโดยใช้ mixed="true" ในข้อกําหนดชนิดที่ซับซ้อน Excel ไม่สนับสนุนเนื้อหาแบบง่ายของชนิดที่ซับซ้อน แต่จะสนับสนุนแท็กและแอตทริบิวต์ลูกที่กําหนดไว้ในชนิดที่ซับซ้อนนั้น

Use sample XML schema and XML data files

The following sample data has basic XML elements and structures you can use to test XML mapping if you don't have XML files or text files to create the XML files. Here’s how you can save this sample data to files on your computer:

  1. Select the sample text of the file you want to copy, and press Ctrl+C.

  2. Start Notepad, and press Ctrl+V to paste the sample text.

  3. Press Ctrl+S to save the file with the file name and extension of the sample data you copied.

  4. Press Ctrl+N in Notepad and repeat step 1-3 to create a file for the second sample text.

  5. ออกจาก Notepad

ตัวอย่างข้อมูลแบบ XML (Expenses.xml)

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Root>
  <EmployeeInfo>
    <Name>Jane Winston</Name>
    <Date>2001-01-01</Date>
    <Code>0001</Code>
  </EmployeeInfo>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Airfare</Description>
    <Amount>500.34</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Hotel</Description>
    <Amount>200</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Taxi Fare</Description>
    <Amount>100.00</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Long Distance Phone Charges</Description>
    <Amount>57.89</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-01</Date>
    <Description>Food</Description>
    <Amount>82.19</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-02</Date>
    <Description>Food</Description>
    <Amount>17.89</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-02</Date>
    <Description>Personal Items</Description>
    <Amount>32.54</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-03</Date>
    <Description>Taxi Fare</Description>
    <Amount>75.00</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-03</Date>
    <Description>Food</Description>
    <Amount>36.45</Amount>
  </ExpenseItem>
  <ExpenseItem>
    <Date>2001-01-03</Date>
    <Description>New Suit</Description>
    <Amount>750.00</Amount>
  </ExpenseItem>
</Root>

ตัวอย่าง XML Schema (Expenses.xsd)

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="Root">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element minOccurs="0" maxOccurs="1" name="EmployeeInfo">
          <xsd:complexType>
            <xsd:all>
              <xsd:element minOccurs="0" maxOccurs="1" name="Name" />
              <xsd:element minOccurs="0" maxOccurs="1" name="Date" />
              <xsd:element minOccurs="0" maxOccurs="1" name="Code" />
            </xsd:all>
          </xsd:complexType>
        </xsd:element>
        <xsd:element minOccurs="0" maxOccurs="unbounded" name="ExpenseItem">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="Date" type="xsd:date"/>
              <xsd:element name="Description" type="xsd:string"/>
              <xsd:element name="Amount" type="xsd:decimal" />
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

สร้างแมป XML

You create an XML Map by adding an XML schema to a workbook. The schema can be copied from an XML schema file (.xsd), or Excel can try to infer one from an XML data file (.xml).

  1. Click Developer > Source.

    คำสั่ง XML บนแท็บ นักพัฒนา

    ถ้าคุณไม่เห็นแท็บ นักพัฒนา ให้ดูที่ แสดงแท็บนักพัฒนา

  2. In the XML Source task pane, click XML Maps, and then click Add.

  3. ในรายการ มองหาใน ให้คลิกไดรฟ์ โฟลเดอร์ หรือตำแหน่งบนอินเทอร์เน็ตที่มีไฟล์ที่คุณต้องการเปิด

  4. คลิกที่ไฟล์แล้วคลิก เปิด

    • For an XML schema file, XML will create an XML Map based on the XML schema. If the Multiple Roots dialog box appears, choose one of the root nodes defined in the XML schema file.

    • For an XML data file, Excel will try to infer the XML schema from the XML data, and then creates an XML Map.

  5. คลิก ตกลง

    The XML Map appears in the XML Source task pane.

แมปองค์ประกอบ XML

คุณสามารถแมปองค์ประกอบ XML กับเซลล์ที่แมปเซลล์เดียวและเซลล์ที่เกิดซ้ำได้ในตาราง XML เพื่อให้คุณสามารถสร้างความสัมพันธ์ระหว่างเซลล์และองค์ประกอบข้อมูลแบบ XML ใน XML Schema ได้

  1. Click Developer > Source.

    คำสั่ง XML บนแท็บ นักพัฒนา

    ถ้าคุณไม่เห็นแท็บ นักพัฒนา ให้ดูที่ แสดงแท็บนักพัฒนา

  2. In the XML Source task pane, select the elements you want to map.

    To select nonadjacent elements, click one element, and then hold down Ctrl and click each element you want to map.

  3. เมื่อต้องการแมปองค์ประกอบ ให้ทำดังนี้

    1. Right-click the selected elements, and click Map element.

    2. In the Map XML elements dialog box, select a cell and click OK.

      เคล็ดลับ: คุณยังสามารถลากองค์ประกอบที่เลือกไปยังตำแหน่งในเวิร์กชีตที่คุณต้องการให้องค์ประกอบนั้นปรากฏได้อีกด้วย

      องค์ประกอบแต่ละรายการจะปรากฏเป็นชนิดตัวหนาในบานหน้าต่างงาน แหล่ง XML เพื่อระบุว่ามีการแมปองค์ประกอบ

  4. เลือกวิธีที่คุณต้องการจัดการป้ายชื่อและส่วนหัวของคอลัมน์ดังนี้

    • เมื่อคุณลากองค์ประกอบ XML ที่ไม่เกิดซ้ำไปยังเวิร์กชีตเพื่อสร้างเซลล์ที่แมปเซลล์เดียว สมาร์ทแท็กที่มีคำสั่งสามรายการจะปรากฏ ซึ่งคุณสามารถใช้เพื่อควบคุมตำแหน่งของส่วนหัวหรือป้ายชื่อได้ดังนี้

      ข้อมูลของฉันมีส่วนหัวแล้ว    คลิกตัวเลือกนี้เพื่อละเว้นส่วนหัวขององค์ประกอบ XML เนื่องจากเซลล์มีส่วนหัวแล้ว (ทางด้านซ้ายหรือด้านบนของข้อมูล)

      วางส่วนหัว XML ไว้ด้านซ้าย    คลิกตัวเลือกนี้เพื่อใช้ส่วนหัวขององค์ประกอบ XML เป็นป้ายชื่อของเซลล์ (ด้านซ้ายของข้อมูล)

      วางส่วนหัว XML ไว้ด้านบน    คลิกตัวเลือกนี้เพื่อใช้ส่วนหัวขององค์ประกอบ XML เป็นส่วนหัวของเซลล์ (ด้านบนของข้อมูล)

    • เมื่อคุณลากองค์ประกอบ XML ที่เกิดซ้ําไปยังเวิร์กชีตเพื่อสร้างเซลล์ที่เกิดซ้ําในตาราง XML ชื่อองค์ประกอบ XML จะถูกใช้เป็นส่วนหัวของคอลัมน์สําหรับตารางโดยอัตโนมัติ อย่างไรก็ตาม คุณสามารถเปลี่ยนส่วนหัวของคอลัมน์เป็นส่วนหัวใดก็ได้ที่คุณต้องการโดยการแก้ไขเซลล์ส่วนหัวของคอลัมน์

      ในบานหน้าต่างงาน แหล่ง XML คุณสามารถคลิก ตัวเลือก เพื่อควบคุมลักษณะการทำงานของตาราง XML เพิ่มเติมได้ดังนี้

      ผสานองค์ประกอบเมื่อแมปโดยอัตโนมัติ    เมื่อมีการเลือกกล่องกาเครื่องหมายนี้ ตาราง XML จะขยายโดยอัตโนมัติ เมื่อคุณลากองค์ประกอบไปยังเซลล์ที่อยู่ติดกับตาราง XML

      ข้อมูลของฉันมีส่วนหัว    เมื่อมีการเลือกกล่องกาเครื่องหมายนี้ ข้อมูลที่มีอยู่สามารถใช้เป็นส่วนหัวของคอลัมน์ เมื่อคุณแมปองค์ประกอบที่เกิดซ้ำในเวิร์กชีตของคุณ

      หมายเหตุ: 

      • If all XML commands are dimmed, and you can't map XML elements to any cells, the workbook might be shared. Click Review > Share Workbook to verify that and to remove it from shared use as needed.

        If you want to map XML elements in a workbook you want to share, map the XML elements to the cells you want, import the XML data, remove all of the XML maps, and then share the workbook.

      • If you can't copy an XML table that contains data to another workbook, the XML table might have an associated XML Map that defines the data structure. This XML Map is stored in the workbook, but when you copy the XML table to a new workbook, the XML Map isn't automatically included. Instead of copying the XML table, Excel creates an Excel table that contains the same data. If you want the new table to be an XML table, do the following:

        1. Add an XML Map to the new workbook by using the .xml or .xsd file you used to create the original XML Map. You should save these files if you want to add XML Maps to other workbooks.

        2. แมปองค์ประกอบ XML ไปยังตารางเพื่อทำให้เป็นตาราง XML

      • When you map a repeating XML element to a merged cell, Excel unmerges the cell. This is expected behavior, because repeating elements are designed to work with unmerged cells only.

        You can map single, nonrepeating XML elements to a merged cell, but mapping a repeating XML element (or an element that contains a repeating element) to a merged cell isn't allowed. The cell will be unmerged, and the element will be mapped to the cell where the pointer is located.

เคล็ดลับ: 

  • คุณสามารถยกเลิกการแมปองค์ประกอบ XML ที่คุณไม่ต้องการใช้ หรือเพื่อป้องกันไม่ให้เนื้อหาของเซลล์ถูกเขียนทับเมื่อคุณนําเข้าข้อมูลแบบ XML For example, you could temporarily unmap an XML element from a single cell or repeating cells that have formulas you don't want to overwrite when you import an XML file. เมื่อการนําเข้าเสร็จสมบูรณ์ คุณสามารถแมปองค์ประกอบ XML ไปยังเซลล์สูตรอีกครั้ง เพื่อให้คุณสามารถส่งออกผลลัพธ์ของสูตรไปยังไฟล์ข้อมูลแบบ XML ได้

  • To unmap XML elements, right-click their name in the XML Source task pane, and click Remove element.

แสดงแท็บนักพัฒนา

ถ้าคุณไม่เห็นแท็บ นักพัฒนา ให้ทำดังต่อไปนี้เพื่อแสดงแท็บ

  • ใน Excel 2010 และเวอร์ชันที่ใหม่กว่า:

    1. คลิก ไฟล์ > ตัวเลือก

    2. คลิกประเภท กำหนด Ribbon เอง

    3. Under Main Tabs, check the Developer box, and click OK.

  • ใน Excel 2007 ให้ทำดังนี้

    1. คลิก ปุ่ม Microsoft Office รูปปุ่ม Office> ตัวเลือก Excel

    2. Click the Popular category.

    3. Under Top options for working with Excel, check the Show Developer tab in the Ribbon box, and click OK.

ดูเพิ่มเติม

ลบข้อมูลแมป XML ออกจากเวิร์กบุ๊ก

ผนวกหรือเขียนทับข้อมูล XML ที่แมป

ภาพรวมของ XML ใน Excel

นําเข้าข้อมูลแบบ XML

ส่งออกข้อมูลแบบ XML

ต้องการความช่วยเหลือเพิ่มเติมหรือไม่

ต้องการตัวเลือกเพิ่มเติมหรือไม่

สํารวจสิทธิประโยชน์ของการสมัครใช้งาน เรียกดูหลักสูตรการฝึกอบรม เรียนรู้วิธีการรักษาความปลอดภัยอุปกรณ์ของคุณ และอื่นๆ

ชุมชนช่วยให้คุณถามและตอบคําถาม ให้คําติชม และรับฟังจากผู้เชี่ยวชาญที่มีความรู้มากมาย

ข้อมูลนี้เป็นประโยชน์หรือไม่

คุณพึงพอใจกับคุณภาพภาษาเพียงใด
สิ่งที่ส่งผลต่อประสบการณ์ใช้งานของคุณ
เมื่อกดส่ง คำติชมของคุณจะถูกใช้เพื่อปรับปรุงผลิตภัณฑ์และบริการของ Microsoft ผู้ดูแลระบบ IT ของคุณจะสามารถรวบรวมข้อมูลนี้ได้ นโยบายความเป็นส่วนตัว

ขอบคุณสำหรับคำติชมของคุณ!

×