下面这些我实在懒得整理了,直接复制了,用到再研究,觉得没什么卵用

    1. # 4. 对齐方式
    2. """
    3. cell = sheet.cell(1, 1)
    4. # horizontal,水平方向对齐方式:"general", "left", "center", "right", "fill", "justify", "centerContinuous", "distributed"
    5. # vertical,垂直方向对齐方式:"top", "center", "bottom", "justify", "distributed"
    6. # text_rotation,旋转角度。
    7. # wrap_text,是否自动换行。
    8. cell.alignment = Alignment(horizontal='center', vertical='distributed', text_rotation=45, wrap_text=True)
    9. wb.save("p2.xlsx")
    10. """
    11. # 5. 边框
    12. # side的style有如下:dashDot','dashDotDot', 'dashed','dotted','double','hair', 'medium', 'mediumDashDot', 'mediumDashDotDot','mediumDashed', 'slantDashDot', 'thick', 'thin'
    13. """
    14. cell = sheet.cell(9, 2)
    15. cell.border = Border(
    16. top=Side(style="thin", color="FFB6C1"),
    17. bottom=Side(style="dashed", color="FFB6C1"),
    18. left=Side(style="dashed", color="FFB6C1"),
    19. right=Side(style="dashed", color="9932CC"),
    20. diagonal=Side(style="thin", color="483D8B"), # 对角线
    21. diagonalUp=True, # 左下 ~ 右上
    22. diagonalDown=True # 左上 ~ 右下
    23. )
    24. wb.save("p2.xlsx")
    25. """
    26. # 6.字体
    27. """
    28. cell = sheet.cell(5, 1)
    29. cell.font = Font(name="微软雅黑", size=45, color="ff0000", underline="single")
    30. wb.save("p2.xlsx")
    31. """
    32. # 7.背景色
    33. """
    34. cell = sheet.cell(5, 3)
    35. cell.fill = PatternFill("solid", fgColor="99ccff")
    36. wb.save("p2.xlsx")
    37. """
    38. # 8.渐变背景色
    39. """
    40. cell = sheet.cell(5, 5)
    41. cell.fill = GradientFill("linear", stop=("FFFFFF", "99ccff", "000000"))
    42. wb.save("p2.xlsx")
    43. """
    44. # 9.宽高(索引从1开始)
    45. """
    46. sheet.row_dimensions[1].height = 50
    47. sheet.column_dimensions["E"].width = 100
    48. wb.save("p2.xlsx")
    49. """