2016-11-25 42 views
1

我想設置特定行沒有&列特定的工作表(incident_sheet3) 試圖set_row/set_column和set_size沒有設定的行和列的xlsxwriter蟒蛇

incident_excel_file = xlsxwriter.Workbook("incidents_excel.xlsx") 
incident_sheet = incident_excel_file.add_worksheet(name="incidents") 
incident_sheet2 = incident_excel_file.add_worksheet(name="Handoff Template") 
incident_excel_file.set_size(100,100) 
incident_sheet.set_column(0,4,25) 
incident_sheet2.set_column(0,15,15) 
incident_sheet3 = incident_excel_file.add_worksheet() 
incident_sheet3.set_column(0,1) 

用於set_column設定爲細胞寬度定義的範圍

+0

我的問題是,我怎樣才能在表單中設置X行和Y列? – ajay

+0

在下面看到我的更新。 – jmcnamara

回答

0

set_column()的語法是:

set_column(first_col, last_col, width, cell_format, options) 

在你的榜樣,你不要「T指定寬度:

incident_sheet3.set_column(0,1) 

更新:如果你想顯示的工作表中的某個區域,並隱藏一切你可以做這樣的:

import xlsxwriter 

workbook = xlsxwriter.Workbook('hide_row_col.xlsx') 
worksheet = workbook.add_worksheet() 

# Write some data. 
worksheet.write('D1', 'Some hidden columns.') 
worksheet.write('A8', 'Some hidden rows.') 

# Hide all rows without data. 
worksheet.set_default_row(hide_unused_rows=True) 

# Set the height of empty rows that we do want to display even if it is 
# the default height. 
for row in range(1, 7): 
    worksheet.set_row(row, 15) 

# Columns can be hidden explicitly. This doesn't increase the file size. 
worksheet.set_column('G:XFD', None, None, {'hidden': True}) 

workbook.close() 

輸出:

enter image description here

看到XlsxWriter文檔的example

+0

謝謝。這有幫助 – ajay