我想從Excel表格中檢索所有值並以XML格式存儲。如何以.XML格式存儲變量值?這是我的代碼。我嘗試使用writeXMl,但它的格式不正確。我想以.XML格式保存xlContent變量中的任何內容。將LINQ保存到XML
var columnNames = new List<string>();
foreach (DataColumn column in dt.Columns)
{
columnNames.Add(column.ColumnName);
}
var xlContent = new XElement("DocumentElement", from row in dt.AsEnumerable()
select new XElement("Assets", from columnName in columnNames
select new XElement(columnName.Replace(" ",""), row[columnName]))).ToString();
dt.WriteXml("C:\\Development\\MyAppln\\ExcelToXML\\Products.xml");
嘗試.. HTTP:// stackoverflow.com/questions/1527790/how-can-i-write-to-an-excel-spreadsheet-using-linq –
@ Jidheesh Rajan鏈接不回答我的問題 – NoviceToProgramming