English 中文(简体)
导出 XmlDocument 以超
原标题:exporting XmlDocument to excel

I have a XmlDocument in which i have hierarchical data and i want to export this data to excel. Please help me to get out of this. I have tried to read this data into a dataset but it is not working for me.

问题回答

请发送 xml 样本以获取更多信息 。

Your code loads xml into dataset, so, if your xml doesn t exported from DataSet, you could use LinqToXml. for example:

xml :

<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
    <title>Business Logic Toolkit for .NET</title>
    <link>http://www.bltoolkit.net</link>
    <description />
    <lastBuildDate>2009-01-11</lastBuildDate>
    <item>
        <title>Version 3.1 released</title>
        <link>http://www.bltoolkit.net/Download.htm</link>
        <description>See &lt;a href="http://www.bltoolkit.net/Download.htm"&gt;change log&lt;/a&gt;</description>
        <pubDate>2009-01-11</pubDate>
    </item>
    <item>
        <title>Version 3.0 released</title>
        <link>http://www.bltoolkit.net/Download.htm</link>
        <description>See &lt;a href="http://www.bltoolkit.net/Download.htm"&gt;change log&lt;/a&gt;</description>
        <pubDate>2008-05-21</pubDate>
    </item>
    <item>
        <title>New examples</title>
        <link>http://www.bltoolkit.net/Doc/</link>
        <description>See the following &lt;a href="http://www.bltoolkit.net/Doc/"&gt;link&lt;/a&gt;</description>
        <pubDate>2008-05-10</pubDate>
    </item>
</channel>
</rss>

此代码将获得所有 rss 项的标题

var path = @"D:
ss.xml";
var doc = XDocument.Load(path);
rssTitles = doc.Root.Descendants("item").Elements("title").Select(el => el.Value);

结果:

Version 3.1 released
Version 3.0 released
New examples
<Roles>
  <BalanceSheets RoleURL="http://fluor.com/role/BalanceSheets" RoleDefination="0020 - CONDENSED CONSOLIDATED BALANCE SHEET">
    <Taxonomys>
      <StatementOfFinancialPositionAbstract TaxonomyPresentationId="StatementOfFinancialPositionAbstract">
        <StatementLineItems TaxonomyPresentationId="StatementOfFinancialPositionAbstract">
          <LiabilitiesAndStockholdersEquityAbstract TaxonomyPresentationId="StatementLineItems">
            <CommitmentsAndContingencies TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract" />
            <OtherLiabilitiesNoncurrent TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract" />
            <NonRecourseProjectFinanceDebtNoncurrent TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract" />
            <LongTermDebtNoncurrent TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract" />
            <LiabilitiesCurrentAbstract TaxonomyPresentationId="LiabilitiesAndStockholdersEquityAbstract">
              <BillingsInExcessOfCost TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <LiabilitiesCurrent TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <AccountsPayable TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <BridgeLoan TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <NonRecourseProjectFinanceDebtCurrent TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <EmployeeRelatedLiabilities TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <OtherAccruedLiabilities TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
              <ConvertibleDebtCurrent TaxonomyPresentationId="LiabilitiesCurrentAbstract" />
            </LiabilitiesCurrentAbstract>
          </LiabilitiesAndStockholdersEquityAbstract>
        </StatementLineItems>
      </StatementOfFinancialPositionAbstract>
    </Taxonomys>
  </BalanceSheets>
</Roles>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签