add export xls

pull/5/head
ChristopheSeux 2023-07-18 17:09:27 +02:00
parent 884eefaf37
commit 4513fc7036
2 changed files with 19 additions and 10 deletions

View File

@ -476,7 +476,7 @@ class VSETB_OT_export_spreadsheet(Operator):
settings = get_scene_settings()
project = settings.active_project
return context.window_manager.invoke_props_dialog(self)
return context.window_manager.invoke_props_dialog(self, width=375)
def draw(self, context):
scn = context.scene
@ -642,13 +642,14 @@ class VSETB_OT_export_spreadsheet(Operator):
try:
import openpyxl
except ModuleNotFoundError:
self.report({'INFO'}, 'Installing openpyxl')
self.report({'INFO'}, 'Installing openpyxl...')
openpyxl = install_module('openpyxl')
from openpyxl import Workbook
workbook = Workbook()
worksheet = workbook.active
workbook.active.title = 'BKL'
for row in rows:
worksheet.append(row)
@ -656,16 +657,24 @@ class VSETB_OT_export_spreadsheet(Operator):
letter = col[0].column_letter
worksheet.column_dimensions[letter].auto_size = True
# Save the file
workbook.save(str(export_path))
# elif spreadsheet.format == 'xls':
# try:
# import xlwt
# except ModuleNotFoundError:
# self.report({'INFO'}, 'Installing openpyxl')
# openpyxl = install_module('xlwt')
elif spreadsheet.format == 'xls':
try:
import xlwt
except ModuleNotFoundError:
self.report({'INFO'}, 'Installing xlwt...')
xlwt = install_module('xlwt')
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('BKL')
for row_index, row in enumerate(rows):
for col_index, cell_value in enumerate(row):
worksheet.write(row_index, col_index, cell_value)
workbook.save(str(export_path))
elif spreadsheet.format == 'Clipboard':
csv_buffer = StringIO()

View File

@ -189,7 +189,7 @@ def get_custom_name_items(self, context):
class SpreadsheetExport(PropertyGroup):
use_custom_cells: BoolProperty(default=False)
format : EnumProperty(items=[(i, i, '') for i in ('csv', 'xlsx', 'Clipboard')])
format : EnumProperty(items=[(i, i, '') for i in ('csv', 'xlsx', 'xls', 'Clipboard')])
separator : StringProperty(default='\\n')
delimiter : StringProperty(default=';')
export_path : StringProperty(default='//export')