I
iyep
Hi everyone...A newbie is confuse here, so please help...and before we start,
please aplogize for my bad english
OK, lets start.
I have a task to make an XML file from unusual Excel file...i'm giving the
screenshot...please follow the link
So, as u can see that the spreadsheet is not a good looking one...and i've
been trying to convert it into an XML file....with reading many tutors...
The file (.xls) is different in the field name (such as "TMPT LHR" can be
"TMPT_LHR" or "TMPTLHR" in other xls file) between another...and it is make
me crazy doing for one single file...not yet another file
Here are methods that i tried:
1. with XML Schema in the Excel view source...not really good at it (my
kowledge). My test went bad, the XML file output doesn't go as i wish, it
messy..
2. Save As the spreadsheet as CSV, and i found it like this...please
follow the link...it more make me confuse..
3. Save As the spreadsheet as Text, and dont get any idea how to convert
it...
4. Save As the spreadsheet as XML Spreadsheet, and i try to read the
<data> tag/node in it and finally succeded reading the element string (inside
the <data>) Using VC#... and try to make a well formed XML file...this part
not done yet...
This is the code..
start***** this is the code for reading the node****
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
namespace test1
{
public partial class Form1 : Form
{
public String fileName;
public String dbconnect;
public String strNodeValues;
//public String[] strNodeValues3a = new String[3] { "", "", "" }; <-
the 3 top field from excel
//public String[] strNodeValues3b = new String[3] { "", "", "" }; <-
the 1 record under the 3 top filed
//public String[] strNodeValues15a = new String[15] { "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "" }; <- the 15 field under the 1
record
//public String[] strNodeValues15b = new String[15] { "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "" }; <- wish this line to held
the 15 data of 1 record, that can be not just one record...see pict above
please...
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
Stream myStream;
// String fileName;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "xml files (*.xml)|*.xml";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
myStream.Close();
fileName = openFileDialog1.FileName;
textBox1.Text = fileName;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(fileName);
while (reader.Read())
{
switch (reader.Name)
{
case "Data ":
reader.Read();
strNodeValues = reader.Value;
MessageBox.Show(reader.Value, "Ini " +
strNodeValues); <- i see it with message box.
break;
}
}
}
private void button7_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox2.Text);
}
private void button8_Click(object sender, EventArgs e)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
}
End***** this is the code for reading the node****
start***** this is the code (class file) for making the XML file**** I
edited it from a log generator...
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace test1
{
class bknxml
{
private const string FILE_NAME = "Logimp.log";
StreamWriter sw = null;
public bknxml()
{
if (File.Exists(FILE_NAME))
sw = File.AppendText(FILE_NAME);
else
{
sw = File.CreateText(FILE_NAME);
sw.WriteLine("<?xml version=\"1.0\" standalone=\"yes\"?>");
//sw.WriteLine("Generated log by Aplikasi XML Import for
PL/SQL error reporting on " + DateTime.Now.DayOfWeek + " at " +
DateTime.Now);
}
}
public void writexml(params string[] file)
{
sw.WriteLine("<DATA_SYNC>");
foreach (string f in file)
{
sw.WriteLine(" <KK_WNI>");
sw.WriteLine(f);
sw.WriteLine(" </KK_WNI>");
}
sw.WriteLine("</DATA_SYNC>");
sw.WriteLine("");
}
public void closefile()
{
sw.Close();
}
}
}
End***** this is the code for making the XML file****
start***** this is how i want the XML well formed look like****
<?xml version="1.0" standalone="yes"?>
<DATA_SYNC>
<KK_WNI>
<No_Transaksi>73710110006102006000004</No_Transaksi>
<No_KK>7371010610060003</No_KK>
<Alamat>JL. BANTAENG 10</Alamat>
<RT>001</RT>
<RW>001</RW>
<Kd_Pos>90221</Kd_Pos>
<Telp> </Telp>
<Dusun> </Dusun>
<Kd_Wilayah>7371011001</Kd_Wilayah>
<Nama_RT> </Nama_RT>
<Nama_RW> </Nama_RW>
<Nama_Ptgs_Reg> </Nama_Ptgs_Reg>
<NIP_Ptgs_Reg> </NIP_Ptgs_Reg>
<Nama_Pjbt> </Nama_Pjbt>
<NIP_Pjbt> </NIP_Pjbt>
<Created_Date>2006-10-06T15:21:22.0000000+08:00</Created_Date>
<Created_By>Febby Ekadiarta</Created_By>
<Updated_By> </Updated_By>
<Tgl_Transaksi>2006-10-19T09:07:54.0000000+08:00</Tgl_Transaksi>
</KK_WNI>
<KK_WNI>
<No_Transaksi>73710110006102006000001</No_Transaksi>
<No_KK>7371010610060001</No_KK>
<Alamat>JL. BANTAENG 10</Alamat>
<RT>001</RT>
<RW>001</RW>
<Kd_Pos>90221</Kd_Pos>
<Telp> </Telp>
<Dusun> </Dusun>
<Kd_Wilayah>7371011001</Kd_Wilayah>
<Nama_RT> </Nama_RT>
<Nama_RW> </Nama_RW>
<Nama_Ptgs_Reg> </Nama_Ptgs_Reg>
<NIP_Ptgs_Reg> </NIP_Ptgs_Reg>
<Nama_Pjbt> </Nama_Pjbt>
<NIP_Pjbt> </NIP_Pjbt>
<Created_Date>2006-10-06T15:12:48.0000000+08:00</Created_Date>
<Created_By>Febby Ekadiarta</Created_By>
<Updated_By> </Updated_By>
<Tgl_Transaksi>2006-10-19T09:07:54.0000000+08:00</Tgl_Transaksi>
</KK_WNI>
</DATA_SYNC>
End***** this is how i want the XML well formed look like****
I want the XML to be look like the above...cause i already made a single
application that can inserting the xml data into an oracle table with XML
style....and would kindly share to other...
SO...Mr and Mrs Expert please help me...
1. Which is the best method that i have to use? Would you kindly suggest me
some better method?
2. If it is not to hard for you to kindly help me, please help me coding the
code...the XML Spreadsheet reader and the XML creator...
Please send me mail...if anyone would kindly collaborate coding with this
stupid newbie
send it to: (e-mail address removed), or YM: (e-mail address removed)
To be honest...its been 1 month i'm starting learning VC#...and i was not
really a programmer mindset...just drop from colledge...
Thank you for you guys who will be and helping this stupid newbie...tx
please aplogize for my bad english
OK, lets start.
I have a task to make an XML file from unusual Excel file...i'm giving the
screenshot...please follow the link
So, as u can see that the spreadsheet is not a good looking one...and i've
been trying to convert it into an XML file....with reading many tutors...
The file (.xls) is different in the field name (such as "TMPT LHR" can be
"TMPT_LHR" or "TMPTLHR" in other xls file) between another...and it is make
me crazy doing for one single file...not yet another file
Here are methods that i tried:
1. with XML Schema in the Excel view source...not really good at it (my
kowledge). My test went bad, the XML file output doesn't go as i wish, it
messy..
2. Save As the spreadsheet as CSV, and i found it like this...please
follow the link...it more make me confuse..
3. Save As the spreadsheet as Text, and dont get any idea how to convert
it...
4. Save As the spreadsheet as XML Spreadsheet, and i try to read the
<data> tag/node in it and finally succeded reading the element string (inside
the <data>) Using VC#... and try to make a well formed XML file...this part
not done yet...
This is the code..
start***** this is the code for reading the node****
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
namespace test1
{
public partial class Form1 : Form
{
public String fileName;
public String dbconnect;
public String strNodeValues;
//public String[] strNodeValues3a = new String[3] { "", "", "" }; <-
the 3 top field from excel
//public String[] strNodeValues3b = new String[3] { "", "", "" }; <-
the 1 record under the 3 top filed
//public String[] strNodeValues15a = new String[15] { "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "" }; <- the 15 field under the 1
record
//public String[] strNodeValues15b = new String[15] { "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "" }; <- wish this line to held
the 15 data of 1 record, that can be not just one record...see pict above
please...
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
Stream myStream;
// String fileName;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "xml files (*.xml)|*.xml";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
myStream.Close();
fileName = openFileDialog1.FileName;
textBox1.Text = fileName;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
XmlTextReader reader = new XmlTextReader(fileName);
while (reader.Read())
{
switch (reader.Name)
{
case "Data ":
reader.Read();
strNodeValues = reader.Value;
MessageBox.Show(reader.Value, "Ini " +
strNodeValues); <- i see it with message box.
break;
}
}
}
private void button7_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox2.Text);
}
private void button8_Click(object sender, EventArgs e)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
}
End***** this is the code for reading the node****
start***** this is the code (class file) for making the XML file**** I
edited it from a log generator...
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace test1
{
class bknxml
{
private const string FILE_NAME = "Logimp.log";
StreamWriter sw = null;
public bknxml()
{
if (File.Exists(FILE_NAME))
sw = File.AppendText(FILE_NAME);
else
{
sw = File.CreateText(FILE_NAME);
sw.WriteLine("<?xml version=\"1.0\" standalone=\"yes\"?>");
//sw.WriteLine("Generated log by Aplikasi XML Import for
PL/SQL error reporting on " + DateTime.Now.DayOfWeek + " at " +
DateTime.Now);
}
}
public void writexml(params string[] file)
{
sw.WriteLine("<DATA_SYNC>");
foreach (string f in file)
{
sw.WriteLine(" <KK_WNI>");
sw.WriteLine(f);
sw.WriteLine(" </KK_WNI>");
}
sw.WriteLine("</DATA_SYNC>");
sw.WriteLine("");
}
public void closefile()
{
sw.Close();
}
}
}
End***** this is the code for making the XML file****
start***** this is how i want the XML well formed look like****
<?xml version="1.0" standalone="yes"?>
<DATA_SYNC>
<KK_WNI>
<No_Transaksi>73710110006102006000004</No_Transaksi>
<No_KK>7371010610060003</No_KK>
<Alamat>JL. BANTAENG 10</Alamat>
<RT>001</RT>
<RW>001</RW>
<Kd_Pos>90221</Kd_Pos>
<Telp> </Telp>
<Dusun> </Dusun>
<Kd_Wilayah>7371011001</Kd_Wilayah>
<Nama_RT> </Nama_RT>
<Nama_RW> </Nama_RW>
<Nama_Ptgs_Reg> </Nama_Ptgs_Reg>
<NIP_Ptgs_Reg> </NIP_Ptgs_Reg>
<Nama_Pjbt> </Nama_Pjbt>
<NIP_Pjbt> </NIP_Pjbt>
<Created_Date>2006-10-06T15:21:22.0000000+08:00</Created_Date>
<Created_By>Febby Ekadiarta</Created_By>
<Updated_By> </Updated_By>
<Tgl_Transaksi>2006-10-19T09:07:54.0000000+08:00</Tgl_Transaksi>
</KK_WNI>
<KK_WNI>
<No_Transaksi>73710110006102006000001</No_Transaksi>
<No_KK>7371010610060001</No_KK>
<Alamat>JL. BANTAENG 10</Alamat>
<RT>001</RT>
<RW>001</RW>
<Kd_Pos>90221</Kd_Pos>
<Telp> </Telp>
<Dusun> </Dusun>
<Kd_Wilayah>7371011001</Kd_Wilayah>
<Nama_RT> </Nama_RT>
<Nama_RW> </Nama_RW>
<Nama_Ptgs_Reg> </Nama_Ptgs_Reg>
<NIP_Ptgs_Reg> </NIP_Ptgs_Reg>
<Nama_Pjbt> </Nama_Pjbt>
<NIP_Pjbt> </NIP_Pjbt>
<Created_Date>2006-10-06T15:12:48.0000000+08:00</Created_Date>
<Created_By>Febby Ekadiarta</Created_By>
<Updated_By> </Updated_By>
<Tgl_Transaksi>2006-10-19T09:07:54.0000000+08:00</Tgl_Transaksi>
</KK_WNI>
</DATA_SYNC>
End***** this is how i want the XML well formed look like****
I want the XML to be look like the above...cause i already made a single
application that can inserting the xml data into an oracle table with XML
style....and would kindly share to other...
SO...Mr and Mrs Expert please help me...
1. Which is the best method that i have to use? Would you kindly suggest me
some better method?
2. If it is not to hard for you to kindly help me, please help me coding the
code...the XML Spreadsheet reader and the XML creator...
Please send me mail...if anyone would kindly collaborate coding with this
stupid newbie
send it to: (e-mail address removed), or YM: (e-mail address removed)
To be honest...its been 1 month i'm starting learning VC#...and i was not
really a programmer mindset...just drop from colledge...
Thank you for you guys who will be and helping this stupid newbie...tx