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:
Create multiple copies of the template sheet in the template excel file.
Rename to numbers sequential. 1,2,3…
Using an Excel Writer (not FeatureWriter) Set up the writer pointing to the template like you did before.
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.
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
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.
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
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.
@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!!
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:
Create multiple copies of the template sheet in the template excel file.
Rename to numbers sequential. 1,2,3…
Using an Excel Writer (not FeatureWriter) Set up the writer pointing to the template like you did before.
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.
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
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
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.
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.