Working with excel and pdf

Hi everyone, i’m facing this problem.
I have an excel file like this


With each row of the column C, from C3, i want to get the text from the cell and use it to rename my pdf files

I managed to read and display the text from excel to message box but i can’t rename to my pdf files. Hope anyone would help with this

Hi,

Is the above image input files? Can you also share output file name and rule of renaming in details?
It seems there are multiple same project number in the sheet.

Regards,

yeah, the output file name is the name read from column C. For example, C3 gives F1299163-03-X01 so the pdf file named EFAKK_231206-1447-01 will become F1299163-03-X01

did you have a solution

Hi @KSK_R_D

You have the 5 files you want to rename the file names with the first five rows right.

1 Like

i took 5 files and 5 rows for example, the amount is unpredictable, they can be more or less

Hi,

Can you try the following sample? This renames files under “files” folder in project folder.

dict = dt.AsEnumerable.ToDictionary(Function(r) r(1).ToString+"-"+System.Text.RegularExpressions.Regex.Match(r(2).ToString,"\d+$").Value,Function(r) r(2).ToString)

Sample
Sample20240125-2.zip (305.6 KB)

Regards,

1 Like

thanks, i’ll try and tell you the result later

image
i received an error here

Hi,

For now, can you try to save the workflow, then close Studio and re-open this project? Automatic recovery may run.

Regards,

1 Like

oh, i mean, your code ran perfectly, but when i write it to my program, it becomes an error

Yep, Sometimes this error occurs when lacking refernce. Doesn’t the above solution solve the matter?

1 Like

yeah it solved my problem, but can you explain a little about it, i’m quite confusing right now

Which details do you need, file operation or reference problem?

If file operation, the following may help you.

First, we create Dictionary which key is input filename without extension such as EFAKK_231206-1447-01 and value is renamed filename such as F1299163-03-X01 (品番) from excel data in advance.

The key is created from PROJECT No. and last 2 digits of 品番 using the following exprssion

r(1).ToString+"-"+System.Text.RegularExpressions.Regex.Match(r(2).ToString,"\d+$").Value

The value is created from 品番

Next iterate the target folder and process each pdf file
the following expression returns renamed string from CurrentFile using the above dictionary.

dict(System.IO.Path.GetFileNameWithoutExtension(CurrentFile.Name))+CurrentFile.Extension

Hope this helps you.

Regards,

1 Like

thanks so much for your help :heart: :heart: :heart:

1 Like

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