Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Append to existing sheet if file exists and create file if it doesn't exist

jaimonsk
8 - Asteroid

Hello Experts,

 

I am looking for a way to create a new excel sheet if the file does not exist and append to existing file(also sheet) if the file is already present and write data to them .

 

For example,
image.png

 

 

 

 

 

We need to dynamically create a file called "test_exec. xlsx" if the flag is set as "0" and append to existing sheet if flag is set as "1"

 

Can somebody help me on this?

 

Thanks in advance :)

6 REPLIES 6
RishiK
Alteryx
Alteryx

Hi there

 

Have a play around with this simple workflow I've attached.

 

If you have rows where the Flag = 0 and Flag = 1, you won't be able to output to the same Excel sheet at once.

afv2688
16 - Nebula
16 - Nebula

Hello @jaimonsk ,

 

I recommend you to use 2 batch macros for that.

 

The first one would only accept the files flagged as 0. You pass as a parameter all the file names and data which would be written as new files

 

Do the same then for the second file but for the one flagged as 1, using this time an output but with the append property.

 

If you need an example for it let me know.

 

Kind regards

jaimonsk
8 - Asteroid

Hello 

danilang
19 - Altair
19 - Altair

Hi @jaimonsk 

 

@afv2688 has a good solution, but you can accomplish the same result in a simple workflow...no macros required. 

 

workflow.png

 

The Output tool on the top branch is configured to create the file if it doesn't exist.  The bottom one appends if the file does exist.  The directory browser read the files from the target directory and joins this with the list of filenames from the data.   Matches, which correspond to existing files, are routed to bottom output.  Non-matches go out the L output where the file is created.

 

Dan

 

jaimonsk
8 - Asteroid

This works great.Thank you so much 

Nesterov
5 - Atom

This is fabulous concept! Thank you!

 

Labels