2

I'm trying to build an XML file from an Excel spreadsheet (no header row). This will be part of a service on a server, so I really don't want to use the MS Office PIO files. I found LinqToExcel on google and tried this code:

var clientExcel = new ExcelQueryFactory(excelFileName);
var sourceXml = new XElement("rows",
  clientExcel.WorksheetNoHeader().Select(line => new XElement("row",
      line.Select((column, index) => new XElement("Column_" + index, column)))));

The code compiles, but at runtime I get a TargetInvocationException. I've worried at this for the better part of a day, but can't figure out where I've gone wrong.

I'd appreciate it if someone would set me straight.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
EoRaptor013
  • 1,735
  • 4
  • 18
  • 31

2 Answers2

1

...if u enable Developer Menu in excel, there's an 'export to xml' option in 2003 its done very easy by Save As > .XML in 2007 u might need to prepare mapping schema. but it still better than write codes where u dont know where is your data header

Bonshington
  • 3,970
  • 2
  • 25
  • 20
  • Sorry, I didn't make clear that these files are data-feeds from several clients, and often are produced by scripts. In any event, we don't have much say over what they send us. – EoRaptor013 Dec 03 '10 at 13:48
-1

Unfortunately LinqToExcel can only read data from spreadsheets. It can not add or update spreadsheet data.

Checkout the ExcelLibary project for writing to excel

Paul
  • 18,349
  • 7
  • 49
  • 56