本文整理匯總了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")