Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Microsoft Office и VBA программирование > Microsoft Office Excel
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 20.03.2012, 23:50   #21
doober
Старожил
 
Аватар для doober
 
Регистрация: 02.05.2009
Сообщений: 3,907
По умолчанию

Попробуйте так
Код:
Sub ExtportToXML()
    Dim objDoc As MSXML2.DOMDocument
    Dim objNode As MSXML2.IXMLDOMNode
    Dim objRoot As MSXML2.IXMLDOMElement
    Dim objElem As MSXML2.IXMLDOMElement
     Dim objElem0 As MSXML2.IXMLDOMElement
    Dim ar As Variant
    Dim i As Integer
    Set objDoc = New DOMDocument
    objDoc.resolveExternals = True
    Set objNode = objDoc.createProcessingInstruction( _
        "xml", "version='1.0' encoding='windows-1251'")
    Set objNode = objDoc.InsertBefore(objNode, _
    objDoc.ChildNodes.Item(0))
    Set objRoot = objDoc.createElement("Aaiiua")
    Set objDoc.DocumentElement = objRoot
   i = 1
  Do
    Set objElem0 = objDoc.createElement("list_clients")
        objRoot.appendChild objElem0
                              
        Set objNode = objDoc.createElement("id_merch")
            objNode.Text = Cells(i, 1)
            objElem0.appendChild objNode
            
        Set objElem = objDoc.createElement("client_info")
            objElem.setAttribute "ident", Cells(i, 2)
            objNode.appendChild objElem
            objElem.setAttribute "info", Cells(i, 3)
            objElem0.appendChild objElem

        Set objElem = objDoc.createElement("client_info")
            objElem.setAttribute "ident", Cells(i, 4)
            objRoot.appendChild objElem
            objElem.setAttribute "info", Cells(i, 5)
            objElem0.appendChild objElem
            objElem.setAttribute "rest", Cells(i, 6)
           objElem0.appendChild objElem

      i = i + 1
 Loop Until Cells(i, 1) = ""
    objDoc.Save strFilePath
End Sub
Анализ,обработка данных Недорого
doober вне форума Ответить с цитированием
Старый 20.03.2012, 23:58   #22
Evrica
 
Аватар для Evrica
 
Регистрация: 24.07.2010
Сообщений: 7
По умолчанию

Спасибо большое! Работает!)
Evrica вне форума Ответить с цитированием
Старый 21.03.2012, 16:13   #23
Evrica
 
Аватар для Evrica
 
Регистрация: 24.07.2010
Сообщений: 7
По умолчанию

оказывается немного не так нужно)
вид должен быть такой :

Код:
<?xml version="1.0" encoding="WINDOWS-1251"?> 
<list_clients>
<id_merch>1</id_merch>
<client_info ident="1" info="ФИО" />
<client_info inent="2" info="ФИО" />
<client_info ident="3" info="ФИО" />
</list_clients>
т.е. чтобы <id_merch> не повторялась и был только один тег <list_clients>
как так сделать? Код макроса выше
Evrica вне форума Ответить с цитированием
Старый 21.03.2012, 16:59   #24
doober
Старожил
 
Аватар для doober
 
Регистрация: 02.05.2009
Сообщений: 3,907
По умолчанию

Без файла Excel и схемы XML(желательно файл .xsd) угадывать больше не буду
Анализ,обработка данных Недорого

Последний раз редактировалось doober; 21.03.2012 в 17:12.
doober вне форума Ответить с цитированием
Старый 21.03.2012, 17:15   #25
Evrica
 
Аватар для Evrica
 
Регистрация: 24.07.2010
Сообщений: 7
По умолчанию

почти сделал...только не знаю как добавить <id_merch> вначале,чтобы не повторялся
схемы вроде нету)

P.S. добавил схему
Вложения
Тип файла: rar Экспорт из Excel в xml.rar (28.2 Кб, 37 просмотров)
Тип файла: rar TestXML.rar (420 байт, 27 просмотров)

Последний раз редактировалось Evrica; 21.03.2012 в 17:38.
Evrica вне форума Ответить с цитированием
Старый 21.03.2012, 22:49   #26
doober
Старожил
 
Аватар для doober
 
Регистрация: 02.05.2009
Сообщений: 3,907
По умолчанию

у вас согласно схемы все верно получается
Код:
<list_clients>
<client_info rest="2382,41р." info="Петров" ident="1"/>
<client_info rest="2340,80р." info="Иванов" ident="2"/>
<client_info rest="1227,74р." info="Чернов" ident="3"/>
<client_info rest="2393,38р." info="Петров" ident="4"/>
<client_info rest="2382,41р." info="Иванов" ident="5"/>
<client_info rest="2340,80р." info="Чернов" ident="6"/>
<client_info rest="1227,74р." info="Петров" ident="7-8"/>
<client_info rest="2393,38р." info="Иванов" ident="9-10"/>
<client_info rest="2382,41р." info="Чернов" ident="11"/>
</list_clients>
Так должно быть?

Код:
−
	<list_clients>
<id_merch>1</id_merch>
<client_info rest="2382,41р." info="Петров" ident="1"/>
<id_merch>2</id_merch>
<client_info rest="2340,80р." info="Иванов" ident="2"/>
<id_merch>3</id_merch>
<client_info rest="1227,74р." info="Чернов" ident="3"/>
<id_merch>4</id_merch>
<client_info rest="2393,38р." info="Петров" ident="4"/>
<id_merch>5</id_merch>
<client_info rest="2382,41р." info="Иванов" ident="5"/>
<id_merch>6</id_merch>
<client_info rest="2340,80р." info="Чернов" ident="6"/>
<id_merch>7-8</id_merch>
<client_info rest="1227,74р." info="Петров" ident="7-8"/>
<id_merch>9-10</id_merch>
<client_info rest="2393,38р." info="Иванов" ident="9-10"/>
<id_merch>11</id_merch>
<client_info rest="2382,41р." info="Чернов" ident="11"/>
</list_clients>
Анализ,обработка данных Недорого

Последний раз редактировалось doober; 21.03.2012 в 22:51.
doober вне форума Ответить с цитированием
Старый 21.03.2012, 22:52   #27
Evrica
 
Аватар для Evrica
 
Регистрация: 24.07.2010
Сообщений: 7
По умолчанию

Нет, должно быть так:

Код:
<list_clients>
<id_merch>123</id_merch>
<client_info rest="2382,41р." info="Петров" ident="1"/>
<client_info rest="2340,80р." info="Иванов" ident="2"/>
<client_info rest="1227,74р." info="Чернов" ident="3"/>
<client_info rest="2393,38р." info="Петров" ident="4"/>
<client_info rest="2382,41р." info="Иванов" ident="5"/>
<client_info rest="2340,80р." info="Чернов" ident="6"/>
<client_info rest="1227,74р." info="Петров" ident="7-8"/>
<client_info rest="2393,38р." info="Иванов" ident="9-10"/>
<client_info rest="2382,41р." info="Чернов" ident="11"/>
</list_clients>
Evrica вне форума Ответить с цитированием
Старый 22.03.2012, 00:03   #28
doober
Старожил
 
Аватар для doober
 
Регистрация: 02.05.2009
Сообщений: 3,907
По умолчанию

Не мог долго на сайт зайти

Код:
Const strFilePath As String = "C:\TestXML1.xml"

Sub ExtportToXML()
        Dim objDoc As MSXML2.DOMDocument
        Dim objNode As MSXML2.IXMLDOMNode
        Dim objRoot As MSXML2.IXMLDOMElement
        Dim objElem As MSXML2.IXMLDOMElement
        Dim objElem0 As MSXML2.IXMLDOMElement
        Dim ar As Variant
        Dim i As Integer
        Set objDoc = New DOMDocument
        objDoc.resolveExternals = True
        Set objNode = objDoc.createProcessingInstruction( _
                      "xml", "version='1.0' encoding='windows-1251'")
        Set objNode = objDoc.InsertBefore(objNode, _
                                          objDoc.ChildNodes.Item(0))
        Set objRoot = objDoc.createElement("list_clients")
        Set objDoc.DocumentElement = objRoot
        Set objNode = objDoc.createElement("id_merch")
        objNode.Text = 123
        objRoot.appendChild objNode
        i = 1
        Do
                Set objElem = objDoc.createElement("client_info")
                objElem.setAttribute "rest", Cells(i, 3)

                objElem.setAttribute "info", Cells(i, 2)

                objElem.setAttribute "ident", Cells(i, 1)
                objRoot.appendChild objElem


                i = i + 1
        Loop Until Cells(i, 1) = ""
        objDoc.Save strFilePath
End Sub
Анализ,обработка данных Недорого
doober вне форума Ответить с цитированием
Старый 22.03.2012, 00:14   #29
Evrica
 
Аватар для Evrica
 
Регистрация: 24.07.2010
Сообщений: 7
По умолчанию

как все оказывается просто)) была такая идея, но что-то не получилось у меня)
Спасибо большое!
Evrica вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
xml to xls, xlsx Diego__ Microsoft Office Excel 4 10.12.2010 10:42
XLS converter XML edition Microsoft Office Excel 1 22.09.2010 19:32
Сonvert из .XML в .CSV или .XLS edition Microsoft Office Excel 1 20.07.2010 21:43
Экспорт xls на xml armagedon_atyrau Microsoft Office Excel 9 29.06.2010 15:52
экспорт из xls в xml для excell 2000 zzz007 Microsoft Office Excel 0 20.08.2009 22:47