The the Workbook COM object has a Close() method. Basically, it should be something like:
xl = Dispatch('Excel.Application')
wb = xl.Workbooks.Open('New Workbook.xlsx')
# do some stuff
wb.Close(True) # save the workbook
The above was just a skeleton here's some code that works on my machine against Office 2010:
from win32com.client import Dispatch
xl = Dispatch('Excel.Application')
wb = xl.Workbooks.Add()
ws = wb.Worksheets.Add()
cell = ws.Cells(1)
cell.Value = 'Some text'
wb.Close(True, r'C:PathofolderTest.xlsx')
Of course, that creates a new xlsx file. But then I'm able to successfully open and modify the file in the same session as follows:
wb = xl.Workbooks.Open(r'C:PathofolderTest.xlsx')
ws = wb.Worksheets(1)
cell = ws.Cells(2)
cell.Value = 'Some more text'
wb.Close(True)
Don't know if any of that helps...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…