1
00:00:00,210 --> 00:00:01,980
Oh, yeah, hello, my dear friend.

2
00:00:02,000 --> 00:00:09,210
So this is a lesson where we're going to try to export the data as a CSV file here, remember all those

3
00:00:09,210 --> 00:00:10,050
commas, right?

4
00:00:11,100 --> 00:00:12,450
OK, so let's get started.

5
00:00:14,400 --> 00:00:20,190
So we're going to begin implementing the export function for our application when the user clicks the

6
00:00:20,190 --> 00:00:20,820
export, but.

7
00:00:22,230 --> 00:00:29,550
So the tables should be passed and it should be saved into a Casby or comma separated value.

8
00:00:31,290 --> 00:00:33,780
So why don't we create a slot for this button?

9
00:00:38,150 --> 00:00:41,000
Self-taught UI dot export button clicked.

10
00:00:48,170 --> 00:00:51,890
And connected to a function called export button clicked that.

11
00:00:55,420 --> 00:00:56,530
It's created right here.

12
00:00:57,160 --> 00:00:59,320
Define export button, collective self.

13
00:01:00,700 --> 00:01:05,020
And we define to let the user choose where to save this file.

14
00:01:05,920 --> 00:01:10,050
So we're going to save the path in queue.

15
00:01:10,090 --> 00:01:11,640
File dialogued.

16
00:01:11,650 --> 00:01:13,180
Get save file name.

17
00:01:16,660 --> 00:01:20,220
Now, if you look in the documentation in order to know the parameters.

18
00:01:20,610 --> 00:01:22,560
But I'll tell you that the first one is self.

19
00:01:24,850 --> 00:01:33,100
So as a parent and then save file, the third one can be an empty string.

20
00:01:36,410 --> 00:01:42,890
And let's have the last one be the extension for which you got to save the file.

21
00:01:44,060 --> 00:01:48,110
So we know in this case, we everything dots v.

22
00:01:49,600 --> 00:01:54,570
So now that we have the path, we're going to want to check to make sure that the path is not no.

23
00:01:54,850 --> 00:01:56,170
So if path.

24
00:01:57,260 --> 00:02:05,870
And now we want to do is create the file and append all the content from our table with open of Astr

25
00:02:06,260 --> 00:02:07,970
of path of zero.

26
00:02:10,950 --> 00:02:18,960
Because this returns a list and only the first element from the list is the actual path you follow.

27
00:02:20,190 --> 00:02:25,590
Just go ahead and look at the documentation so that you can have more information for the get the save

28
00:02:25,590 --> 00:02:27,630
file name and we can open it.

29
00:02:30,740 --> 00:02:35,570
Writing new line equals empty string as a string.

30
00:02:38,830 --> 00:02:40,630
We import as Viña.

31
00:02:42,140 --> 00:02:43,430
Import C, v.

32
00:02:47,920 --> 00:02:49,180
And let's go back to function.

33
00:02:50,710 --> 00:02:52,420
Writing equals Covid.

34
00:02:52,780 --> 00:02:54,160
Writer of Stream.

35
00:02:56,340 --> 00:03:01,710
So what we did is open the path for which the user has selected for writing and also reading.

36
00:03:03,000 --> 00:03:05,430
But we're going to be interested in writing.

37
00:03:05,460 --> 00:03:09,300
We're going to instantiate the writer object for our stream.

38
00:03:10,780 --> 00:03:15,310
So now what we want to do is first write the header so that.

39
00:03:17,860 --> 00:03:20,320
Road data is empty west.

40
00:03:20,470 --> 00:03:24,040
And for each column in the header list.

41
00:03:26,220 --> 00:03:31,080
Four column and range self-taught UI, not Hable widget column count.

42
00:03:36,540 --> 00:03:45,810
We want to append to our road data so road data, dot append, self-taught UI dot table widget, horizontal

43
00:03:45,810 --> 00:03:48,630
header item of this column text.

44
00:03:57,060 --> 00:04:03,510
Now, after we have loaded the information in our road data, we just want to actually write it in our

45
00:04:03,510 --> 00:04:04,140
file.

46
00:04:05,560 --> 00:04:08,110
So what we need is right.

47
00:04:08,230 --> 00:04:11,080
Not right row of the data.

48
00:04:14,850 --> 00:04:18,660
Now we have the header list, we want to print the actual values, right?

49
00:04:20,910 --> 00:04:26,400
So for each row in range, self-taught yuai table widget count.

50
00:04:32,530 --> 00:04:36,460
We initialize row data with an empty list for each row and.

51
00:04:37,410 --> 00:04:43,290
For each column in the index matrix, because this table is actually a matrix.

52
00:04:45,910 --> 00:04:47,260
For each column in range.

53
00:04:49,610 --> 00:04:52,670
Self-taught yuai table widget column count.

54
00:04:54,810 --> 00:04:55,440
We get the.

55
00:04:57,040 --> 00:05:04,960
Item which is self-taught UI, not Hable widget, not item at the specific row and the specific column.

56
00:05:06,430 --> 00:05:08,950
We check if it is not known.

57
00:05:10,800 --> 00:05:14,340
So with the item is not none.

58
00:05:14,490 --> 00:05:20,100
We append to road data and item, not text.

59
00:05:22,670 --> 00:05:23,510
If it is not.

60
00:05:25,530 --> 00:05:34,110
What do we want to append to the road data is just an empty string, so else row data data penned and

61
00:05:34,110 --> 00:05:34,950
empty string.

62
00:05:37,060 --> 00:05:44,590
So after we've done all of these for this role, we can append the role to our writer writer Don Wright,

63
00:05:44,590 --> 00:05:46,150
row of row data.

64
00:05:52,770 --> 00:05:58,770
So let me just take a minute here to explain once more what's going on.

65
00:05:59,780 --> 00:06:03,420
So the user is prompted with this dialogue.

66
00:06:05,630 --> 00:06:10,520
The user can then choose the path of the file wherever the user wants to see.

67
00:06:12,500 --> 00:06:15,710
So if the past is not empty, which it probably isn't.

68
00:06:16,520 --> 00:06:23,600
We're going to want to open the file and looking at that directory as a string will instantiate the

69
00:06:23,600 --> 00:06:29,210
right or object, append the header list, and then append the values list.

70
00:06:39,110 --> 00:06:45,050
Let's try it out, run the project, manage employee click export button.

71
00:06:46,820 --> 00:06:50,030
And we'll save this file named employee.

72
00:06:50,210 --> 00:06:57,740
Let's go down and check, see if the place is created yet if it is created, we'll see what happens.

73
00:06:58,730 --> 00:07:00,920
And our file is here, and let's look inside.

74
00:07:02,210 --> 00:07:02,690
Yeah.

75
00:07:03,470 --> 00:07:04,670
Yeah, baby, yeah.

76
00:07:05,510 --> 00:07:06,380
So that's pretty cool, huh?

77
00:07:07,130 --> 00:07:08,420
So that's it for this lesson.

78
00:07:09,230 --> 00:07:13,490
But we have successfully exported the employee data as a CSV file.

79
00:07:14,390 --> 00:07:15,860
I do want to see in the next one, though.

80
00:07:15,950 --> 00:07:16,340
OK.

81
00:07:16,700 --> 00:07:18,680
Until then, have a very nice day.
