Rename Excel file with current date

I’ve created a report in Knime, it saves so much time and I wished I knew about Knime before.

Anyway, I have a report that writes to an Excel File, with the Excel Writer Node. I would like the name of the report to look something like this:

Daily Report 021218 am
Daily Report 021218 pm

I can already write the report name to “Daily Report”, it’s just adding the date, and the am/pm at the end that I would like to do.

Please can somebody offer me some advice.

Hi,

You can generate current date and time using “Create Date&Time Range” node. There is an option in its configuration window below start and end points for this (“use execution date&time”). After creating the date, use a “String Manipulation” node to generate the path including file name, for example: join("C:\\Daily Report ", string($Date&Time$)). Then use a “Table Row To Variable” node to generate a flow variable which contains the path and the file name created in the previous step. Now feed the flow variable to the “Excel Writer (XLS)” node and in the configuration window of the node, for the output location, beside the “browse…” button, you can see another button which is to use flow variables for that setting. Click on it and use the variable you’ve created as the path. Done!

current%20date

current-date.knwf (17.9 KB)

Best,
Armin

2 Likes

Thank you for the quick reply.

I’ve tried your knwf file and it looks like it’s going to work, however I get an error about writing to the C drive “C:” is not writable.

I’ll let you know if I can sort it out, thanks again for your help so far :biking_man:

You’re welcome!

The path I used is an example. You can change the path and the file name as you wish (Be aware of using double backslashes “\\” instead of one “\”)

Best,
Armin

1 Like

I’ve tried my main drive and an external drive, but no luck yet.

join("E:\TestFolder\ ", string($Date&Time$))

This is the error that I get:

WARN Excel Writer (XLS) 3:3 Relative paths are not allowed (‘E:TestFolder 2018-12-02.xlsx’), please enter an absolute path or a URL

Sussess, I got it to write to the main directory with this:

join("E:\Daily Report ", string($Date&Time$))

Sorry about all the messages, I got it to work!!! Thank you so much.

I went with this as my final output command:

join(“E:\Output\Daily Report “, string($Date&Time$),”.xlsx”)

The above has 2 backslashes, one after E: and one after Output, for some reason it only shows one backslash after each in the browser.

join(“E:\\Output\\Daily Report “, string($Date&Time$),”.xlsx”)

Yes, I told you about this:

I’m glad that your problem is solved now.

Good luck,
Armin

3 Likes

A post was split to a new topic: Integrate timestamp into filename

Hi Armin, I don’t see the “file name” in the list of flow variables.


Hi @mvaseghi and welcome to the forum.

This is likely because you haven’t created a path variable upstream that is connected to the writer node (I’m making an assumption here since you are only showing screenshots of the configuration window, and not the workflow itself). You also need to connect a table to the input port of the node.

If a path variable already exists, it should be available for you to choose:

2023-06-13 10_10_06

2 Likes

@mvaseghi you can see how to create paths variables here.

Or you could use Java Snippets and convert the strings to paths.

“The mighty “return” in Java”

entry “Know your paths and folders”

2 Likes

thank you. Forgot about converting to path