How to work with XLS Formatter

Dear all,

I have created a workflow reading two excel files with the excel reader node, filtering a sheet and writing it back using excel writer:

So far - so good :slight_smile:

The end result written back using excel writer should have the following properties:

  1. header in row1 should be frozen

  2. header in row1 should have grey background

  3. all cells should have auto-size and auto-high

  4. auto filter should be set

  5. Write result into excel sheet

I tried to realize this using xls formatter from Continental, but run into problems.
I can’t connect excelwriter to xlsformatter node.
Watching the youtube video does not helped me.

I assume I have to unpivot my source into xls control table but there i am stuck.

Does anybody has an idea?

Thx for help!

BR,

Heinz

Hi @Heinz , would you be able to upload your workflow with some sample spreadsheets (after replacing any sensitive data with dummy data). I have a couple of components that may be able to speed you up with using the continental nodes, and happy to try to give some pointers.

See also this forum article I wrote last year…

along with this demo worflow

And

and (a bit more involved, and a few additional components :wink: )

1 Like

Hi @Heinz , I decided to have a go just using some dummy data. The following will do all of the above list except it doesn’t do auto-height of rows because that doesn’t seem to be available. (If somebody knows different, please advise). It may be possible to do this with a java snippet or python though if that is critical and we can’t find a way of achieving it with continental nodes.

Please read the annotations I’ve placed in this demo workflow. The formatting is done within the component “XLS Control Format Template 3” which I’ve just created based on your list of requirements. It doesn’t have much configuration as this would be far too complex. It needs to be told the name of the sheet (which should match the sheet name specified in the Auto Tag Generator, and of course the sheet name in the Excel Writer. You also specify here if it is to freeze panes. If selected, currently, it will freeze the header row (1 row) and also the number of columns defined in the Auto Tag Generator config.

For all other formatting, the idea is that if you wish to modify it, you disconnect the component, open it, modify by changing, adding or removing the various continental nodes that are present inside it, then rename the component and share it to somewhere you can access it in future.

Demo data:

Becomes:

1 Like

Hi takbb,

please find attached a simple example of reading data and exporting them to excel.

In this excel sheet I would like to do

  1. header in row1 should be frozen
  2. header in row1 should have grey background
  3. all cells should have auto-size and auto-high
  4. auto filter should be set

in an for me easy way.
temp.knwf (18.5 KB)

I am expecting that this nodes from Continental should be executed before the excel writer node and I do not see the reason for this xls control table auto tag conenctor node. Please be so kind to explain.

Another issue is: I can’t get an output port from the excelwriter node.

Later I have to do these formattings to 20 sheets with in this exceltable; do I have to do it every time or is there a clue to this for all these sheets at once?

Thanks for help!

BR,

Heinz

Hi @Heinz, you are correct that the Auto tag generator can be executed before or after the Excel Writer. It simply needs to be using the same data that will be sent to the Excel Writer, so the upper port is a “pass through” port, and it could equally be written has this:

It is personal preference, and I find it cleaner to have the data passed through the tag generator so that I know that any future changes in the workflow won’t have a change to the data being passed to the Excel Writer after the tag generator has seen it.

Re the flow variable on the Excel Writer node, are you using the Classic UI, and which version of KNIME?

In “classic”, the output port on the Excel Writer node will be visible if you right click on the node and say Show Flow Variable Ports, or if you try to drag from the (invisible) point just on the top right of the Excel Writer, where you “know” the flow port would be! In the Modern UI, they should be visible whenever you hover over the mouse over the node

The formatting can be performed in a loop, if it is the same formatting for all sheets. That is a little more involved but I can demonstrate it once you have got this working.

TO give some idea, here is a screen image of doing exactly that on a work project yesterday. This also uses additional components to collect the formatting models together on each iteration:

Incidentally, the workflow that you uploaded was simply my initial Table Creator node and Excel Writer from my demo. Were you intending to upload something else? Any demo I give will be using the components in the demo I uploaded, which in turn use the Continental nodes as I described in the previous message.

1 Like

Hi takbb,

thank you very much for your effort.
I am using latest knime version 5.1.0.

Do I need this xls control table node?

In my mind I would like to use before excel write 4 xls formatters nodes each one for one of my topics

  1. header in row1 should be frozen
  2. header in row1 should have grey background
  3. all cells should have auto-size and auto-high
  4. auto filter should be set

Just to be clear in communication please find below screenshot of what I have in mind:

Remark: Please forget about the node headers

BR,

Heinz

Hi @Heinz, this isn’t the way the Continental nodes work, I’m afraid. Yes you do need to somehow create an xls control table, because that is fundamental to the way those nodes work. You can do it manually or you can use a component that creates a bunch of common ones for you.

The detail of using the Continental nodes is here:

What you have to do is create a set of “tags” that the continental nodes then each use. This is the control table. Every data cell that you need to format in the table being written to the Excel Writer needs to have one or more “tags” defined for it.Each of the Continental XLS formatter nodes then acts on a specified tag (which you supply the name of in the config).

The Excel Writer only writes the xlsx file using the data but it does not apply any formatting. To apply formatting, once you have written the xlsx file, you need to have an “XLS Formatter (apply)” read the XLSX and write a new xlsx file (not the same file) and it applies the formatting information that has been generated by each of the XLS nodes. (This is made available from those green data ports).

The flow I have uploaded is the simplest flow I can think of which does everything you have specified except it doesn’t do the auto-row height because I haven’t found a way of setting height to “auto” in the continental nodes.

Now, it is the creating of the tags which is the most challenging when starting out, which is why I create the Auto Tag Generator component. You don’t have to use that, but if you don’t want to, then you will need to read all the tutorials on using the continental nodes which describe how to create tags. Personally I use the auto generator component precisely because I don’t want to have to remember how to do it! In your case, the auto tag generator will provide all the tags that you need to perform the job, and in the demo workflow I already gave a link to, it does it.

You appeared from your first post to be having difficulty in creating the tags, so if you want to, you can use my Auto Tag Generator and in place of the “XLS Control Format Template 3” component, you can place theXLS nodes that wish to use for formatting. You will then simply need to give each of these the “tag names” provided by the Auto Tag generator. The tag name it generates for the header cells is “header” and for all data cells is “data”. I’m not forcing you to use the components I built, but I was under the impression you wanted a simple way to achieve your objective, and this is the simplest way I know.

You can see all of the tags it generates by looking at the second data port on the Auto Tag Generator

1 Like

@Heinz

I work heavily between KNIME and Excel and I find this node to be infinitely easier if you are proficient on the Excel side.

The Continental nodes are fine if you just want a few simple formatting rules applied to clean up a table, but if you really want to dial in a nice presentation it will cost you hours. I can do the same thing with the write to a template approach in a few minutes as well as include conditional formatting, user interaction settings, graphs, etc. You can also write around existing formulas (using blank cells on the KNIME side) to update data only where necessary keeping interactivity in tact.

4 Likes

Thank you very much!
This seems to me the most smartest way.

BR,

Heinz

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.