Using Python using xlsxwriter read data written to a different sheet Excel spreadsheet software

[Introduction] Environmental

  System environment: win10 + python 3.5.4 + PyCharm

BACKGROUND Description

Requirements: The information in the database, and host query data is written to an Excel spreadsheet

[Information] data collection scripts

Liezi database level: the disk group information:

select to_char(sysdate, 'yyyy-mm-dd,hh24:mi:ss') check_time,name,total_mb/1024,free_mb/1024,usable_file_mb/1024,
round(100 * (total_mb - usable_file_mb) / total_mb, 2) used_pct from v$asm_diskgroup;

Host-level example: Local spatial information:

df -h

Generating the original data format:

cat >xxxdb.log
<data>
<diskgroup>
CHECK_TIME          NAME                             TOTAL_MB    FREE_MB USABLE_FILE_MB   USED_PCT
------------------- ------------------------------ ---------- ---------- -------------- ----------
2019-06-26,14:53:14 ARCH                               817016     449942         449942      44.93
2019-06-26,14:53:14 OCR                                 91344      90476          30014      67.14
2019-06-26,14:53:14 XXXXBDATA_N                      3068346      88085          88085      97.13
2019-06-26,14:53:14 XXXXDBDATA                        3579716     425776         425776      88.11
</diskgroup>
</data>
<data>
<filesystem>
2019-03-26_14:53:23
Filesystem             Size   Used  Available Capacity  Mounted on
rpool/ROOT/solaris     196G   8.2G        40G    18%    /
rpool/ROOT/solaris/var
                       196G   1.7G        40G     5%    /var
fd                       0K     0K         0K     0%    /dev/fd
swap                   555G    60M       555G     1%    /tmp
rpool/ROOT/solaris/oracle
                       196G    72G        40G    65%    /oracle
rpool/VARSHARE         196G    60M        40G     1%    /var/share
rpool/VARSHARE/zones   196G   288K        40G     1%    /system/zones
rpool/data              10G   288K        10G     1%    /data
rpool/export           196G   304K        40G     1%    /export
rpool/export/home      196G    29G        40G    43%    /export/home
rpool/export/home/admin
                       196G   352K        40G     1%    /export/home/admin
rpool/guests           196G   320K        40G     1%    /guests
zg-audit01              29G   1.5G        28G     6%    /oracle/audit
</filesystem>
</data>
 

[Python script]

# Load plugins 
Import xlsxwriter, SYS, Re

# local read log information acquired path
patch_file_name1 = str ( 'D: \\ \\ Python Software Object \\ Datafiles \\ \\ xxxdb.log')
# read data of one line
= Open inFile1 (patch_file_name1, 'R & lt'). Read ()
# to <data> </ data> intermediate as an array of end-content
data = re.findall (r '<data > \ n ([\ s \ S ?] +) </ Data> \ n-', inFile1)

# custom Excel spreadsheet name
Workbook = xlsxwriter.Workbook (' chuzhang.xlsx ')

# define the table format
cell_format = workbook.add_format ({
' Bold ': True,
' border ':. 1,
' fg_color ':' # B8B8B8 ',
})
# text is defined in a table format wrap
cell_format.set_text_wrap ()

to create a first name sheet1 #
worksheet1 = workbook.add_worksheet (' disk usage group ')
# Table writing position of the array and write data, then use the table format defined
worksheet1.set_column ( "A: A", 100)
worksheet1.write ( 'A2', Data [0], cell_format)

# Create a second name sheet2
worksheet2 = workbook.add_worksheet ( 'local disk usage')
# write form and position of the array write data, then use the table format defined
worksheet2.set_column ( "a: a", 100)
worksheet2.write ( 'A2', data [. 1], cell_format)

# Close table information
workbook.close ()

【Final Results】

[Refer to the official documentation]

xlsxwriter official website, http://xlsxwriter.readthedocs.org/

 

Guess you like

Origin www.cnblogs.com/zetanchen/p/11088376.html