Workbook

save()
save_copy()

You can save the workbook by calling save(). You can also save the file under a different name by calling save with a filename:

>>> save("C:\\Users\\James_Bond\\Desktop\\007.xlsx")

and, you can save a copy with save_copy:

>>> save_copy("C:\\Users\\Bruce_Wayne\\Desktop\\batman.xlsx")

You should always provide save with a full pathname.

recalc_wkbk([option = 1])

Recalculates the workbook. You can set option to 1, 2, or 3. 1 will recalculate cells that have had their inputs changed since the last calculation. 2 will recalculate all formulas. 3 will rebuild the cell dependency graph, and then recalculate all formulas. Option 1 should usually be used.

>>> recalc_wkbk()
## recalculates the workbook
recalc_mode([option])

changes the calculation mode of Excel. The options are ‘automatic’, ‘semiautomatic’, and ‘manual’. Returns the current calculation mode if no option is passed.

>>> recalc_mode()
'automatic'
>>> recalc_mode('manual')
>>> recalc_mode()
'manual'

This affects every open workbook.

pivot_refresh([sheet])

pivot_refresh() will refresh the pivot tables on sheet. If sheet isn’t passed, it’ll refresh the active sheet.

>>> pivot_refresh()
## refreshes the pivot table on the active sheet
wkbk_dir()

Returns the directory of the current workbook.

>>> wkbk_dir()
"C:\\Users\\James_Bond\\Documents\\"

Multiple Workbooks

active_wkbk([wkbk = None])

Sets the active workbook. Returns the currently active workbook by default.

>>> active_wkbk()
"Book1.xlsx"
>>> active_wkbk("Book2.xlsx")
>>> active_wkbk()
"Book2.xlsx"

(The active workbook is the workbook you’re reading from and writing to.)

open_wkbk(wkbk_name)

Opens a workbook. wkbk_name can include the full path of the workbook; if it doesn’t include a path, DataNitro will check the current folder.

>>> open_wkbk("C:\Users\DataNitro\Book1.xlsx")
# opens Book1 in C:\Users\DataNitro
>>> open_wkbk("no_more_vba.xlsx")
# opens no_more_vba in the same folder as the current workbook
close_wkbk(wkbk)

Closes a workbook.

>>> close_wkbk("Book2.xlsx")
# Book2 is now closed.
new_wkbk()

Creates a new workbook and returns its name.

>>> new_wkbk()
"Book2"
all_wkbks()

Returns a list of all open workbooks.

>>> all_wkkbs()
["Book1.xlsx", "Book2.xlsx"]
copy_sheet(workbook[, sheet])
move_sheet(workbook[, sheet])

Copies or moves “sheet” from the current workbook into “workbook”. Uses the active sheet by default.

>>> copy_sheet("Book2")
# active sheet is copied to Book2
>>> move_sheet("Book2", "this_sheet")
# this_sheet is moved to Book2