import win32com.client
excel = win32com.client.Dispatch("Excel.Application")
excel.Visible = True
workbook = excel.Workbooks.Add()
workbook = excel.Workbooks.Open("피벗테이블예제.xlsx")
workbook = excel.Workbooks.Open(r"C:\2016-052.xlsx")
worksheet = workbook.Worksheets("Sheet1")
worksheet = workbook.ActiveSheet
worksheet2 = workbook.Worksheets.Add()
worksheet2.Name = "파이썬"
workbook.RefreshAll()
worksheet.Range('A174').Value = 'hello!'
worksheet.Range('A1:A10').Value = 'hello!'
worksheet.Cells(1, 1).Value = "hello world"
worksheet.Range('A3:B4, A6:B7, D3:F7').Value = "Hi2"
worksheet.Range(worksheet.Cells(3,1), worksheet.Cells(3,3)).Value = "Hi2"
worksheet.Range("B1").Interior.ColorIndex = 27
worksheet.Columns(1).ColumnWidth = 10
worksheet.Range("B:F").ColumnWidth = 20
worksheet.Rows(1).RowHeight = 40
worksheet.Range("2:100").RowHeight = 60
data = worksheet.Cells(2, 1).Value
print(worksheet.Cells(1, 1).Value)
worksheet.Range("A1:D24").Copy(worksheet2.Range("A1:D24"))
worksheet.Range("A1:D24").Copy(worksheet2.Range("D1"))
worksheet.cells(1,1).Font.name = "맑은 고딕"
worksheet.cells(1,1).Font.Size = 14
worksheet.cells(1,3).Font.Bold = True
worksheet.cells(1,3).Font.italic = True
worksheet.cells(1,3).Font.Underline = True
worksheet.Range("A1").font.ColorIndex = 40
worksheet.Range("B2").BorderAround(ColorIndex = 16,Weight = 3,LineStyle = 1)
worksheet.Range("B2:C8").BorderAround(ColorIndex = 16,Weight = 3,LineStyle = 1)
rng = worksheet.Range("B2:C8")
rng.Borders.LineStyle = 1
rng.Borders.ColorIndex = 14
rng.Borders.Weight = 2
worksheet2.Range("D3").ShrinkToFit = True
worksheet.Range("B2:C8").ClearFormats()
worksheet.cells(2,1).Value = '위로정렬'
worksheet.cells(1,2).Value = '왼쪽정렬'
worksheet.cells(2,2).Value = '가운데정렬'
worksheet.cells(2,3).Value = '우측정렬'
worksheet.cells(3,2).Value = '아래로정렬'
worksheet.Range("A:C").ColumnWidth = 40
worksheet.Range("1:3").RowHeight = 60
worksheet.Range("B1").VerticalAlignment = -4160
worksheet.Range("B1").HorizontalAlignment = -4108
worksheet.Range("B3").VerticalAlignment = -4107
worksheet.Range("B3").HorizontalAlignment = -4108
worksheet.Range("A2").HorizontalAlignment = -4131
worksheet.Range("A2").VerticalAlignment = -4108
worksheet.Range("C2").HorizontalAlignment = -4152
worksheet.Range("C2").VerticalAlignment = -4108
worksheet.Range("B2").VerticalAlignment = -4108
worksheet.Range("B2").HorizontalAlignment = -4108
worksheet.UsedRange.Columns.Count
worksheet.UsedRange.Rows.Count
worksheet.Rows(8).EntireRow.Insert()
worksheet.Columns(8).EntireColumn.Insert()
worksheet.Range("C2:D3").Insert()
worksheet.Range("C2:D3").Insert(1)
worksheet.Rows(2).Insert()
worksheet.Columns("B").Insert(1)
worksheet.Rows(8).EntireRow.Delete()
worksheet.Columns(8).EntireColumn.Delete()
worksheet.Columns.AutoFit()
worksheet.Rows.AutoFit()
worksheet.Range(f"A1:A10").ClearFormats()
workbook.Save()
workbook.SaveAs('c:\\Users\\Jason\\Desktop\\test.xlsx')
excel.Quit()