不是将此代码写入控制台,而是将其显示为Gridview,以便导出到Excel电子表格。我在VStudio和代码中进行了哪些设置和设置。我对c#编程很新,请帮忙。
class Program
{
public class XAxisCalib
{
public int Max1 { get; set; }
public int Min2 { get; set; }
public int Max3 { get; set; }
public int Min4 { get; set; }
public int Max5 { get; set; }
public int Min6 { get; set; }
}
static void Main(string[] args)
{
string[] fileEntries = Directory.GetFiles(@"c:\Sciclone UAC", "*.cfg*");
foreach (string fileName in fileEntries)
{
{
XDocument doc = XDocument.Load(fileName);
var query = from x in doc.Descendants("XAxisCalib")
select new
{
MaxChild = x.Descendants("Max"),
MinChild = x.Descendants("Min")
};
foreach (var x in query)
{
foreach (var nextLevel in x.MaxChild)
{
Console.WriteLine("" + nextLevel.Value);
}
foreach (var nextLevel in x.MinChild)
{
Console.WriteLine("" + nextLevel.Value + "\n");
}
}
var query2 = from y in doc.Descendants("YAxisCalib")
select new
{
MaxChild = y.Descendants("Max"),
MinChild = y.Descendants("Min")
};
foreach (var y in query2)
{
foreach (var nextLevel in y.MaxChild)
{
Console.WriteLine("" + nextLevel.Value);
}
foreach (var nextLevel in y.MinChild)
{
Console.WriteLine("" + nextLevel.Value + "\n");
}
var query3 = from z in doc.Descendants("ZAxisCalib")
select new
{
MaxChild = z.Descendants("Max"),
MinChild = z.Descendants("Min")
};
foreach (var z in query3)
{
foreach (var nextLevel in z.MaxChild)
{
Console.WriteLine("" + nextLevel.Value);
}
foreach (var nextLevel in z.MinChild)
{
Console.WriteLine("" + nextLevel.Value + "\n");
}
}
}
}
}
}
}
}
答案 0 :(得分:0)
我认为最快的方法是将XML加载到DataSet中,并将其用作GridView的DataSource。
有关详细信息,请查看: