本文整理汇总了Python中pyexcel.save_as方法的典型用法代码示例。如果您正苦于以下问题:Python pyexcel.save_as方法的具体用法?Python pyexcel.save_as怎么用?Python pyexcel.save_as使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyexcel
的用法示例。
在下文中一共展示了pyexcel.save_as方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_xls_output_stringio
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def test_xls_output_stringio(self):
data = [
[1, 2, 3],
[4, 5, 6]
]
io = pyexcel.save_as(dest_file_type='xlsx', array=data)
r = pyexcel.get_sheet(file_type="xlsx", file_content=io.getvalue())
result = [1, 2, 3, 4, 5, 6]
actual = list(r.enumerate())
eq_(result, actual)
示例2: test_writing_date_format
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def test_writing_date_format(self):
excel_filename = "testdateformat.xlsx"
data = [[datetime.date(2014, 12, 25),
datetime.time(11, 11, 11),
datetime.datetime(2014, 12, 25, 11, 11, 11)]]
pe.save_as(dest_file_name=excel_filename, array=data)
r = pe.get_sheet(file_name=excel_filename, library="pyexcel-xls")
assert isinstance(r[0, 0], datetime.date) is True
assert r[0, 0].strftime("%d/%m/%y") == "25/12/14"
assert isinstance(r[0, 1], datetime.time) is True
assert r[0, 1].strftime("%H:%M:%S") == "11:11:11"
assert isinstance(r[0, 2], datetime.date) is True
assert r[0, 2].strftime("%d/%m/%y %H:%M:%S") == "25/12/14 11:11:11"
os.unlink(excel_filename)
示例3: create_sample_file1
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def create_sample_file1(file):
data = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 1.1, 1]
table = []
table.append(data[:4])
table.append(data[4:8])
table.append(data[8:12])
pyexcel.save_as(array=table, dest_file_name=file)
示例4: test_series_table
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def test_series_table(self):
pyexcel.save_as(adict=self.content, dest_file_name=self.testfile)
r = pyexcel.get_sheet(file_name=self.testfile, name_columns_by_row=0)
eq_(r.dict, self.content)
示例5: _create_a_file
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def _create_a_file(self, file):
pyexcel.save_as(dest_file_name=file, array=self.content)
示例6: test_ods_output_stringio
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def test_ods_output_stringio(self):
data = [
[1, 2, 3],
[4, 5, 6]
]
io = pyexcel.save_as(dest_file_type="ods",
array=data)
r = pyexcel.get_sheet(file_type="ods", file_content=io.getvalue())
result = [1, 2, 3, 4, 5, 6]
actual = list(r.enumerate())
eq_(result, actual)
示例7: setUp
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def setUp(self):
self.content = [[1, 2, 3.1]]
self.test_file = "test_auto_detect_init.ods"
pe.save_as(array=self.content, dest_file_name=self.test_file)
示例8: handle
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def handle(self, *args, **options):
self.stdout.write('Successfully created .. ')
data = []
ss_index = {}
stages_rows = []
head_row = ["Site ID", "Name", "Address", "Latitude", "longitude", "Status"]
project = Project.objects.get(pk=1)
stages = project.stages.filter(stage__isnull=True)
for stage in stages:
sub_stages = stage.parent.all()
if len(sub_stages):
head_row.append("Stage :" + stage.name)
stages_rows.append("Stage :" + stage.name)
for ss in sub_stages:
head_row.append("Sub Stage :" + ss.name)
ss_index.update({head_row.index("Sub Stage :" + ss.name): ss.id})
data.append(head_row)
total_cols = len(head_row) - 6 # for non stages
for site in project.sites.filter(is_active=True, is_survey=False):
site_row = [site.identifier, site.name, site.address, site.latitude, site.longitude, site.status]
site_row.extend([None] * total_cols)
for k, v in ss_index.items():
if Stage.objects.filter(project_stage_id=v, site=site).count() == 1:
site_sub_stage = Stage.objects.get(project_stage_id=v, site=site)
site_row[k] = site_sub_stage.form_status
data.append(site_row)
p.save_as(array=data, dest_file_name="media/stage-report/{}_stage_data.xls".format(project.id))
示例9: stages_status_download
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def stages_status_download(request, pk):
try:
data = []
ss_index = {}
stages_rows = []
head_row = ["Site ID", "Name", "Address", "Latitude", "longitude", "Status"]
project = Project.objects.get(pk=pk)
stages = project.stages.filter(stage__isnull=True)
for stage in stages:
sub_stages = stage.parent.all()
if len(sub_stages):
head_row.append("Stage :"+stage.name)
stages_rows.append("Stage :"+stage.name)
for ss in sub_stages:
head_row.append("Sub Stage :"+ss.name)
ss_index.update({head_row.index("Sub Stage :"+ss.name): ss.id})
data.append(head_row)
total_cols = len(head_row) - 6 # for non stages
for site in project.sites.filter(is_active=True, is_survey=False):
site_row = [site.identifier, site.name, site.address, site.latitude, site.longitude, site.status]
site_row.extend([None]*total_cols)
for k, v in ss_index.items():
if Stage.objects.filter(project_stage_id=v, site=site).count() == 1:
site_sub_stage = Stage.objects.get(project_stage_id=v, site=site)
site_row[k] = site_sub_stage.form_status
data.append(site_row)
p.save_as(array=data, dest_file_name="media/stage-report/{}_stage_data.xls".format(project.id))
xl_data = open("media/stage-report/{}_stage_data.xls".format(project.id), "rb")
response = HttpResponse(xl_data, content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename="report.xls"'
return response
except Exception as e:
messages.info(request, 'Data Creattion Failed {}'.format(str(e)))
return HttpResponse("failed Data Creattion Failed {}".format(str(e)))
示例10: get_xlsx
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def get_xlsx(curent_dir):
wdata = []
wdata.append(['IP', '??', '??', '??', '??', '??'])
wdata.extend(traverse_dir(curent_dir))
wfile = '[email protected]{}.xlsx'.format(time.strftime(ISOTIMEFORMAT, time.localtime(time.time())))
try:
pyexcel.save_as(array=wdata, dest_file_name=wfile)
except:
print('Build xlsx error!')
return False
print('Successful output file: {}'.format(wfile))
示例11: get_xlsx
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def get_xlsx(self):
try:
pyexcel.save_as(array=self.array,
dest_file_name=self.xlsx_name,
dest_sheet_name=self.sheet)
except KeyboardInterrupt as e:
print(str(e))
return False
print('Successful output file: {}'.format(self.xlsx_name))
示例12: transcode
# 需要导入模块: import pyexcel [as 别名]
# 或者: from pyexcel import save_as [as 别名]
def transcode(source_file_type, output_file_type,
sheet_name, sheet_index,
name_columns_by_row, name_rows_by_column,
csv_source_delimiter, csv_source_encoding,
csv_source_lineterminator, csv_source_quotechar,
csv_source_escapechar, csv_source_quoting,
csv_source_no_doublequote,
csv_output_delimiter, csv_output_encoding,
csv_output_lineterminator, csv_output_quotechar,
csv_output_escapechar, csv_output_quoting,
csv_output_no_doublequote,
source, output):
"""
Trancode an excel file from one format to another.
\b
SOURCE: a file name or '-'. '-' tells the command to use stdin
OUTPUT: a file name or '-'. '-' tells the command to use stdout
"""
params = {}
if source == '-':
params['file_content'] = get_input_content(source_file_type)
params['file_type'] = source_file_type
elif source.startswith("http"):
params['url'] = source
else:
params['file_name'] = source
if output == '-':
params['dest_file_stream'] = get_output_stream(output_file_type)
params['dest_file_type'] = output_file_type
else:
params['dest_file_name'] = output
if source_file_type == 'csv' or source.endswith('csv'):
csv_params = _make_csv_params(
csv_source_lineterminator, csv_source_encoding,
csv_source_delimiter, csv_source_quoting,
csv_source_quotechar, csv_source_escapechar,
csv_source_no_doublequote)
params.update(csv_params)
if output_file_type == 'csv' or output.endswith('csv'):
csv_params = _make_csv_params(
csv_output_lineterminator, csv_output_encoding,
csv_output_delimiter, csv_output_quoting,
csv_output_quotechar, csv_output_escapechar,
csv_output_no_doublequote, prefix="dest_")
params.update(csv_params)
sheet_parameters = [sheet_name, sheet_index,
name_columns_by_row, name_rows_by_column]
if _is_sheet_operation(sheet_parameters):
if name_columns_by_row is not None:
params['name_columns_by_row'] = name_columns_by_row
elif name_rows_by_column is not None:
params['name_rows_by_column'] = name_rows_by_column
params['sheet_name'] = sheet_name
params['sheet_index'] = sheet_index
pe.save_as(**params)
else:
pe.save_book_as(**params)