Páginas
miércoles, 24 de diciembre de 2014
Python: Funcion para convertir fecha de Excel a formato d-m-y
(exceldate.py)
import datetime
def exceldate(serial):
seconds = (serial - 25569) * 86400.0
d = datetime.datetime.utcfromtimestamp(seconds)
return d.strftime('%d-%m-%y')
if __name__ == "__main__":
exceldate()
Y asi se utiliza:
>>> from exceldate import exceldate
>>> d = exceldate(42031.0)
>>> d
'27-01-15'
miércoles, 17 de diciembre de 2014
Python: Objetos, propiedades y metodos en la libreria xlrd
Abrir un libro:
reporte = xlrd.open_workbook(path)
Metodos y propiedades del objeto libro:
actualfmtcount
addin_func_names
biff2_8_load
biff_version
builtinfmtcount
codepage
colour_map
countries
datemode
derive_encoding
dump
encoding
fake_globals_get_sheet
filestr
font_list
format_list
format_map
formatting_info
get2bytes
get_record_parts
get_record_parts_conditional
get_sheet
get_sheets
getbof
handle_boundsheet
handle_builtinfmtcount
handle_codepage
handle_country
handle_datemode
handle_externname
handle_externsheet
handle_filepass
handle_name
handle_obj
handle_sheethdr
handle_sheetsoffset
handle_sst
handle_supbook
handle_writeaccess
initialise_format_info
load_time_stage_1
load_time_stage_2
logfile
mem
name_and_scope_map
name_map
name_obj_list
names_epilogue
nsheets
on_demand
palette_record
parse_globals
props
ragged_rows
raw_user_name
read
release_resources
sheet_by_index
sheet_by_name
sheet_loaded
sheet_names
sheets
style_name_map
unload_sheet
use_mmap
user_name
verbosity
xf_list
xfcount
Metodos y propiedades de la hoja:
automatic_grid_line_colour
bf
biff_version
book
bt
cached_normal_view_mag_factor
cached_page_break_preview_mag_factor
cell
cell_note_map
cell_type
cell_value
cell_xf_index
col
col_label_ranges
col_slice
col_types
col_values
colinfo_map
columns_from_right_to_left
computed_column_width
cooked_normal_view_mag_factor
cooked_page_break_preview_mag_factor
default_additional_space_above
default_additional_space_below
default_row_height
default_row_height_mismatch
default_row_hidden
defcolwidth
dump
fake_XF_from_BIFF20_cell_attr
first_visible_colx
first_visible_rowx
fixed_BIFF2_xfindex
formatting_info
gcw
gridline_colour_index
gridline_colour_rgb
handle_feat11
handle_hlink
handle_msodrawingetc
handle_note
handle_obj
handle_quicktip
handle_txo
has_pane_record
horizontal_page_breaks
horz_split_first_visible
horz_split_pos
hyperlink_list
hyperlink_map
insert_new_BIFF20_xf
logfile
merged_cells
name
ncols
nrows
number
panes_are_frozen
put_cell
put_cell_ragged
put_cell_unragged
ragged_rows
read
remove_splits_if_pane_freeze_is_remov
req_fmt_info
rich_text_runlist_map
row
row_label_ranges
row_len
row_slice
row_types
row_values
rowinfo_map
scl_mag_factor
sheet_selected
sheet_visible
show_formulas
show_grid_lines
show_in_page_break_preview
show_outline_symbols
show_sheet_headers
show_zero_values
split_active_pane
standardwidth
string_record_contents
tidy_dimensions
update_cooked_mag_factors
utter_max_cols
utter_max_rows
verbosity
vert_split_first_visible
vert_split_pos
vertical_page_breaks
visibility
Metodos y propiedades de las celdas:
capitalize
center
count
decode
encode
endswith
expandtabs
find
format
index
isalnum
isalpha
isdigit
islower
isspace
istitle
isupper
join
ljust
lower
lstrip
partition
replace
rfind
rindex
rjust
rpartition
rsplit
rstrip
split
splitlines
startswith
strip
swapcase
title
translate
upper
zfill
reporte = xlrd.open_workbook(path)
Metodos y propiedades del objeto libro:
actualfmtcount
addin_func_names
biff2_8_load
biff_version
builtinfmtcount
codepage
colour_map
countries
datemode
derive_encoding
dump
encoding
fake_globals_get_sheet
filestr
font_list
format_list
format_map
formatting_info
get2bytes
get_record_parts
get_record_parts_conditional
get_sheet
get_sheets
getbof
handle_boundsheet
handle_builtinfmtcount
handle_codepage
handle_country
handle_datemode
handle_externname
handle_externsheet
handle_filepass
handle_name
handle_obj
handle_sheethdr
handle_sheetsoffset
handle_sst
handle_supbook
handle_writeaccess
initialise_format_info
load_time_stage_1
load_time_stage_2
logfile
mem
name_and_scope_map
name_map
name_obj_list
names_epilogue
nsheets
on_demand
palette_record
parse_globals
props
ragged_rows
raw_user_name
read
release_resources
sheet_by_index
sheet_by_name
sheet_loaded
sheet_names
sheets
style_name_map
unload_sheet
use_mmap
user_name
verbosity
xf_list
xfcount
Metodos y propiedades de la hoja:
automatic_grid_line_colour
bf
biff_version
book
bt
cached_normal_view_mag_factor
cached_page_break_preview_mag_factor
cell
cell_note_map
cell_type
cell_value
cell_xf_index
col
col_label_ranges
col_slice
col_types
col_values
colinfo_map
columns_from_right_to_left
computed_column_width
cooked_normal_view_mag_factor
cooked_page_break_preview_mag_factor
default_additional_space_above
default_additional_space_below
default_row_height
default_row_height_mismatch
default_row_hidden
defcolwidth
dump
fake_XF_from_BIFF20_cell_attr
first_visible_colx
first_visible_rowx
fixed_BIFF2_xfindex
formatting_info
gcw
gridline_colour_index
gridline_colour_rgb
handle_feat11
handle_hlink
handle_msodrawingetc
handle_note
handle_obj
handle_quicktip
handle_txo
has_pane_record
horizontal_page_breaks
horz_split_first_visible
horz_split_pos
hyperlink_list
hyperlink_map
insert_new_BIFF20_xf
logfile
merged_cells
name
ncols
nrows
number
panes_are_frozen
put_cell
put_cell_ragged
put_cell_unragged
ragged_rows
read
remove_splits_if_pane_freeze_is_remov
req_fmt_info
rich_text_runlist_map
row
row_label_ranges
row_len
row_slice
row_types
row_values
rowinfo_map
scl_mag_factor
sheet_selected
sheet_visible
show_formulas
show_grid_lines
show_in_page_break_preview
show_outline_symbols
show_sheet_headers
show_zero_values
split_active_pane
standardwidth
string_record_contents
tidy_dimensions
update_cooked_mag_factors
utter_max_cols
utter_max_rows
verbosity
vert_split_first_visible
vert_split_pos
vertical_page_breaks
visibility
Metodos y propiedades de las celdas:
capitalize
center
count
decode
encode
endswith
expandtabs
find
format
index
isalnum
isalpha
isdigit
islower
isspace
istitle
isupper
join
ljust
lower
lstrip
partition
replace
rfind
rindex
rjust
rpartition
rsplit
rstrip
split
splitlines
startswith
strip
swapcase
title
translate
upper
zfill
martes, 9 de diciembre de 2014
Python: Crear un archivo HTML basado en una hoja de Excel
La idea es que Python lea las celdas del archivo excel y vaya escribiendo el archivo HTML un dato a la vez:
import xlrd
def upload():
mobile = open('d:/rubenBk/HTML/mobile quota.html', 'w')
report = xlrd.open_workbook('D:/RubenBK/Reports/cctableruben.xlsm')
sheet = report.sheet_by_name('Licencias')
mobile.write('<body style="background-color:yellow">')
mobile.write('<table>')
for r in range(sheet.nrows):
mobile.write('<tr>') #creates the row
for c in range(sheet.ncols):
if unicode(sheet.cell_value(r,c)).encode('utf-8') != '': #if the cell contais data, apply a border to it.
mobile.write('<td style = "border-style:solid; border-width:1px">' + unicode(sheet.cell_value(r,c)).encode('utf-8') + '</td>')#fills data in row
else:
mobile.write('<td>' + unicode(sheet.cell_value(r,c)).encode('utf-8') + '</td>')#fills data in row
mobile.write('</table>')
mobile.write('<a href = "D:/RubenBK/HTML/Home.html">Home</a>')
mobile.write('</body>')
if __name__ == '__main__':
upload()
viernes, 5 de diciembre de 2014
Python: Abrir ventana para seleccionar archivos
Una maravilla esto, super util para hacer las aplicaciones mas 'user friendly':
import Tkinter, tkFileDialog, re
root = Tkinter.Tk() #esto se hace solo para eliminar la ventanita de Tkinter
root.withdraw() #ahora se cierra
file_path = tkFileDialog.askopenfilename() #abre el explorador de archivos y guarda la seleccion en la variable!
#Ahora para guardar el directorio donde se encontraba el archivo seleccionado:
match = re.search(r'/.*\..+', file_path)#matches name of file
file_position = file_path.find(match.group()) #defines position of filename in file path
save_path = file_path[0: file_position+1] #extracts the saving path.
import Tkinter, tkFileDialog, re
root = Tkinter.Tk() #esto se hace solo para eliminar la ventanita de Tkinter
root.withdraw() #ahora se cierra
file_path = tkFileDialog.askopenfilename() #abre el explorador de archivos y guarda la seleccion en la variable!
#Ahora para guardar el directorio donde se encontraba el archivo seleccionado:
match = re.search(r'/.*\..+', file_path)#matches name of file
file_position = file_path.find(match.group()) #defines position of filename in file path
save_path = file_path[0: file_position+1] #extracts the saving path.
Suscribirse a:
Entradas (Atom)