17. maj 2005 - 08:37Der er
7 kommentarer og 1 løsning
Eksportere som XML
I mit program oprettes en logfil i HTML, hvilket i og for sig er godt nok, men jeg ville gerne have filen i XML format i stedet, hvilket kan klares med ExportXML acExportQuery, "qryOverførLogtabel", "C:\MinFil.xml", , "C:\MitSchema.xsl"
Men de filer jeg får ud af det ligner CRAP i IE, det var jo ikke meningen. Hvad kan jeg gøre for BÅDE at få det i XML OG så det ser "godt ud"?
Hi puppetmaster I havent played around with XML so much, and almost not at all in Access so I dont think I can help so mcuh here but maybe a little input may help you on your way. Waht is wrong with the XML you are exporting? You have to remember that Access is only exporting the data as it is in the table, so there is no formatting fo your data. You would nee to modify the XSD if you want to format your data so it looks nice.
Hm - hvis en wizard i Access kan exportere en tabel med xml, xsl og xsd, så kan det også skrives i vba. BTW 'formatteringen' ligger vel i xsl filen ?
f.eks:
Function FormatFromXSL(strRef, strFormat, iNumDecimals, LCID, nType) FormatFromXSL = ToString(Format(GetValue(strRef, nType), strFormat, iNumDecimals, LCID, nType)) End Function
Function Format(varValue, strFormat, iNumDecimals, LCID, nType) Dim FormatTemp Dim strTemp
If IsDate(varValue) Then Select Case strFormat Case "General Date" FormatTemp = FormatDateTime(varValue, vbGeneralDate) Case "Long Date" FormatTemp = FormatDateTime(varValue, vbLongDate) Case "Medium Date" FormatTemp = Day(varValue) & "-" & MonthName(Month(varValue), True) & "-" & Mid(Year(varValue), 3, 2) Case "Short Date" FormatTemp = FormatDateTime(varValue, vbShortDate) Case "Long Time" FormatTemp = FormatDateTime(varValue, vbLongTime) Case "Medium Time" strTemp = FormatDateTime(varValue, vbLongTime) If (IsNumeric(Mid(strTemp, 2, 1))) Then FormatTemp = Mid(strTemp,1,5) & Mid(strTemp, 9) Else FormatTemp = Mid(strTemp,1,4) & Mid(strTemp, 9) End If Case "Short Time" FormatTemp = FormatDateTime(varValue, vbShortTime) Case Else Select Case LCase(strFormat) Case "yyyy", "q", "m", "y", "d", "w", "ww", "h", "n", "s" FormatTemp = DatePart(LCase(strFormat), varValue) Case Else ' This does not currently support custom formats such as dd-mmm-yyyy FormatTemp = FormatDateTime(varValue, vbGeneralDate) End Select End Select ElseIf IsNumeric(varValue) Then Select Case strFormat Case "General Number" FormatTemp = varValue Case "Currency" FormatTemp = FormatCurrencyPerLocale(varValue, iNumDecimals, LCID) Case "Euro" ' This does not really support the Euro format. FormatTemp = FormatCurrencyPerLocale(varValue, iNumDecimals, LCID) Case "Fixed" If IsNumeric(iNumDecimals) Then FormatTemp = FormatNumber(varValue, iNumDecimals, vbTrue, vbUseDefault, vbFalse) Else FormatTemp = FormatNumber(varValue, 2, vbTrue, vbUseDefault, vbFalse) End If Case "Standard" If IsNumeric(iNumDecimals) Then FormatTemp = FormatNumber(varValue, iNumDecimals, vbUseDefault, vbUseDefault, vbTrue) Else FormatTemp = FormatNumber(varValue, 2, vbUseDefault, vbUseDefault, vbTrue) End If Case "Percent" If IsNumeric(iNumDecimals) Then FormatTemp = FormatPercent(varValue, iNumDecimals) Else FormatTemp = FormatPercent(varValue) End If Case "Scientific" Dim nExp Dim nValue If (varValue = 0) Then nExp = 0 Else nExp = Int(Log(Abs(varValue)) / Log(10)) End If nValue = Round(CDbl(varValue)/(10^CDbl(nExp)), 2) If (Sgn(nExp) < 0) Then FormatTemp = FormatNumber(nValue, 2, vbTrue, vbFalse, vbFalse) & "E" & nExp Else FormatTemp = FormatNumber(nValue, 2, vbTrue, vbFalse, vbFalse) & "E+" & nExp End If Case "True/False" If (CBool(varValue)) Then FormatTemp = "True" Else FormatTemp = "False" End If Case "Yes/No" If (CBool(varValue)) Then FormatTemp = "Yes" Else FormatTemp = "No" End If Case "On/Off" If (CBool(varValue)) Then FormatTemp = "On" Else FormatTemp = "Off" End If Case Else ' This is a custom format If nType = 6 Then ' This is a currency FormatTemp = FormatCurrencyPerLocale(varValue, iNumDecimals, LCID) End If End Select End If
Har du kigget på de extra features, der er i 2003 udgaven af
ExportXML Method To keep from breaking solutions that were built on the current version of the ExportXML method, new behavior was added to the method using optional parameters.
ExportXML (ObjectType As AcExportXMLObjectType, Datasource As String, [DataTarget As String], [SchemaTarget As String], [PresentationTarget as String], [ImageTarget As String], [Encoding As AcExportXMLEncoding], [OtherFlags As Long], [WhereCondition As String], [AdditionalData as AdditionalData])
Export Data, Schema, Formatting, and Related Tables to XML This subroutine exports the table called Orders in the current database as well as a number of related tables to an XML file. The schema and the formatting are also exported as separate .xsd and .xsl files, respectively. Existing files are overwritten. This procedure assumes that you have a database with tables named Categories, Customers, Employees, Orders, Orders Details, Orders Details Details, Products, Product Details, Product Details Details, Shippers, and Suppliers. You also need a hard drive formatted as C: to run the procedure as is.
Private Sub ExportRelTables() ' Purpose: Exports the Orders table as well as ' a number of related database to an XML file. ' XSD and XSL files are also created.
Dim objAD As AdditionalData
' Create the AdditionalData object. Set objAD = Application.CreateAdditionalData
' Add the related tables to the object. With objAD .Add "Order Details" objAD(Item:="Order Details").Add "Order Details Details" .Add "Customers" .Add "Shippers" .Add "Employees" .Add "Products" objAD(Item:="Products").Add "Product Details" objAD(Item:="Products")(Item:="Product Details").Add _ "Product Details Details" .Add "Suppliers" .Add "Categories" End With Application.ExportXml acExportTable, "Orders", _ "C:\Orders.xml", "C:\OrdersSchema.xsd", _ "C:\OrdersStyle.xsl", AdditionalData:= objAD End Sub
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.