def doExport(self, event):
export_count = 0
dlg = wx.FileDialog(self, "Save to file:", ".", "", "Text (*.txt)|*.txt", wx.SAVE|wx.OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
i = dlg.GetFilterIndex()
if i == 0: # Text format
try:
f = open(dlg.GetPath(), "w")
f.write('# "Name", Number\n')
for i in range(self.listCtrl.GetItemCount()):
f.write('"%s",%s\n' % (self.getColumnText(i,0), self.getColumnText(i,1)))
export_count += 1
f.close()
pySIMmessage(self, "Exported %d phonebook contacts\n\nFilename: %s" % (export_count, dlg.GetPath()), "Export OK")
except:
print_exc()
pySIMmessage(self, "Unable to save your phonebook to file: %s" % dlg.GetPath(), "Export error")
# elif i == 1: # Excel document
# try:
# xl = win32com.client.Dispatch("Excel.Application")
# xl.Workbooks.Add()
# xl.Cells(1,1).Value = "Name"
# xl.Cells(1,2).Value = "Number"
# for i in range(self.listCtrl.GetItemCount()):
# row = i + 2
# xl.Cells(row,1).Value = self.getColumnText(i,0)
# xl.Cells(row,2).Value = self.getColumnText(i,1)
# export_count += 1
# xl.ActiveWorkbook.SaveAs(dlg.GetPath())
# xl.ActiveWorkbook.DisplayAlerts = 0
# #xl.Saved = 1
# xl.Quit()
# pySIMmessage(self, "Exported %d phonebook contacts\n\nFilename: %s" % (export_count, dlg.GetPath()), "Export OK")
# except:
# print_exc()
# pySIMmessage(self, "Unable to save your phonebook to file: %s" % dlg.GetPath(), "Export error")
dlg.Destroy()
评论列表
文章目录