0

I have a requirement to create generic method/ class in C# to generate excel document using Office Writer. In documentation and all samples, it's mentioned to use pre-populated template and fill that template with data. Since I need to create header dynamically, I cannot have template file with fixed header columns. Can we create template dynamically in runtime?

Can someone help me here?

RohitKtr
  • 37
  • 1
  • 2
  • This was a legitimate question for someone using OfficeWriter. OfficeWriter's ExcelTemplate object uses a preformatted Excel template with placeholders that indicate where the data should go. The OfficeWriter API is used to bind data to the template file. The post author has a need to modify his template file programmatically before populating it with data, in which case he can use the ExcelApplication object which provides full runtime control. – Aviva M. May 01 '13 at 15:51
  • Can you add more information to your question to make it clearer what you are trying to do? Do the headers need to be dynamic because at runtime users select which columns they want to see? Are your column headers the same as the field names returned by your SQL query? If so, there is another way to make the headers dynamic, using ordinal data markers with the "fieldname" modifier: Please give more information so we can give you the best advice. Thanks. – Aviva M. May 02 '13 at 13:27

1 Answers1

1

Yes, since a template for OfficeWriter is just a normal Excel document with special symbols in it to mark where data should go, you can create or modify them like any Excel document with the ExcelApplication library.

The documentation has a good write up on creating templates with the ExcelApplication library (it was hidden deep within the Advanced Tutorials section).

Seth Moore
  • 3,575
  • 2
  • 23
  • 33