File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Source:https://github.com/Show-Me-the-Code/show-me-the-code
2
+ # Author:renzongxian
3
+ # Date:2014-12-22
4
+ # Python 3.4
5
+
6
+ """
7
+
8
+ 第 0016 题: 纯文本文件 numbers.txt, 里面的内容(包括方括号)如下所示:
9
+ [
10
+ [1, 82, 65535],
11
+ [20, 90, 13],
12
+ [26, 809, 1024]
13
+ ]
14
+ 请将上述内容写到 numbers.xls 文件中.
15
+
16
+ """
17
+
18
+ import xlwt3
19
+ import json
20
+
21
+
22
+ def write_txt_to_xls (txt_file ):
23
+ # Read form the txt file
24
+ txt_object = open (txt_file , 'r' )
25
+ file_content = json .load (txt_object )
26
+
27
+ # Write to the xls file
28
+ xls_object = xlwt3 .Workbook ()
29
+ sheet = xls_object .add_sheet ('numbers' )
30
+ for i in range (len (file_content )):
31
+ data = file_content [i ]
32
+ for j in range (len (data )):
33
+ sheet .write (i , j , data [j ])
34
+ xls_object .save ('numbers.xls' )
35
+
36
+
37
+ if __name__ == '__main__' :
38
+ write_txt_to_xls ('numbers.txt' )
39
+
Original file line number Diff line number Diff line change
1
+ [
2
+ [1, 82, 65535],
3
+ [20, 90, 13],
4
+ [26, 809, 1024]
5
+ ]
You can’t perform that action at this time.
0 commit comments