简体   繁体   中英

How do I open and populate a .XML file in a sheet in Excel using VB.Net?

I am looking for a way to open and populate a new sheet while population the sheet from a file.xml.

Any ideas?

Thanks

  1. Include a reference to 'Microsoft.Office.Interop.Excel' in your project
  2. Then do something like this:
Imports Microsoft.Office.Interop.Excel
Public Class ReadExcel
    Public Sub OpenDoc(ByVal Filename As String)
        Dim excelApp As New Microsoft.Office.Interop.Excel.Application
        excelApp.Workbooks.OpenXML(Filename)
        ' do something here...
    End Sub
End Class

In addition to what Derek Tomes has answered, you can specify the loading options for the openXML method.

  • xlXmlLoadImportToList = 2
  • xlXmlLoadMapXml = 3
  • xlXmlLoadOpenXml = 1
  • xlXmlLoadPromptUser = 0

You may use xlXmlLoadImportToList to open a new workbook with the xml data you want to load or you may use xlXmlLoadOpenXml to open the xml file itself in excel.

you can hide the alerts with the DisplayAlerts property set to false when loading your xml then just set it to true afterwards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM