|
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
http://img227.imageshack.us/img227/1637/capthd0.jpg
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 :P
Here are methods that i tried:
1. with XML Schema in the Excel view source...not really good at it (my kowledge), cause 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..
http://img84.imageshack.us/img84/8210/csvfj3.jpg
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("");
//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****
<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: me.iyepb0@gmail.com, or YM: me.iyepb0@yahoo.com
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</data></data>
<div class="ForumMod">modified on Monday, December 24, 2007 4:18:44 PM</div>
|
|
|
|
|
Method 3 is probably the best, i.e. saving the spreadsheet as an XML Spreadsheet and then transforming it into the required form. Note that there is a special language design to do exactly this: XSLT.
Some tips for Xml with .NET, take a look into them:
1) There is a whole namespace dedicated to reading, writing and manipulating Xml, the System.Xml namespace.
2) There is (in .NET 3.0 / 3.5) a "query" language (other than XPath) for selecting Xml: LINQ (System.Xml.Linq)
|
|
|
|
|
There's a simpler way than those you listed and you won't have to save the Excel file in another format. You can use ADO.NET to read from the Excel file (use OleDb), next you fill the data in a dataset then save the data in the dataset as an .xml file using WriteXml() (you have the option to save the schema too or you could save the schema in a separate file using WriteXmlSchema())
Tell me if you want the details.
|
|
|
|
|
Just to put in my two cents – there is a free editor out there that can edit those ado.net xml file. Just drag the file in and it leats you view and edit all the data in a really effective way: (then save it as Excel file.. optionally selecting which rows you'd like to be in that fie)
http://www.nobhillsoft.com/MarieAlix.aspx
(its currently on beta so its given out freely)
|
|
|
|
|
Hi all, I'm looking for a way to hide a property from the property grid while still allowing it to be serialized into XML. The problem is that if I set the [Browseable(false)] attribute on the property, this hides it from the property grid but also makes the property not serialize out to XML. Is there a decent way around this issue?
|
|
|
|
|
Did you put a XmlElement on the property?
|
|
|
|
|
Yes, but if Browseable is set to false, it doesn't serialize out to XML. So what I need is a way to hide a property from the property grid without using the browseable attribute, or a way to change the browseable attribute dynamically before the item is saved..
|
|
|
|
|
Not sure why Browseable affect serialization... but well..
Some idea, overwrite attribute before you serialize or deserialize. May not work as the property wasn't set to Ignore.
XmlAttributeOverrides[^]
Another way is to use an interface for the property grid, where unwanted property are left out in the interface.
modified on Tuesday, December 25, 2007 1:11:55 AM
|
|
|
|
|
Hi,
i'vw copied some of MS code form msdn about how to print
but it always prints 2 pages only and BLANK
WHAT is going on
this is the code
<br />
<br />
private void printToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
ofdScenario.Filter = "Text Files|*.txt";<br />
if (ofdScenario.ShowDialog() == DialogResult.OK)<br />
{<br />
if (ofdScenario.FileName != "")<br />
{<br />
try<br />
{<br />
prntDoc.DocumentName = ofdScenario.FileName;<br />
srAppUtility = new StreamReader(prntDoc.DocumentName);<br />
prntPreview.Document = prntDoc;<br />
prntPreview.ShowDialog();<br />
prntDoc.Print();<br />
}<br />
catch (Exception E)<br />
{<br />
MessageBox.Show("printToolStripMenuItem_Click");<br />
MessageBox.Show("Error Occured while Printing \nError Message :" +<br />
E.Message, "Print Error", MessageBoxButtons.OK, MessageBoxIcon.Error);<br />
}<br />
finally<br />
{<br />
<br />
srAppUtility.Close();<br />
}<br />
<br />
}<br />
}<br />
}<br />
private void prntDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)<br />
{<br />
#region Inner Defenitions<br />
<br />
float linesPerPage = 0;<br />
float yPos = 0;<br />
int count = 0;<br />
float leftMargin = e.MarginBounds.Left;<br />
float topMargin = e.MarginBounds.Top;<br />
string line = null;<br />
<br />
#endregion<br />
<br />
linesPerPage = e.MarginBounds.Height/printerFont.GetHeight(e.Graphics);<br />
<br />
while (count < linesPerPage &&<br />
((line = srAppUtility.ReadLine()) != null))<br />
{<br />
yPos = topMargin + (count * printerFont.GetHeight(e.Graphics));<br />
e.Graphics.DrawString(line, printerFont, Brushes.Black, leftMargin, yPos, new StringFormat());<br />
count++;<br />
}<br />
<br />
if (line != null)<br />
e.HasMorePages = true;<br />
else<br />
e.HasMorePages = false;<br />
<br />
}<br />
Have Fun
Never forget it
|
|
|
|
|
half-life wrote: yPos = topMargin + (count * printerFont.GetHeight(e.Graphics));
e.Graphics.DrawString(line, printerFont, Brushes.Black, leftMargin, yPos, new StringFormat());
i think problem is in "StringFormat()", you didnt defined some String formats properties
StringFormat PageStringFormat = new StringFormat();
PageStringFormat.Trimming = StringTrimming.Word;
PageStringFormat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
try this StringFormat, i hope it should work
Becoming Programmer...
|
|
|
|
|
THANKS
it works
Have Fun
Never forget it
|
|
|
|
|
glad to know
Becoming Programmer...
|
|
|
|
|
hi
i create a userControl and inheritance it from TextBox control, i was override OnTextChanged event as follow(to change codpage of numbers to arabic):
protected override void OnTextChanged(EventArgs e)<br />
{ <br />
this.Text = this.ToArabicNumber(this.Text); <br />
}
and my method (ToArabicNumber) is here:
private string ToArabicNumber(string text)<br />
{<br />
char[] chars = new char[text.Length];<br />
chars = text.ToCharArray();<br />
StringBuilder sb = new StringBuilder();<br />
foreach (char c in chars)<br />
{<br />
if (char.IsDigit(c))<br />
{<br />
sb.Append(Strings.ChrW(Strings.AscW(c) + 1728).ToString());<br />
}<br />
}<br />
return sb.ToString();<br />
}
my problem is that in runTime, when i enter any value to my custom textBox, it's Text changed and fire OntextChanged event and change codpage to arabic and then fire OntextChanged and so on (Unlimited loop),
how to solve my problem ?
thanks
|
|
|
|
|
hdv212 wrote: how to solve my problem ?
If the text is already an arabic number, then don't set the text.
protected override void OnTextChanged(EventArgs e)
{
string arabicNumber = ToArabicNumber(Text);
if (Text != arabicNumber)
Text = arabicNumber;
}
|
|
|
|
|
thanks for reply
but my problem is that when i change TextBox.Text in onChangedText, the onChangedText event fire again and so on (Unlimited loop), like this :
TextBox.Text(onChangedText fired) -> ChangeToArabic(onChangedText fired)
-> ChangeToArabic(onChangedText fired) -> ChangeToArabic(onChangedText fired) -> ChangeToArabic(onChangedText fired)-> ...
how to solve this problem ?
|
|
|
|
|
hdv212 wrote: thanks for reply
but my problem is that when i change TextBox.Text in onChangedText, the onChangedText event fire again and so on (Unlimited loop)
Are you suggesting that I gave you a solution that loops infinitely? If you can show where my solution loops infinitely then I'll accept that you still have a problem. If not, then what is your problem?
Please look at my solution. It is very simple. It does loop but once. The reason it only loops once is that I have a condition that stops it looping more than that.
So, my question to you: Did you try my solution before complaining that I don't solve it? Looking at the way you phrased your follow up post, you are basically saying I did not understand your original problem, which implies that you didn't attempt to implement my solution. This suggest that IN FACT you did not understand my solution, rather than me not understand your problem.
|
|
|
|
|
thanks Colin Angus Mackay
i tested your suggestion way, but it is not help me, because when i add new character in my textBox(and fire OnTextChanged event) my new text different with old text that i converted to arabic numbers.
|
|
|
|
|
hdv212 wrote: i tested your suggestion way, but it is not help me
Bit it no longer loops infinitely. Right?
hdv212 wrote: because when i add new character in my textBox(and fire OnTextChanged event) my new text different with old text that i converted to arabic numbers.
Then you need to capture the selection before changing the text, then put the selection back afterwards. In a text box a selection can have zero length which representst the position the cursor is at.
|
|
|
|
|
Hi,
Here iam using windows applicatio,and i have one timer control,here i need to give timercontrol interval value in Config File.
How can i do this?
Vasvai
|
|
|
|
|
Well, you get yourself a StreamReader, pass the path to your config file and start reading.
Say you had your config file setup like this:
name="bob"
interval=20
age=86
You could use something like:
StreamReader SR = new StreamReader("myConfigFile");
do {
string[] line = SR.ReadLine().Split('=');
string variable = line[0];
string value = line[1];
switch(variable) {
case "interval":
myTimer.Interval = Convert.ToInt32(value);
break;
}
if(SR.Position == SR.Length)
break;
}while (true);
Just to give you an idea.
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
hi there,
i want that my application should run once at a time, like some softwares/programs (for example : windows default picture viewer)
so to i do that i did it like this :(in Main())
string name = Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf(@"\") + 1).ToLower().Replace(".exe","");
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName(name);
if (p.Length != 0)
{
Application.Exit();
return;
}
but i dont like this way, anyone know any other good way?
thanks
Becoming Programmer...
|
|
|
|
|
i dunno what happened but "edit and delete" buttons arent showing in the post,
so here is the original post that not appearing correct (above) :
hi there,
i want that my application should run once at a time, like some softwares/programs (for example : windows default picture viewer)
so to do that i did it like this in Main())
string name = Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf(@"\") + 1).ToLower().Replace(".exe","");
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName(name);
if (p.Length != 0)
{
Application.Exit();
return;
}
but i dont like this way, anyone know any other good way?
thanks
Becoming Programmer...
|
|
|
|
|
|
my way is short than it, xD
Becoming Programmer...
|
|
|
|
|
So what? Shorter doesn't mean better. What if your executable is renamed? Your code won't work.
|
|
|
|
|