Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wera #36

Closed
wants to merge 1 commit into from
Closed

Wera #36

wants to merge 1 commit into from

Conversation

Kevv2228
Copy link

…, Side, Alignment from openpyxl.styles import NamedStyle from openpyxl.utils import get_column_letter from openpyxl.worksheet.datavalidation import DataValidation from openpyxl.drawing.image import Image # Crear un nuevo libro de Excel wb = openpyxl.Workbook() # Crear hojas wb.active.title = "Ejemplo de funciones" sheet1 = wb.active sheet2 = wb.create_sheet(title="Herramientas fundamentales") sheet3 = wb.create_sheet(title="BD Clientes") # -------------------------- # Hoja 1: Ejemplo de funciones # -------------------------- # Agregar datos y aplicar formato sheet1["A1"] = "Número" sheet1["A2"] = 1000 sheet1["A3"] = 2000 sheet1["A4"] = 0.25 # Formato de número sheet1["A2"].number_format = '#,##0' sheet1["A3"].number_format = '€#,##0.00' sheet1["A4"].number_format = '0.00%' # Pegado especial sheet1["B2"] = "Pegado Transpuesto" sheet1["B3"] = "Valores" # Formato de celda sheet1["A1"].font = Font(name="Calibri", size=14, bold=True, color="FF0000") sheet1["A1"].fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") sheet1["A1"].border = Border(left=Side(border_style="thin"), right=Side(border_style="thin"), top=Side(border_style="thin"), bottom=Side(border_style="thin")) # Protección de celda protected = NamedStyle(name="protected") protected.protection.locked = True sheet1["B1"].style = protected sheet1.protection.set_password("123") # Combinar y centrar celdas sheet1.merge_cells("C1:E1") sheet1["C1"] = "Título Combinado" sheet1["C1"].alignment = Alignment(horizontal="center") # Formato condicional sheet1["A5"] = 500 sheet1["A6"] = 1000 sheet1["A7"] = 500 highlight = openpyxl.formatting.Rule(type="duplicateValues", dxf=openpyxl.styles.differential.DifferentialStyle(fill=PatternFill(start_color="FFC7CE", end_color="FFC7CE"))) sheet1.conditional_formatting.add("A5:A7", highlight) # Insertar imagen img = Image("ruta_de_tu_imagen.png") # Especifica la ruta de tu imagen sheet1.add_image(img, "F5") # Insertar comentario sheet1["A1"].comment = openpyxl.comments.Comment("Este es un comentario", "Autor") # Insertar gráfico from openpyxl.chart import BarChart, Reference values = Reference(sheet1, min_col=1, min_row=2, max_col=1, max_row=4) chart = BarChart() chart.add_data(values) sheet1.add_chart(chart, "H10") # ------------------------------ # Hoja 2: Herramientas fundamentales # ------------------------------ sheet2["A1"] = "Herramientas Fundamentales" # (Aquí puedes repetir los mismos ejemplos con más detalle si lo deseas) # ------------------------------ # Hoja 3: BD Clientes # ------------------------------ clientes = [("Nombre", "Apellido", "Dirección", "Teléfono", "Correo Electrónico"), ("Juan", "Pérez", "Calle 1", "123456789", "[email protected]"), ("María", "López", "Calle 2", "987654321", "[email protected]")] for row in clientes: sheet3.append(row) # Aplicar filtros sheet3.auto_filter.ref = "A1:E3" # Guardar el archivo wb.save("240813-12345678-Salas Medel Josué Balam-EF.xlsx")

import openpyxl
from openpyxl.styles import Font, PatternFill, Border, Side, Alignment from openpyxl.styles import NamedStyle
from openpyxl.utils import get_column_letter
from openpyxl.worksheet.datavalidation import DataValidation from openpyxl.drawing.image import Image

Crear un nuevo libro de Excel

wb = openpyxl.Workbook()

Crear hojas

wb.active.title = "Ejemplo de funciones"
sheet1 = wb.active

sheet2 = wb.create_sheet(title="Herramientas fundamentales") sheet3 = wb.create_sheet(title="BD Clientes")

--------------------------

Hoja 1: Ejemplo de funciones

--------------------------

Agregar datos y aplicar formato

sheet1["A1"] = "Número"
sheet1["A2"] = 1000
sheet1["A3"] = 2000
sheet1["A4"] = 0.25

Formato de número

sheet1["A2"].number_format = '#,##0'
sheet1["A3"].number_format = '€#,##0.00'
sheet1["A4"].number_format = '0.00%'

Pegado especial

sheet1["B2"] = "Pegado Transpuesto"
sheet1["B3"] = "Valores"

Formato de celda

sheet1["A1"].font = Font(name="Calibri", size=14, bold=True, color="FF0000") sheet1["A1"].fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") sheet1["A1"].border = Border(left=Side(border_style="thin"), right=Side(border_style="thin"), top=Side(border_style="thin"), bottom=Side(border_style="thin"))

Protección de celda

protected = NamedStyle(name="protected")
protected.protection.locked = True
sheet1["B1"].style = protected
sheet1.protection.set_password("123")

Combinar y centrar celdas

sheet1.merge_cells("C1:E1")
sheet1["C1"] = "Título Combinado"
sheet1["C1"].alignment = Alignment(horizontal="center")

Formato condicional

sheet1["A5"] = 500
sheet1["A6"] = 1000
sheet1["A7"] = 500

highlight = openpyxl.formatting.Rule(type="duplicateValues", dxf=openpyxl.styles.differential.DifferentialStyle(fill=PatternFill(start_color="FFC7CE", end_color="FFC7CE"))) sheet1.conditional_formatting.add("A5:A7", highlight)

Insertar imagen

img = Image("ruta_de_tu_imagen.png") # Especifica la ruta de tu imagen sheet1.add_image(img, "F5")

Insertar comentario

sheet1["A1"].comment = openpyxl.comments.Comment("Este es un comentario", "Autor")

Insertar gráfico

from openpyxl.chart import BarChart, Reference

values = Reference(sheet1, min_col=1, min_row=2, max_col=1, max_row=4) chart = BarChart()
chart.add_data(values)
sheet1.add_chart(chart, "H10")

------------------------------

Hoja 2: Herramientas fundamentales

------------------------------

sheet2["A1"] = "Herramientas Fundamentales"

(Aquí puedes repetir los mismos ejemplos con más detalle si lo deseas)

------------------------------

Hoja 3: BD Clientes

------------------------------

clientes = [("Nombre", "Apellido", "Dirección", "Teléfono", "Correo Electrónico"),
("Juan", "Pérez", "Calle 1", "123456789", "[email protected]"),
("María", "López", "Calle 2", "987654321", "[email protected]")]

for row in clientes:
sheet3.append(row)

Aplicar filtros

sheet3.auto_filter.ref = "A1:E3"

Guardar el archivo

wb.save("240813-12345678-Salas Medel Josué Balam-EF.xlsx")

…, Side, Alignment from openpyxl.styles import NamedStyle from openpyxl.utils import get_column_letter from openpyxl.worksheet.datavalidation import DataValidation from openpyxl.drawing.image import Image # Crear un nuevo libro de Excel wb = openpyxl.Workbook() # Crear hojas wb.active.title = "Ejemplo de funciones" sheet1 = wb.active sheet2 = wb.create_sheet(title="Herramientas fundamentales") sheet3 = wb.create_sheet(title="BD Clientes") # -------------------------- # Hoja 1: Ejemplo de funciones # -------------------------- # Agregar datos y aplicar formato sheet1["A1"] = "Número" sheet1["A2"] = 1000 sheet1["A3"] = 2000 sheet1["A4"] = 0.25 # Formato de número sheet1["A2"].number_format = '#,##0' sheet1["A3"].number_format = '€#,##0.00' sheet1["A4"].number_format = '0.00%' # Pegado especial sheet1["B2"] = "Pegado Transpuesto" sheet1["B3"] = "Valores" # Formato de celda sheet1["A1"].font = Font(name="Calibri", size=14, bold=True, color="FF0000") sheet1["A1"].fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") sheet1["A1"].border = Border(left=Side(border_style="thin"), right=Side(border_style="thin"), top=Side(border_style="thin"), bottom=Side(border_style="thin")) # Protección de celda protected = NamedStyle(name="protected") protected.protection.locked = True sheet1["B1"].style = protected sheet1.protection.set_password("123") # Combinar y centrar celdas sheet1.merge_cells("C1:E1") sheet1["C1"] = "Título Combinado" sheet1["C1"].alignment = Alignment(horizontal="center") # Formato condicional sheet1["A5"] = 500 sheet1["A6"] = 1000 sheet1["A7"] = 500 highlight = openpyxl.formatting.Rule(type="duplicateValues", dxf=openpyxl.styles.differential.DifferentialStyle(fill=PatternFill(start_color="FFC7CE", end_color="FFC7CE"))) sheet1.conditional_formatting.add("A5:A7", highlight) # Insertar imagen img = Image("ruta_de_tu_imagen.png") # Especifica la ruta de tu imagen sheet1.add_image(img, "F5") # Insertar comentario sheet1["A1"].comment = openpyxl.comments.Comment("Este es un comentario", "Autor") # Insertar gráfico from openpyxl.chart import BarChart, Reference values = Reference(sheet1, min_col=1, min_row=2, max_col=1, max_row=4) chart = BarChart() chart.add_data(values) sheet1.add_chart(chart, "H10") # ------------------------------ # Hoja 2: Herramientas fundamentales # ------------------------------ sheet2["A1"] = "Herramientas Fundamentales" # (Aquí puedes repetir los mismos ejemplos con más detalle si lo deseas) # ------------------------------ # Hoja 3: BD Clientes # ------------------------------ clientes = [("Nombre", "Apellido", "Dirección", "Teléfono", "Correo Electrónico"), ("Juan", "Pérez", "Calle 1", "123456789", "[email protected]"), ("María", "López", "Calle 2", "987654321", "[email protected]")] for row in clientes: sheet3.append(row) # Aplicar filtros sheet3.auto_filter.ref = "A1:E3" # Guardar el archivo wb.save("240813-12345678-Salas Medel Josué Balam-EF.xlsx")

import openpyxl
from openpyxl.styles import Font, PatternFill, Border, Side, Alignment
from openpyxl.styles import NamedStyle
from openpyxl.utils import get_column_letter
from openpyxl.worksheet.datavalidation import DataValidation
from openpyxl.drawing.image import Image

# Crear un nuevo libro de Excel
wb = openpyxl.Workbook()

# Crear hojas
wb.active.title = "Ejemplo de funciones"
sheet1 = wb.active

sheet2 = wb.create_sheet(title="Herramientas fundamentales")
sheet3 = wb.create_sheet(title="BD Clientes")

# --------------------------
# Hoja 1: Ejemplo de funciones
# --------------------------

# Agregar datos y aplicar formato
sheet1["A1"] = "Número"
sheet1["A2"] = 1000
sheet1["A3"] = 2000
sheet1["A4"] = 0.25

# Formato de número
sheet1["A2"].number_format = '#,##0'
sheet1["A3"].number_format = '€#,##0.00'
sheet1["A4"].number_format = '0.00%'

# Pegado especial
sheet1["B2"] = "Pegado Transpuesto"
sheet1["B3"] = "Valores"

# Formato de celda
sheet1["A1"].font = Font(name="Calibri", size=14, bold=True, color="FF0000")
sheet1["A1"].fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid")
sheet1["A1"].border = Border(left=Side(border_style="thin"), right=Side(border_style="thin"), top=Side(border_style="thin"), bottom=Side(border_style="thin"))

# Protección de celda
protected = NamedStyle(name="protected")
protected.protection.locked = True
sheet1["B1"].style = protected
sheet1.protection.set_password("123")

# Combinar y centrar celdas
sheet1.merge_cells("C1:E1")
sheet1["C1"] = "Título Combinado"
sheet1["C1"].alignment = Alignment(horizontal="center")

# Formato condicional
sheet1["A5"] = 500
sheet1["A6"] = 1000
sheet1["A7"] = 500

highlight = openpyxl.formatting.Rule(type="duplicateValues", dxf=openpyxl.styles.differential.DifferentialStyle(fill=PatternFill(start_color="FFC7CE", end_color="FFC7CE")))
sheet1.conditional_formatting.add("A5:A7", highlight)

# Insertar imagen
img = Image("ruta_de_tu_imagen.png")  # Especifica la ruta de tu imagen
sheet1.add_image(img, "F5")

# Insertar comentario
sheet1["A1"].comment = openpyxl.comments.Comment("Este es un comentario", "Autor")

# Insertar gráfico
from openpyxl.chart import BarChart, Reference

values = Reference(sheet1, min_col=1, min_row=2, max_col=1, max_row=4)
chart = BarChart()
chart.add_data(values)
sheet1.add_chart(chart, "H10")

# ------------------------------
# Hoja 2: Herramientas fundamentales
# ------------------------------
sheet2["A1"] = "Herramientas Fundamentales"
# (Aquí puedes repetir los mismos ejemplos con más detalle si lo deseas)

# ------------------------------
# Hoja 3: BD Clientes
# ------------------------------
clientes = [("Nombre", "Apellido", "Dirección", "Teléfono", "Correo Electrónico"),
            ("Juan", "Pérez", "Calle 1", "123456789", "[email protected]"),
            ("María", "López", "Calle 2", "987654321", "[email protected]")]

for row in clientes:
    sheet3.append(row)

# Aplicar filtros
sheet3.auto_filter.ref = "A1:E3"

# Guardar el archivo
wb.save("240813-12345678-Salas Medel Josué Balam-EF.xlsx")
@mattsb42-meta mattsb42-meta locked as spam and limited conversation to collaborators Aug 18, 2024
@mattsb42 mattsb42 closed this Aug 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants