44# SPDX-License-Identifier: GPL-3.0-or-later
55#
66
7+ from os import remove
8+ from os .path import splitext
9+
10+ from odf .opendocument import load
11+ from odf .table import TableCell , TableRow
712from openpyxl import load_workbook
813from xlrd import open_workbook
9- from os .path import splitext
10- from odf .opendocument import OpenDocumentSpreadsheet , load
11- from odf .table import Table , TableCell , TableRow
14+
1215from shexstatements .shexfromcsv import CSV
13- from os import remove
1416
1517
1618class Spreadsheet :
@@ -39,11 +41,10 @@ def generate_shex_from_spreadsheet(filepath, skip_header=False, stream=None):
3941 """
4042 shexstatement = ""
4143 try :
42- pattern = '^\s*$'
4344 data = ""
44- filename , file_extension = splitext (filepath )
45+ _ , file_extension = splitext (filepath )
4546
46- if ( file_extension in {".xlsx" , ".xlsm" , ".xltx" , ".xltm" }) :
47+ if file_extension in {".xlsx" , ".xlsm" , ".xltx" , ".xltm" }:
4748 wb = None
4849 if stream is not None :
4950 with open ("tmp" + filepath , "wb" ) as sf :
@@ -54,7 +55,7 @@ def generate_shex_from_spreadsheet(filepath, skip_header=False, stream=None):
5455 wb = load_workbook (filepath )
5556 for ws in wb .worksheets :
5657 for i in range (1 , ws .max_row + 1 ):
57- line = list ()
58+ line = []
5859 for j in range (1 , ws .max_column + 1 ):
5960 cell = ws .cell (row = i , column = j ).value
6061 if cell is not None :
@@ -65,23 +66,23 @@ def generate_shex_from_spreadsheet(filepath, skip_header=False, stream=None):
6566 if stream is not None :
6667 remove (filepath )
6768
68- elif ( file_extension in {".xls" }) :
69+ elif file_extension in {".xls" }:
6970 wb = None
7071 if stream is not None :
71- #wb = open_workbook(file_contents=stream, encoding_override="cp1252")
72+ # wb = open_workbook(file_contents=stream, encoding_override="cp1252")
7273 wb = open_workbook (file_contents = stream )
7374 else :
7475 wb = open_workbook (filepath )
7576 for sheet in wb .sheets ():
7677 for i in range (0 , wb .sheets ()[0 ].nrows ):
77- line = list ()
78+ line = []
7879 for j in range (0 , wb .sheets ()[0 ].ncols ):
7980 cell = sheet .cell (i , j ).value
8081 if len (str (cell )) > 0 :
8182 line .append (cell )
8283 data = data + "|" .join (line ) + "\n "
8384
84- elif ( file_extension in {".ods" }) :
85+ elif file_extension in {".ods" }:
8586 wb = None
8687 if stream is not None :
8788 with open ("tmp" + filepath , "wb" ) as sf :
@@ -94,7 +95,7 @@ def generate_shex_from_spreadsheet(filepath, skip_header=False, stream=None):
9495 rows = wb .getElementsByType (TableRow )
9596 for row in rows :
9697 cells = row .getElementsByType (TableCell )
97- line = list ()
98+ line = []
9899 for cell in cells :
99100 if len (str (cell )) > 0 :
100101 line .append (str (cell ))
0 commit comments