'''

from Basics import openExcel, openWorkbook, saveCopy, closeExcel

xl = openExcel()
wb = openWorkbook("../files/testWorkbook.xlsx", xl)

def insertSheetAt(position, name, workbook):
    """Position can be an integer (position of the sheet), or
    its name (String).
    name is the name of the new sheet (DUH)."""

    #Selecting the position, the sheet will be inserted
    #one step before.
    workbook.Sheets(position).Select()
    #Inserting a blank sheet.
    new_ws = wb.Worksheets.Add()
    #Renaming.
    new_ws.Name = name

insertSheetAt(2, "firstNewSheet", wb)
insertSheetAt("lol", "SecondNewSheet", wb)

saveCopy("../files/testWorkbookInsertNewSheetResult.xlsx", wb)
closeExcel(xl)

#Voila.
#At first you add 3 sheets : "toto", "titi", "lol"
#After the execution you then have
#"toto", "firstNewSheet",  "titi", "SecondNewSheet", "lol"
Пример #2
0
'''
Created on 26 avr. 2013

@author: Alexis Thongvan

The purpose of this code is to copy one of the
workbook's sheet and rename it
'''

from Basics import openExcel, openWorkbook, saveCopy, closeExcel

xl = openExcel()
wb = openWorkbook("../files/testWorkbook.xlsx", xl)

def copySheet(source_sheet, new_name, wb):
    """Copy a sheet, source_sheet must be the name in
    a String, you cannot use an integer"""
    ws = wb.Sheets(source_sheet)
    ws.Copy(Before=wb.Sheets(source_sheet))
    ws = wb.Sheets(source_sheet + " (2)")
    ws.Name = new_name

copySheet("lol", "BOOOM", wb)

saveCopy("../files/testWorkbookCopySheetResult.xlsx", wb)
closeExcel(xl)

#The "lol" has been duplicated and rename "BOOOM"
#Before : "toto", "titi", "lol"
#After : "toto", "titi", "BOOOM", "lol"
'''
Created on 26 avr. 2013

@author: Alexis Thongvan

Some sheets can be hidden, masked, to display them
right clic on any sheet name in excel and choose display.
then select one of the hidden sheets.

Our testWorkbook.xls contains 2 hidden sheet :
Hidden1 and data
'''
from Basics import openExcel, openWorkbook, saveCopy, closeExcel

xl = openExcel()
wb = openWorkbook("../files/testWorkbook.xlsx", xl)

def displayHiddenSheet(sheet_name, wb):
    wb.Sheets(sheet_name).Visible = True

displayHiddenSheet("Hidden1", wb)
saveCopy("../files/testWorkbookDisplayHiddenSheetResult.xlsx", wb)
closeExcel(xl)

#As you can see the hidden sheet is now selectable and visible
#Before : "toto", "titi", "lol"
#After : "toto", "titi", "lol", "Hidden1"