Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Transforming Excel data to Xml

I am using Excel 2000 with c#, i want to transform Excel data to Xml.
I am able to do so using OleDbConnection, then transferring data to
dataset and generating xml from dataset, but the solution is not that
effective. If anybody can suggest me other alternatives or even post
sample code, it will be of great use. its Little urgent for me.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Transforming Excel data to Xml

I'm definitely NOT an expert on XML,

and I dont know if it is a lot different from your approach.

it uses an interim workbook.. then uses ADO to read it directly thru the
Jet engine. The resulting recordset is then saved in XML format.

one thing.. it's simple :)


Sub SaveAsXml()
Dim cn As Object, rs As Object
Dim rg As Range
Dim cl As Range
Const cNAME = "Adummy"
Dim sPath$, sBook$, sList$

Set rg = Selection.CurrentRegion

If rg.Rows.Count < 2 Or rg.Columns.Count < 2 Then
MsgBox "Make sure you select proper range"
Exit Sub
End If
If ThisWorkbook.Path = "" Then
sPath = VBA.CurDir
Else
sPath = ThisWorkbook.Path & "\"
End If

If Dir(sPath & cNAME & ".xls") < "" Then Kill sPath & cNAME & ".xls"
If Dir(sPath & cNAME & ".xml") < "" Then Kill sPath & cNAME & ".xml"


With Workbooks.Add(xlWBATWorksheet)
.Worksheets(1).Name = "Table"
.Worksheets(1).Cells(1).Resize(rg.Rows.Count, rg.Columns.Count).Value =
rg.Value
.SaveAs sPath & cNAME & ".xls"
.Close 0
End With

Set cn = CreateObject("ADODB.Connection")
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.CursorLocation = 3 'adUseClient
cn.Properties("Extended Properties") = "Excel 8.0;IMEX=1;HDR=YES"
cn.Properties("Data Source") = sPath & cNAME & ".xls"

cn.Open
Set rs = cn.Execute("[Table$]", , 2) ' adCmdTable
rs.Save sPath & cNAME & ".xml", 1 ' adPersistXML
rs.Close
cn.Close

End Sub





keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(viswas_p) wrote:

I am using Excel 2000 with c#, i want to transform Excel data to Xml.
I am able to do so using OleDbConnection, then transferring data to
dataset and generating xml from dataset, but the solution is not that
effective. If anybody can suggest me other alternatives or even post
sample code, it will be of great use. its Little urgent for me.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transforming data in column into a linear text string mocha99 Excel Discussion (Misc queries) 2 August 11th 09 07:25 PM
transforming rank data David Schwartz Excel Discussion (Misc queries) 3 January 31st 09 06:33 PM
Data transforming and zigzag figure poltting yoyo2000 Excel Discussion (Misc queries) 0 September 13th 05 05:22 PM
Transforming Data Murtaza Links and Linking in Excel 4 August 23rd 05 07:19 PM
Transforming a worksheet's functionality? Arlen Excel Discussion (Misc queries) 1 February 4th 05 10:57 PM


All times are GMT +1. The time now is 07:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"