本文整理汇总了Python中xlwt.Workbook方法的典型用法代码示例。如果您正苦于以下问题:Python xlwt.Workbook方法的具体用法?Python xlwt.Workbook怎么用?Python xlwt.Workbook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xlwt
的用法示例。
在下文中一共展示了xlwt.Workbook方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def __init__(self, path, engine=None, encoding=None, mode='w',
**engine_kwargs):
# Use the xlwt module as the Excel writer.
import xlwt
engine_kwargs['engine'] = engine
if mode == 'a':
raise ValueError('Append mode is not supported with xlwt!')
super(_XlwtWriter, self).__init__(path, mode=mode, **engine_kwargs)
if encoding is None:
encoding = 'ascii'
self.book = xlwt.Workbook(encoding=encoding)
self.fm_datetime = xlwt.easyxf(num_format_str=self.datetime_format)
self.fm_date = xlwt.easyxf(num_format_str=self.date_format)
示例2: __init__
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def __init__(self):
# count用于计数excel行
self.excel = xlwt.Workbook(encoding='utf8')
self.sheet = self.excel.add_sheet('文献列表', True)
self.set_style()
self.sheet.write(0, 0, '序号', self.basic_style)
self.sheet.write(0, 1, '题名', self.basic_style)
self.sheet.write(0, 2, '作者', self.basic_style)
self.sheet.write(0, 3, '单位', self.basic_style)
self.sheet.write(0, 4, '关键字', self.basic_style)
self.sheet.write(0, 5, '摘要', self.basic_style)
self.sheet.write(0, 6, '来源', self.basic_style)
self.sheet.write(0, 7, '发表时间', self.basic_style)
self.sheet.write(0, 8, '数据库', self.basic_style)
if config.crawl_isDownLoadLink == '1':
self.sheet.write(0, 9, '下载地址', self.basic_style)
# 生成userKey,服务器不做验证
self.cnkiUserKey = self.set_new_guid()
示例3: __init__
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def __init__(self, path, engine=None, **engine_kwargs):
# Use the openpyxl module as the Excel writer.
from openpyxl.workbook import Workbook
super(_OpenpyxlWriter, self).__init__(path, **engine_kwargs)
# Create workbook object with default optimized_write=True.
self.book = Workbook()
# Openpyxl 1.6.1 adds a dummy sheet. We remove it.
if self.book.worksheets:
try:
self.book.remove(self.book.worksheets[0])
except AttributeError:
# compat
self.book.remove_sheet(self.book.worksheets[0])
示例4: write_data
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def write_data(data, tname):
file = xlwt.Workbook(encoding='utf-8')
table = file.add_sheet(tname, cell_overwrite_ok=True)
l = 0
for line in data:
c = 0
for _ in line:
table.write(l, c, line[c])
c += 1
l += 1
sio = StringIO.StringIO()
file.save(sio)
return sio
# excel业务逻辑处理
示例5: from_data
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def from_data(self, fields, rows):
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('Sheet 1')
for i, fieldname in enumerate(fields):
worksheet.write(0, i, fieldname)
worksheet.col(i).width = 8000 # around 220 pixels
style = xlwt.easyxf('align: wrap yes')
for row_index, row in enumerate(rows):
for cell_index, cell_value in enumerate(row):
if isinstance(cell_value, basestring):
cell_value = re.sub("\r", " ", cell_value)
if cell_value is False: cell_value = None
worksheet.write(row_index + 1, cell_index, cell_value, style)
fp = StringIO()
workbook.save(fp)
fp.seek(0)
data = fp.read()
fp.close()
return data
示例6: create_workbook
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def create_workbook(output_file):
''' Creates a proper instance of data file writer depending on file extension.
Supported formats are: xls, xslx and csv.
Args:
output_file (str): file name.
Returns:
(xlwt.Workbook, XlsxWorkbook or OneCsvWriter): created data file
writer instance.
Raises:
ValueError: if a file with not supported extension was provided.
'''
if output_file.endswith('.xls'):
work_book = xlwt.Workbook()
elif output_file.endswith('.xlsx'):
work_book = XlsxWorkbook()
elif output_file.endswith('.csv'):
work_book = OneCsvWriter(output_file)
else:
raise ValueError('File {0} has unsupported output format'.format
(output_file))
return work_book
示例7: test_super_efficiency_with_VRS
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def test_super_efficiency_with_VRS(DEA_example2_data):
data = DEA_example2_data
data.add_input_category('I1')
data.add_input_category('I2')
data.add_input_category('I3')
data.add_output_category('O1')
data.add_output_category('O2')
model = EnvelopmentModelBase(
data,
EnvelopmentModelInputOriented(generate_supper_efficiency_upper_bound),
DefaultConstraintCreator())
model = EnvelopmentModelVRSDecorator(model)
super_efficiency_model = SupperEfficiencyModel(model)
start_time = datetime.datetime.now()
solution = super_efficiency_model.run()
end_time = datetime.datetime.now()
work_book = xlwt.Workbook()
writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
(end_time - start_time).total_seconds())
writer.write_data(solution)
work_book.save('tests/test_super_efficiency_with_VRS.xls')
示例8: test_peel_the_onion_CRS_multi_output_oriented
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def test_peel_the_onion_CRS_multi_output_oriented(DEA_example2_data):
model = _create_large_model_CRS_multi_output_oriented_with_non_discretionary(
DEA_example2_data)
start_time = datetime.datetime.now()
solution, ranks, state = peel_the_onion_method(model)
end_time = datetime.datetime.now()
_check_large_model_CRS_multi_output_oriented_with_non_discretionary(
solution, model.input_data)
dmus = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
expected_ranks = [1, 3, 2, 1, 3, 1, 1, 2, 1, 2, 1]
utils_for_tests.check_onion_ranks(
model.input_data, dmus, expected_ranks, ranks)
work_book = xlwt.Workbook()
ranks_as_list = []
ranks_as_list.append(ranks)
writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
(end_time - start_time).total_seconds(),
ranks=ranks_as_list)
writer.write_data(solution)
work_book.save('tests/test_peel_the_onion.xls')
示例9: test_virtual_weight_restrictions_multiplier_model
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def test_virtual_weight_restrictions_multiplier_model(data):
model = MultiplierModelBase(data, 0,
MultiplierInputOrientedModel())
bounds = {'I1': (None, 0.5)}
model = MultiplierModelWithVirtualWeightRestrictions(model, bounds)
start_time = datetime.datetime.now()
model_solution = model.run()
end_time = datetime.datetime.now()
utils_for_tests.check_if_category_is_within_virtual_limits(
model_solution, bounds)
work_book = xlwt.Workbook()
writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
(end_time - start_time).total_seconds())
writer.write_data(model_solution)
work_book.save('tests/test_virtual_weights_multi_output.xls')
示例10: test_price_ratio_multiplier_model
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def test_price_ratio_multiplier_model(data):
model = MultiplierModelBase(data, 0,
MultiplierInputOrientedModel())
bounds = {('I1', 'I2'): (None, 0.4), ('O1', 'O2'): (0.01, None)}
model = MultiplierModelWithPriceRatioConstraints(model, bounds)
start_time = datetime.datetime.now()
model_solution = model.run()
end_time = datetime.datetime.now()
utils_for_tests.check_if_category_is_within_price_ratio_constraints(
model_solution, bounds)
work_book = xlwt.Workbook()
writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
(end_time - start_time).total_seconds())
writer.write_data(model_solution)
work_book.save('tests/test_price_ratio_multi_output.xls')
示例11: test_abs_restrictions_env_model
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def test_abs_restrictions_env_model(data):
model = EnvelopmentModelBase(data,
EnvelopmentModelInputOriented(
generate_upper_bound_for_efficiency_score),
DefaultConstraintCreator())
bounds = {'I2': (0.01, 0.5)}
model = EnvelopmentModelWithAbsoluteWeightRestrictions(model, bounds)
start_time = datetime.datetime.now()
model_solution = model.run()
end_time = datetime.datetime.now()
utils_for_tests.check_if_category_is_within_abs_limits(
model_solution, bounds)
work_book = xlwt.Workbook()
writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
(end_time - start_time).total_seconds())
writer.write_data(model_solution)
work_book.save('tests/test_abs_constraints_env_output.xls')
示例12: test_abs_restrictions_env_model_output
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def test_abs_restrictions_env_model_output(data):
filename = 'tests/DEA_Harish_parameters.txt'
params = parse_parameters_from_file(filename)
categories, data, dmu_name, sheet_name = read_data(
params.get_parameter_value('DATA_FILE'))
coefficients, has_same_dmus = convert_to_dictionary(data)
model_input = construct_input_data_instance(categories, coefficients)
models, all_params = build_models(params, model_input)
assert len(models) == 1 and len(all_params) == 1
model = models[0]
start_time = datetime.datetime.now()
model_solution = model.run()
end_time = datetime.datetime.now()
bounds = {'Urban Roads (%)': (None, 0.003)}
utils_for_tests.check_if_category_is_within_abs_limits(
model_solution, bounds)
work_book = xlwt.Workbook()
writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
(end_time - start_time).total_seconds())
writer.write_data(model_solution)
work_book.save('tests/test_abs_constraints_env_outoriented_output.xls')
示例13: test_virual_restrictions_env_model
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def test_virual_restrictions_env_model(data):
model = EnvelopmentModelBase(data,
EnvelopmentModelInputOriented(
generate_upper_bound_for_efficiency_score),
DefaultConstraintCreator())
bounds = {'I2': (0.01, 0.5)}
model = EnvelopmentModelWithVirtualWeightRestrictions(model, bounds)
start_time = datetime.datetime.now()
model_solution = model.run()
end_time = datetime.datetime.now()
utils_for_tests.check_if_category_is_within_virtual_limits(
model_solution, bounds)
work_book = xlwt.Workbook()
writer = XLSWriter(Parameters(), work_book, datetime.datetime.today(),
(end_time - start_time).total_seconds())
writer.write_data(model_solution)
work_book.save('tests/test_virtual_constraints_env_output.xls')
示例14: __init__
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def __init__(self, path, engine=None, mode='w', **engine_kwargs):
# Use the openpyxl module as the Excel writer.
from openpyxl.workbook import Workbook
super(_OpenpyxlWriter, self).__init__(path, mode=mode, **engine_kwargs)
if self.mode == 'a': # Load from existing workbook
from openpyxl import load_workbook
book = load_workbook(self.path)
self.book = book
else:
# Create workbook object with default optimized_write=True.
self.book = Workbook()
if self.book.worksheets:
try:
self.book.remove(self.book.worksheets[0])
except AttributeError:
# compat - for openpyxl <= 2.4
self.book.remove_sheet(self.book.worksheets[0])
示例15: export2xls
# 需要导入模块: import xlwt [as 别名]
# 或者: from xlwt import Workbook [as 别名]
def export2xls(self):
import xlwt
font0 = xlwt.Font()
font0.bold = True
font0.height = 300
print((font0.height))
style0 = xlwt.XFStyle()
style0.font = font0
style1 = xlwt.XFStyle()
style1.num_format_str = 'D-MMM-YY'
wb = xlwt.Workbook()
ws = wb.add_sheet('A Test Sheet')
ws.write(0, 0, 'Test', style0)
ws.write(2, 0, 1)
ws.write(2, 1, 1)
ws.write(2, 2, xlwt.Formula("A3+B3"))
wb.save('datasheet.xls')
os.system("gnumeric datasheet.xls")