Найти - Пользователи
Полная версия: Как получить из файла xls (Excel) настройки страниц
Начало » Python для новичков » Как получить из файла xls (Excel) настройки страниц
1
kosmo67
меня интересует больше ориентация страницы книжная или альбомная
xlrd я так понял этого не умеет…
kosmo67
может кому пригодится…

from xlrd.biffh import *
import xlrd
class PageSetup(BaseObject):
    print_columns_rows = 0
    landscape_portrait = 0
    paper_setup_initialised = 1 # Paper size, scaling factor, paper orientation (portrait/landscape),
                              # print resolution and number of copies are not initialised
    colour_black_and_white = 1
    default_draft_quality = 0
    print_cell_notes = 0
    default_paper_orientation = 0
    automatic_page_numbers = 0
    print_notes = 0
    print_errors_displayed = 0
    not_print_errors = 0
def read_ps(bk,st):
    self_put_cell = st.put_cell
    local_unpack = unpack
    bk_get_record_parts = bk.get_record_parts
    while 1:
        rc, data_len, data = bk_get_record_parts()
        if rc == XL_EOF:
            return None
        
        elif  rc == XL_PAGESETUP:
            paper_size,scaling_factor,start_page,width,height,option_flags,print_resolution,\
            vertical_print_resolution,header_margin,footer_margin,number_copies = local_unpack('<HHHHHHHHddH', data)
            ps = PageSetup()
            upkbits(ps, option_flags, (
                ( 0, 0x0001, 'print_columns_rows'),
                ( 1, 0x0002, 'landscape_portrait'),
                ( 2, 0x0004, 'paper_setup_initialised'),
                ( 6, 0x0040, 'default_paper_orientation'), 
                ))
            return ps
        else:
            pass
file_name = 'template.xls'
book = xlrd.open_workbook(file_name,
           on_demand = True,
           formatting_info = True)
sheet = book.sheet_by_index(0)
    
page_setup = read_ps(book,sheet)
if page_setup:
    if page_setup.landscape_portrait:
        print 'portrait'
    else:
        print 'landscape'
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB