我在c#中使用xmlwriter来创建一个保存俱乐部成员记录的xml文件。 我想存储每个成员的记录,链接到将存储在文件夹中的个人id照片的位置。
private void button1_Click(object sender, EventArgs e)
{
string documentPath = @"D:\Book6.xml";
XmlDocument myxDoc = new XmlDocument();
myxDoc.Load(documentPath);
//Member Node creation
XmlNode member = myxDoc.CreateElement("Member");
//XmlNode information = myxDoc.CreateElement("Information");
XmlNode name = myxDoc.CreateElement("Name");
name.InnerText = txtName.Text;
member.AppendChild(name);
//
XmlNode dateofbirth = myxDoc.CreateElement("DateofBirth");
dateofbirth.InnerText = txtDOB.Text;
member.AppendChild(dateofbirth);
//
XmlNode idnumber = myxDoc.CreateElement("IdNumber");
idnumber.InnerText = txtID.Text;
member.AppendChild(idnumber);
//
XmlNode address = myxDoc.CreateElement("Address");
address.InnerText = txtAddress1.Text;
member.AppendChild(address);
//
XmlNode contactnumber = myxDoc.CreateElement("ContactNumber");
contactnumber.InnerText = txtCellnumber.Text;
member.AppendChild(contactnumber);
//
XmlNode email = myxDoc.CreateElement("Email");
email.InnerText = txtEmail.Text;
member.AppendChild(email);
//
XmlNode designation = myxDoc.CreateElement("Designation");
designation.InnerText = txtDesignation.Text;
member.AppendChild(designation);
//
XmlNode branch = myxDoc.CreateElement("Branch");
branch.InnerText = txtBranch.Text;
member.AppendChild(branch);
//
XmlNode province = myxDoc.CreateElement("Province");
province.InnerText = txtProvince.Text;
member.AppendChild(province);
//
XmlNode district = myxDoc.CreateElement("District");
district.InnerText = txtDistrict.Text;
member.AppendChild(district);
//
XmlNode constituency = myxDoc.CreateElement("Constituency");
constituency.InnerText = txtConstituency.Text;
member.AppendChild(constituency);
//
XmlNode formnumber = myxDoc.CreateElement("FormNumber");
formnumber.InnerText = txtFormNum.Text;
member.AppendChild(formnumber);
//
XmlNode subscription = myxDoc.CreateElement("Subscription");
subscription.InnerText = txtSubscripton.Text;
member.AppendChild(subscription);
//
XmlNode period = myxDoc.CreateElement("Period");
period.InnerText = txtPeriod.Text;
member.AppendChild(period);
//
XmlNode image = myxDoc.CreateElement("Image");
image.InnerText = txtName.Text;//imageLocation; //imagePhoto.ToString();
member.AppendChild(image);
//member.AppendChild(information);
myxDoc.DocumentElement.AppendChild(member);
myxDoc.Save(documentPath);
txtName.Text = String.Empty;
txtDOB.Text = String.Empty;
txtID.Text = String.Empty;
txtAddress1.Text = String.Empty;
txtAddress2.Text = String.Empty;
txtAddress3.Text = String.Empty;
txtCellnumber.Text = String.Empty;
txtEmail.Text = String.Empty;
txtDesignation.Text = String.Empty;
txtBranch.Text = String.Empty;
txtProvince.Text = String.Empty;
txtDistrict.Text = String.Empty;
txtConstituency.Text = String.Empty;
txtFormNum.Text = String.Empty;
txtSubscripton.Text = String.Empty;
txtPeriod.Text = String.Empty;
txtWard.Text = String.Empty;
}
private void btnPhoto_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
//filters
open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (open.ShowDialog() == DialogResult.OK)
{
imagePhoto.Image = new Bitmap(open.FileName);
imagePhoto.SizeMode = PictureBoxSizeMode.StretchImage;
imageLocation = open.FileName;
}
}
}
}
答案 0 :(得分:0)
在查看导入数据之后,我发现它似乎只将数据导入为纯字符串。我甚至探索过使用" = HYPERLINK()"函数然而它作为文本导入并且不会被计算。
根据您的需要,有一些可能的解决方案。
选项1: 您可以创建excel文件而不是xml文件。然而,这很复杂,可能有点繁琐。
选项1.1:您可以创建并优化xml文件。您可以通过将工作表另存为xml然后查看xml并编写一些代码来重新创建它来查看这些是如何布局的。
选项2: 如果您是要将数据导入excel文件的人,则可以通过选择的数据运行宏或vb脚本以将其转换为链接。