views:

34

answers:

1

Hi all,

lately I've been into combining multiple OpenXML speadsheets via PHPExcel which showed me that this framework has certain issues which makes it pretty much unusable for what I want to do (my related SO question).

To make it short: it's hard to guarantee that all formatting features of Excel 2007 will persist a file merge performed with that particular framework.

Anways, now I'm thinking of a more general approach. I want to open a template XLSX which contains various formatting and add some plain alphanumeric data worksheets 'at the end' of the workbook.

Is sensefully possible to do the following:

  • unzip template XLSX
  • parse XML files
  • add worksheets
  • save xml files
  • rezip files to get valuid XLSX

Any hints or experiences would be highly appreciated.

thanks in advance

K

+1  A: 

I haven't worked with .xlsx too much, but I've altered .docx files by manually adding and editing the XML.

The biggest concern with adding new parts to a document is to make sure you update the .rels files. The best way to figure out what needs to be updated is to create a new .xlsx document in Excel, add a worksheet, save the file and then unzip it to see what has changed. You can also use the DocumentReflector tool that comes with the OpenXML SDK if you want to see the internals of the file without having to unzip it.

I found the OpenXML reference manual very helpful when hand editing files because it tells you what elements you have to keep and what elements are optional to make a valid document. It makes it easier to work with when you can remove some of the extraneous elements that Excel adds automatically.

Adam Sheehan