资源描述:
《EXCEL导出为指定的XML》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、导出前的EXCEL导出后的XML格式DimxmldocAsDOMDocumentDimverAsVariant'DimColAsIntegerDimRowAsIntegerDimiAsIntegerDimjAsIntegerDimkAsIntegerPrivateSubSaveAsXML_Click()Row=Application.WorksheetFunction.CountA(Columns("E"))'MsgBoxCells(1,1).ValueSetxmldoc=NewDOMDocumentSetver=xmldoc.cr
2、eateProcessingInstruction("xml","version="&Chr(34)&"1.0"&Chr(34)&"encoding=""gb2312""")xmldoc.appendChildverSetDeliverynode=xmldoc.createElement("Delivery")xmldoc.appendChildDeliverynodeFori=2ToRow-1IfIsEmpty(Cells(i,"C"))=FalseThenSetOrdernode=xmldoc.createElement("订单
3、")CreateAttributeOrdernode,"单据编号",Cells(i,"C")Deliverynode.appendChildOrdernodeCreateNodeOrdernode,"购货单位",Cells(i,"B")CreateNodeOrdernode,"日期",Cells(i,"A")SetDetailnode=xmldoc.createElement("Detail")Ordernode.appendChildDetailnodeIfIsEmpty(Cells(i,"C"))=FalseThenSetCat
4、alognode=xmldoc.createElement("Catalog")CreateAttributeCatalognode,"规格型号",Cells(i,"D")Detailnode.appendChildCatalognode'CreateNodeCatalognode,"规格型号",Cells(i,"D")CreateNodeCatalognode,"数量",Cells(i,"E")SetBarcodenode=xmldoc.createElement("Barcode")Catalognode.appendChild
5、BarcodenodeIfCells(i,6).Value="ok"OrCells(i,6).Value="OK"ThenCreateNodeBarcodenode,"编码",Cells(i,"F")ElseFork=1ToCells(i,5).ValueCreateNodeBarcodenode,"编码",Cells(i,k+5)NextEndIfForj=i+1ToRow-1IfIsEmpty(Cells(j,"C"))=TrueThenSetCatalognode=xmldoc.createElement("Catalog")
6、CreateAttributeCatalognode,"规格型号",Cells(j,"D")Detailnode.appendChildCatalognodeCreateNodeCatalognode,"数量",Cells(j,"E")SetBarcodenode=xmldoc.createElement("Barcode")Catalognode.appendChildBarcodenodeIfCells(j,6).Value="ok"OrCells(j,6).Value="OK"ThenCreateNodeBarcodenode
7、,"编码",Cells(j,"F")ElseFork=1ToCells(j,5).ValueCreateNodeBarcodenode,"编码",Cells(j,k+5)NextEndIfElsei=j-1ExitForEndIfNextEndIfEndIfNextxmldoc.save"C:DocumentsandSettingsAdministrator桌面转换后.xml"EndSubPrivateSubCreateNode(ByValparentAsIXMLDOMNode,ByValnodenameAsString,B
8、yValvalNodeAsString)DimnewnodeAsIXMLDOMNodeSetnewnode=parent.ownerDocument.createElement(nodename)newnode.Text=valNod