首页 > 代码库 > rails excel的创建
rails excel的创建
Example of how to add tables to an XlsxWriter worksheet.
Tables in Excel are used to group rows and columns of data into a single structure that can be referenced in a formula or formatted collectively.
See also Working with Worksheet Tables.
################################################################################# Example of how to add tables to an XlsxWriter worksheet.## Tables in Excel are used to group rows and columns of data into a single# structure that can be referenced in a formula or formatted collectively.## Copyright 2013-2014, John McNamara, jmcnamara@cpan.org#import xlsxwriterworkbook = xlsxwriter.Workbook(‘tables.xlsx‘)worksheet1 = workbook.add_worksheet()worksheet2 = workbook.add_worksheet()worksheet3 = workbook.add_worksheet()worksheet4 = workbook.add_worksheet()worksheet5 = workbook.add_worksheet()worksheet6 = workbook.add_worksheet()worksheet7 = workbook.add_worksheet()worksheet8 = workbook.add_worksheet()worksheet9 = workbook.add_worksheet()worksheet10 = workbook.add_worksheet()worksheet11 = workbook.add_worksheet()worksheet12 = workbook.add_worksheet()currency_format = workbook.add_format({‘num_format‘: ‘$#,##0‘})# Some sample data for the table.data = [ [‘Apples‘, 10000, 5000, 8000, 6000], [‘Pears‘, 2000, 3000, 4000, 5000], [‘Bananas‘, 6000, 6000, 6500, 6000], [‘Oranges‘, 500, 300, 200, 700],]################################################################################# Example 1.#caption = ‘Default table with no data.‘# Set the columns widths.worksheet1.set_column(‘B:G‘, 12)# Write the caption.worksheet1.write(‘B1‘, caption)# Add a table to the worksheet.worksheet1.add_table(‘B3:F7‘)################################################################################# Example 2.#caption = ‘Default table with data.‘# Set the columns widths.worksheet2.set_column(‘B:G‘, 12)# Write the caption.worksheet2.write(‘B1‘, caption)# Add a table to the worksheet.worksheet2.add_table(‘B3:F7‘, {‘data‘: data})################################################################################# Example 3.#caption = ‘Table without default autofilter.‘# Set the columns widths.worksheet3.set_column(‘B:G‘, 12)# Write the caption.worksheet3.write(‘B1‘,