add export xls
parent
884eefaf37
commit
4513fc7036
|
@ -476,7 +476,7 @@ class VSETB_OT_export_spreadsheet(Operator):
|
||||||
settings = get_scene_settings()
|
settings = get_scene_settings()
|
||||||
project = settings.active_project
|
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):
|
def draw(self, context):
|
||||||
scn = context.scene
|
scn = context.scene
|
||||||
|
@ -642,13 +642,14 @@ class VSETB_OT_export_spreadsheet(Operator):
|
||||||
try:
|
try:
|
||||||
import openpyxl
|
import openpyxl
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
self.report({'INFO'}, 'Installing openpyxl')
|
self.report({'INFO'}, 'Installing openpyxl...')
|
||||||
openpyxl = install_module('openpyxl')
|
openpyxl = install_module('openpyxl')
|
||||||
|
|
||||||
from openpyxl import Workbook
|
from openpyxl import Workbook
|
||||||
|
|
||||||
workbook = Workbook()
|
workbook = Workbook()
|
||||||
worksheet = workbook.active
|
worksheet = workbook.active
|
||||||
|
workbook.active.title = 'BKL'
|
||||||
for row in rows:
|
for row in rows:
|
||||||
worksheet.append(row)
|
worksheet.append(row)
|
||||||
|
|
||||||
|
@ -656,16 +657,24 @@ class VSETB_OT_export_spreadsheet(Operator):
|
||||||
letter = col[0].column_letter
|
letter = col[0].column_letter
|
||||||
worksheet.column_dimensions[letter].auto_size = True
|
worksheet.column_dimensions[letter].auto_size = True
|
||||||
|
|
||||||
|
|
||||||
# Save the file
|
# Save the file
|
||||||
workbook.save(str(export_path))
|
workbook.save(str(export_path))
|
||||||
|
|
||||||
# elif spreadsheet.format == 'xls':
|
elif spreadsheet.format == 'xls':
|
||||||
# try:
|
try:
|
||||||
# import xlwt
|
import xlwt
|
||||||
# except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
# self.report({'INFO'}, 'Installing openpyxl')
|
self.report({'INFO'}, 'Installing xlwt...')
|
||||||
# openpyxl = install_module('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':
|
elif spreadsheet.format == 'Clipboard':
|
||||||
csv_buffer = StringIO()
|
csv_buffer = StringIO()
|
||||||
|
|
|
@ -189,7 +189,7 @@ def get_custom_name_items(self, context):
|
||||||
|
|
||||||
class SpreadsheetExport(PropertyGroup):
|
class SpreadsheetExport(PropertyGroup):
|
||||||
use_custom_cells: BoolProperty(default=False)
|
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')
|
separator : StringProperty(default='\\n')
|
||||||
delimiter : StringProperty(default=';')
|
delimiter : StringProperty(default=';')
|
||||||
export_path : StringProperty(default='//export')
|
export_path : StringProperty(default='//export')
|
||||||
|
|
Loading…
Reference in New Issue