Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _init_workbook(self, filename, set_default_styles):
if filename and isinstance(filename, str):
_workbook = xlsxwriter.Workbook(filename)
self.output = None
else:
self.output = BytesIO()
_workbook = xlsxwriter.Workbook(self.output)
del self._workbook
del self._style
self._workbook = _workbook
self._style = HFExcelStyle(self.workbook)
if set_default_styles:
self.set_default_styles()
def main():
args = make_args()
config = configparser.ConfigParser()
utils.load_config(config, args.config)
for cmd in args.modify:
utils.modify_config(config, cmd)
with open(os.path.expanduser(os.path.expandvars(args.logging)), 'r') as f:
logging.config.dictConfig(yaml.load(f))
model_dir = utils.get_model_dir(config)
path, step, epoch = utils.train.load_model(model_dir)
state_dict = torch.load(path, map_location=lambda storage, loc: storage)
mapper = [(inflection.underscore(name), member()) for name, member in inspect.getmembers(importlib.machinery.SourceFileLoader('', __file__).load_module()) if inspect.isclass(member)]
path = os.path.join(model_dir, os.path.basename(os.path.splitext(__file__)[0])) + '.xlsx'
with xlsxwriter.Workbook(path, {'strings_to_urls': False, 'nan_inf_to_errors': True}) as workbook:
worksheet = workbook.add_worksheet(args.worksheet)
for j, (key, m) in enumerate(mapper):
worksheet.write(0, j, key)
for i, (name, variable) in enumerate(state_dict.items()):
value = m(name, variable)
worksheet.write(1 + i, j, value)
if hasattr(m, 'format'):
m.format(workbook, worksheet, i, j)
worksheet.autofilter(0, 0, i, len(mapper) - 1)
worksheet.freeze_panes(1, 0)
logging.info(path)
#######################################################################
#
# An example of creating an Excel charts with gradient fills using
# Python and XlsxWriter.
#
# Copyright 2013-2019, John McNamara, jmcnamara@cpan.org
#
import xlsxwriter
workbook = xlsxwriter.Workbook('chart_gradient.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
# Add the worksheet data that the charts will refer to.
headings = ['Number', 'Batch 1', 'Batch 2']
data = [
[2, 3, 4, 5, 6, 7],
[10, 40, 50, 20, 10, 50],
[30, 60, 70, 50, 40, 30],
]
worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
worksheet.write_column('C2', data[2])
def goPartExcel(self):
L = self.dl.export_excel_data()
NL = ['收件人昵称', '收件人姓名', '收件人手机','省', '市', '区', '详细地址', '邮政编码', '运费',
'支付类型', '订单号', '商品名称',
]
sa = time.time()
s1 = 'send_%s' % sa
sio = BytesIO()
workbook = xlsxwriter.Workbook(sio)
worksheet = workbook.add_worksheet(u'%s' % s1)
# format = workbook.add_format({'bold': True, 'font_color': 'red'})
format = workbook.add_format({'bold': True, 'font_color': 'black', 'bg_color': '#e0e0e0'})
format.set_align('center')
format1 = workbook.add_format({'bold': True, 'font_color': 'black', 'bg_color': '#e0e0e0'})
format1.set_align('left')
format2 = workbook.add_format()
format2.set_align('center')
format3 = workbook.add_format()
format3.set_align('left')
for row in range(len(NL)):
def __init__(self, stream: io.BufferedWriter, params: SaveResultsRequestParams) -> None:
SaveAsWriter.__init__(self, stream, params)
self._header_written = False
self._workbook = xlsxwriter.Workbook(self._file_stream.name)
self._worksheet = self._workbook.add_worksheet()
self._current_row = 1
def get_xlsx_export(self, context):
datas = self._get_datas(context)
output = io.BytesIO()
export_header = (
self.request.GET.get('export_xlsx_header', 'off') == 'on')
model_name = self.opts.verbose_name
book = xlsxwriter.Workbook(output)
sheet = book.add_worksheet(
u"%s %s" % (_(u'Sheet'), force_text(model_name)))
styles = {'datetime': book.add_format({'num_format': 'yyyy-mm-dd hh:mm:ss'}),
'date': book.add_format({'num_format': 'yyyy-mm-dd'}),
'time': book.add_format({'num_format': 'hh:mm:ss'}),
'header': book.add_format({'font': 'name Times New Roman', 'color': 'red', 'bold': 'on', 'num_format': '#,##0.00'}),
'default': book.add_format()}
if not export_header:
datas = datas[1:]
for rowx, row in enumerate(datas):
for colx, value in enumerate(row):
if export_header and rowx == 0:
cell_style = styles['header']
else:
if isinstance(value, datetime.datetime):
#######################################################################
#
# An example of creating Excel Area charts with Python and XlsxWriter.
#
# Copyright 2013-2019, John McNamara, jmcnamara@cpan.org
#
import xlsxwriter
workbook = xlsxwriter.Workbook('chart_area.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
# Add the worksheet data that the charts will refer to.
headings = ['Number', 'Batch 1', 'Batch 2']
data = [
[2, 3, 4, 5, 6, 7],
[40, 40, 50, 30, 25, 50],
[30, 25, 30, 10, 5, 10],
]
worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1])
worksheet.write_column('C2', data[2])
def ExportResults(domain,ip,export):
print "\n"
row = 0
col = 0
if export == "js":
#Export the results in json format
print "Exporting the results in an json"
with open ('output.json','w') as f:
json.dump(ip,f)
elif (export == "xl"):
#Export the results in excel format
print "\nExporting the results in an excel"
# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('output.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write(row, col, "Domain")
worksheet.write(row, col+1, "IP")
row +=1
for dom in domain:
col = 0
worksheet.write(row, col, dom)
row += 1
#update row
row = 1
for direction_ip in ip:
col = 1
worksheet.write(row, col, direction_ip)
row += 1
#close the excel
workbook.close()
def get_xlsx_export(self, context):
u'''
导出 xlsx
'''
datas = self._get_datas(context)
output = StringIO.StringIO()
export_header = (
self.request.GET.get('export_xlsx_header', 'off') == 'on')
model_name = self.opts.verbose_name
book = xlsxwriter.Workbook(output)
sheet = book.add_worksheet(
u"%s %s" % (_(u'Sheet'), force_unicode(model_name)))
styles = {'datetime': book.add_format({'num_format': 'yyyy-mm-dd hh:mm:ss'}),
'date': book.add_format({'num_format': 'yyyy-mm-dd'}),
'time': book.add_format({'num_format': 'hh:mm:ss'}),
'header': book.add_format({'font': 'name Times New Roman', 'color': 'red', 'bold': 'on', 'num_format': '#,##0.00'}),
'default': book.add_format()}
if not export_header:
datas = datas[1:]
for rowx, row in enumerate(datas):
for colx, value in enumerate(row):
if export_header and rowx == 0:
cell_style = styles['header']
else:
if isinstance(value, datetime.datetime):