Skip to main content
Solved

Using Template file when writing to multiple sheets in the same output excel


j.bramley
Participant
Forum|alt.badge.img+1

I am trying to use a template file in an excel writer for my data. The data is collected from a number of sites, so I was aiming to use the site id attribute as the sheet name to export a new sheet per site. Unfortunately the template is only being used for the first site which passes through my writer, and the other sheets are unformatted. Has anyone encountered this and found a solution to apply the template to all sheets if multiple are being written in the same feature writer?

 

Best answer by crutledge

Hi ​@j.bramley 
Well it took some testing but I think I got something to work in the way we would like it to. I am using 2024.0.1 fyi.

So the results are good. Here are the steps to set it up and try on you end:

  1. Create multiple copies of the template sheet in the template excel file.
  2. Rename to numbers sequential. 1,2,3…
  3. Using an Excel Writer (not FeatureWriter) Set up the writer pointing to the template like you did before.
  4. SETTINGS: Note the Sorter before the writer. I sorted the Attribute Variable used to name the sheet (ImpactYear). This will ensure that the she sheets are written out in some kind of order.
    Key thing is the template sheet name is a number. I entered 2 of the 4 template sheet copies. Just because.
  5. Results:
    The 4 template sheets came along for the ride (1-4) and there was a new sheet created for each year in the variable

    Okay. I hope that works for you. Good Luck!!

View original
Did this help you find an answer to your question?

8 replies

crutledge
Influencer
Forum|alt.badge.img+33
  • Influencer
  • July 1, 2025

Hi ​@j.bramley I don't know the best way of doing it but one thing you could try is: Go to your Excel template file and create a bunch of copies of the template sheet. The writer may be working like "sheet1=sheet1fromtemplate, sheet2=sheet2fromtemplate, ..."

You could also try putting 1 in the order field. Change to insert not update.

Also, something doesn't quite look right. Are you using the featrewriter? If so click the parameters button and choose yes to overwrite file. And put your path to the Excel template file here.

https://support.safe.com/hc/en-us/articles/25407596375309-Using-a-Template-File-when-Writing-Excel-Data

Hope that helps.


crutledge
Influencer
Forum|alt.badge.img+33
  • Influencer
  • July 1, 2025

And delete the sheet name you have. In the original. 


j.bramley
Participant
Forum|alt.badge.img+1
  • Author
  • Participant
  • July 2, 2025

Thanks ​@crutledge, yes so I am using a feature writer and have changed this to insert with the template file all set up in the parameters. I have also added in duplicate template sheets, but have to name these differently to the template used (I could maybe try do this dynamically, however the number of sheets required each time will be different) but unfortunately it currently still only formats the first feature

 

My other option would be to output each feature as its own excel file to ensure the formatting comes through, however can’t then think of a best way to automate merging these files/sheets all in to one spreadsheet after


crutledge
Influencer
Forum|alt.badge.img+33
  • Influencer
  • July 2, 2025

Hi ​@j.bramley I can't test until tomorrow but my next suggestion is exactly what you ended with. Combine all files into one....with formating...there is a setting Read Formatting that come into play I think.

Sorry that's not much help. I can test tomorrow.


j.bramley
Participant
Forum|alt.badge.img+1
  • Author
  • Participant
  • July 2, 2025

@crutledge thank you!! I feel that combining after too will be the way as it looks like its something that others have found with trying to write to multiple sheets using a template file where the sheet names/number need to be dynamic. Any advice on the read formatting and achieving this is greatly appreciated!!


crutledge
Influencer
Forum|alt.badge.img+33
  • Influencer
  • Best Answer
  • July 5, 2025

Hi ​@j.bramley 
Well it took some testing but I think I got something to work in the way we would like it to. I am using 2024.0.1 fyi.

So the results are good. Here are the steps to set it up and try on you end:

  1. Create multiple copies of the template sheet in the template excel file.
  2. Rename to numbers sequential. 1,2,3…
  3. Using an Excel Writer (not FeatureWriter) Set up the writer pointing to the template like you did before.
  4. SETTINGS: Note the Sorter before the writer. I sorted the Attribute Variable used to name the sheet (ImpactYear). This will ensure that the she sheets are written out in some kind of order.
    Key thing is the template sheet name is a number. I entered 2 of the 4 template sheet copies. Just because.
  5. Results:
    The 4 template sheets came along for the ride (1-4) and there was a new sheet created for each year in the variable

    Okay. I hope that works for you. Good Luck!!


j.bramley
Participant
Forum|alt.badge.img+1
  • Author
  • Participant
  • July 7, 2025

@crutledge perfect, that all works!! Thank you!

Renaming the sheets 1-4 worked perfectly, and I still managed to write out more than 4 sheets so it is not a case of one template sheet per output either, thank you!! Saves me requiring openpyxl on my FME server machine so this will deliver the output directly from FME


crutledge
Influencer
Forum|alt.badge.img+33
  • Influencer
  • July 7, 2025

Good to hear! I will have to test and see if we can get away with only one template sheet in the template xlxs or if 1,2 or more sheets are needed to make this work. I think, but don’t know why, changing the name of the sheet to a number worked (2) rather than a name (Sheet1). It is definitely not intuitive and deserves further understanding/explanation.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings