using OfficeOpenXml.Table;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
public static void Main()
Console.WriteLine("Hello World");
public static void leer(string archivo)
StringBuilder result = new StringBuilder();
XDocument xdoc = XDocument.Load(archivo);
XNamespace cfdi = "http://www.sat.gob.mx/cfd/3";
string folio = xdoc.Element(cfdi + "Comprobante").Attribute("Folio").Value;
var lv1s = from lvl in xdoc.Descendants(cfdi + "Comprobante")
Sello = lvl.Attribute("Sello").Value,
ChildEmisor = from e in lvl.Descendants(cfdi + "Emisor")
RFC = e.Attribute("Rfc").Value,
Nombre = e.Attribute("Nombre").Value,
RegimenFiscal = e.Attribute("RegimenFiscal").Value
ChildReceptor = from r in lvl.Descendants(cfdi + "Receptor")
RFC = r.Attribute("Rfc").Value,
Nombre = r.Attribute("Nombre").Value,
UsoCFDI = r.Attribute("UsoCFDI").Value,
ChildConcepts = from r in lvl.Descendants(cfdi + "Conceptos")
ChildConcept = from c in r.Descendants(cfdi + "Concepto")
ClaveProdServ = c.Attribute("ClaveProdServ").Value,
Cantidad = c.Attribute("Cantidad").Value,
ClaveUnidad = c.Attribute("ClaveUnidad").Value,
Unidad = c.Attribute("Unidad").Value
var d = from x in lv1s.ToList().Select(c => c.ChildEmisor).ToList()
Sello = lv1s.Select(f => f.Sello).FirstOrDefault(),
rfcE = x.Select(g => g.RFC).FirstOrDefault(),
rfcR = lv1s.Select(c => c.ChildReceptor.ToList().Select(o => o.RFC).FirstOrDefault()).FirstOrDefault()
Export(archivo, d.ToList());
private static void Export(string FileName, IEnumerable<object> list)
var lista = list.Cast<Object>().ToList();
string filePath = "C:\\XML\\Articho.xlsx";
FileInfo file = new FileInfo(filePath);
ExcelPackage pck = new ExcelPackage(file);
ExcelWorksheet worksheet = pck.Workbook.Worksheets.Add("Hoja1");
worksheet.Cells.LoadFromCollection(lista,true);
FileInfo fi = new FileInfo(filePath);