Hey, welcome back.
Yesterday, we coded this script which produced these three PDF files.
So each of them looks something like this.
So we extracted that invoice number from each of these file names.
Now, today, our purpose, our goal is to keep developing this PDF files and add more information which
will consist of adding the date.
And that is also information which we get from the file names.
You see, each Excel file has the date here when it has been created, so the invoice date and then
we're going to extract these data from inside the Excel files and then write some labels here at the
end of the PDF file.
So let's go ahead and do this.
This is the code we have currently, so it simply creates a PDF document for each file path for each
Excel file path, and it adds a page to that document.
And then we get the invoice number from the file name and we write that invoice number inside the PDF
documents.
So we do that for each Excel file and then we output the PDF in a PDF file on disk.
So now before we write the final PDF file on disk, we want to add more contents.
So let's pleat the code like that to make it more readable.
So we read the dataframe, we create the PDF file, get the file name and the invoice number, create
the cell.
And now in between here we want to basically duplicate this code.
So to duplicate some codes on pie chart, you can just select the code by clicking on the numbers here
and dragging your cursor as I'm doing.
So select these two and then press on control D or command D on your keyboard.
That will duplicate those lines of code.
I duplicated these lines of code because here I'm going to write the date.
So it's basically the same code but with different values.
The date, something like that.
And here goes.
This second part of that Now together date, we should refer to the file name.
So the file name of each Excel file contains a date.
So file name is a string.
And then we split that string at the dash and that gives us a list.
So this expression here gives us a list of two items, two strings.
The first string.
The first string is the invoice number.
Let's say 100001, and the second string is the date 22 and the 3.1. 18.
So that is a list of two strings.
And we got the first item of that string using this indexing operation here.
So we extract the first item, which has an index of zero.
No.
Now to extract the second item, you have two choices.
Either you select this code duplicated with control D or command D, and you say date is like that.
So you extract the second item of the list, which is the date.
Or another way is to say here, invoice number date is equal to that.
And then you remove that and what happens is this.
So let's suppose that.
File name is one one, something like that.
I'm just guessing.
And when you say file name, that's plate at that.
You get that right.
Now, if you see.
File name, invoice number and date is equal to that, then invoice number will get the first item of
that list, and date will get the second item of that list.
So automatically Python distributes the values of the list to each of these variables.
And I do prefer this second method here, so I'm going to leave it like that with just one line of code.
You store two values in each variable.
So we go here and now invoice number is changed to date.
So we have this two lines and we have these two lines as well.
And let me remove those lines.
Run to see what we've got so far.
And let's check one of the PDF files.
So here is the date, here is the invoice number, but we need an l pn of one in the invoice line.
So that's indicates that a break line should be created so that the next cell is added to a new line.
So that fixes the issue here.
Next, we need to add this table.
So the data for that table are stored inside each of the Excel files.
And that's it for this video.
Let's commit the changes.
So we change the PDF files and the main output file.
So that is the 26.
And we added a date and invoice date to be more specific, commit.
And that's it.
Let's continue in the next video with more code.
So.