且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用c#将包含父节点和子节点的xml转换为单个excel文件

更新时间:2023-11-14 09:08:28

请使用以下代码生成基于xml的excel文件。





public void XMLToExcel(string strXMLPath,string outputFileName,string sheetName)

{

string strPath = Path .GetDirectoryName(strXMLPath);

DataSet dsXML = new DataSet();

dsXML.ReadXml(strXMLPath);

strPath = strPath + \\+ outputFileName +。xlsx;

DataTable tblXML = dsXML.Tables [0];

tblXML.TableName = sheetName;

DataTableToFilePath(tblXML,strPath);

}
Please use the following code generating excel file based on the xml.


public void XMLToExcel(string strXMLPath, string outputFileName, string sheetName)
{
string strPath = Path.GetDirectoryName(strXMLPath);
DataSet dsXML = new DataSet();
dsXML.ReadXml(strXMLPath);
strPath = strPath + "\\" + outputFileName + ".xlsx";
DataTable tblXML = dsXML.Tables[0];
tblXML.TableName = sheetName;
DataTableToFilePath(tblXML, strPath);
}