def importVCardFile(self, vcardfilename, currentSheet): self.componentDict = {} self.componentList = [] writer = KSpread.writer() if not writer.setSheet(currentSheet): raise Exception, T.i18n("Invalid sheet \"%1\" defined.", [currentSheet]) writer.next() #hack writer.next() #hack f = open(vcardfilename, 'r') lines = [] for line in f: if not line.strip() == "": lines.append( line ) continue if len(lines) > 0: self.importVCardLines(writer, lines) lines = [] if len(lines) > 0: self.importVCardLines(writer, lines) if writer.setSheet(currentSheet): writer.next() #hack writer.setValues(self.componentList)
def doImport(self): currentSheet = self.sheetslistview.sheet() if not currentSheet: raise Exception, T.i18n("No current sheet.") writer = KSpread.writer() if not writer.setSheet(currentSheet): self.forms.showMessageBox("Sorry", T.i18n('Invalid sheet "%1" defined.', [currentSheet])) cell = self.sheetslistview.editor() if not writer.setCell(cell): self.forms.showMessageBox("Sorry", T.i18n('Invalid cell "%1" defined.', [cell])) csvfilename = self.openwidget.selectedFile() if not os.path.isfile(csvfilename): self.forms.showMessageBox("Sorry", T.i18n("File '%1' not found.", [csvfilename])) # writer.connect("valueChanged()",writer.next) csv.register_dialect("custom", self.getCustomDialect()) csvfile = open(csvfilename, "r") try: csvreader = csv.reader(csvfile, dialect="custom") try: while True: record = csvreader.next() if not writer.setValues(record): print "Failed to set all of '%s' to cell '%s'" % (record, writer.cell()) # writer.insertValues(record) writer.next() except StopIteration: pass finally: csvfile.close()
def importVCardFile(self, vcardfilename, currentSheet): self.componentDict = {} self.componentList = [] writer = KSpread.writer() if not writer.setSheet(currentSheet): raise Exception, T.i18n("Invalid sheet \"%1\" defined.", [currentSheet]) writer.next() #hack writer.next() #hack f = open(vcardfilename, 'r') lines = [] for line in f: if not line.strip() == "": lines.append(line) continue if len(lines) > 0: self.importVCardLines(writer, lines) lines = [] if len(lines) > 0: self.importVCardLines(writer, lines) if writer.setSheet(currentSheet): writer.next() #hack writer.setValues(self.componentList)
def doImport(self): currentSheet = self.sheetslistview.sheet() if not currentSheet: raise "No current sheet." writer = KSpread.writer() if not writer.setSheet(currentSheet): raise "Invalid sheet \"%s\" defined." % currentSheet cell = self.sheetslistview.editor() if not writer.setCell(cell): raise "Invalid cell \"%s\" defined." % cell csvfilename = self.openwidget.selectedFile() if not os.path.isfile(csvfilename): raise "File '%s' not found." % csvfilename #writer.connect("valueChanged()",writer.next) csv.register_dialect("custom", self.getCustomDialect()) csvfile = open(csvfilename,'r') try: csvreader = csv.reader(csvfile, dialect="custom") try: while True: record = csvreader.next() if not writer.setValues(record): print "Failed to set all of '%s' to cell '%s'" % (record,writer.cell()) #writer.insertValues(record) writer.next() except StopIteration: pass finally: csvfile.close()
def start(self): writer = KSpread.writer() filename = self.showImportDialog(writer) if not filename: return # no exception, user prob pressed cancel Plan = Kross.module("Plan") if Plan is None: raise Exception, T.i18n("Failed to start Plan. Is Plan installed?") Plan.openUrl(filename) proj = Plan.project() data = self.showDataSelectionDialog(writer, Plan) if len(data) == 0: raise Exception, T.i18n("No data to import") objectType = data[0] schedule = data[1] props = data[2] if len(props) == 0: raise Exception, T.i18n("No properties to import") record = [] if data[3] == True: for prop in props: record.append(proj.headerData(objectType, prop)) if not writer.setValues(record): if self.forms.showMessageBox( "WarningContinueCancel", T.i18n("Warning"), T.i18n( "Failed to set all properties of '%1' to cell '%2'", [", ".join(record), writer.cell()])) == "Cancel": return writer.next() if objectType == 0: # Nodes self.importValues(writer, proj, proj, props, schedule) if objectType == 1: # Resources for i in range(proj.resourceGroupCount()): self.importValues(writer, proj, proj.resourceGroupAt(i), props, schedule) if objectType == 2: # Accounts for i in range(proj.accountCount()): self.importValues(writer, proj, proj.accountAt(i), props, schedule)
def doImport(self): currentSheet = self.sheetslistview.sheet() if not currentSheet: raise Exception, T.i18n("No current sheet.") writer = KSpread.writer() if not writer.setSheet(currentSheet): self.forms.showMessageBox( "Sorry", T.i18n("Invalid sheet \"%1\" defined.", [currentSheet])) cell = self.sheetslistview.editor() if not writer.setCell(cell): self.forms.showMessageBox( "Sorry", T.i18n("Invalid cell \"%1\" defined.", [cell])) csvfilename = self.openwidget.selectedFile() if not os.path.isfile(csvfilename): self.forms.showMessageBox( "Sorry", T.i18n("File '%1' not found.", [csvfilename])) #writer.connect("valueChanged()",writer.next) csv.register_dialect("custom", self.getCustomDialect()) csvfile = open(csvfilename, 'r') try: csvreader = csv.reader(csvfile, dialect="custom") try: while True: record = csvreader.next() if not writer.setValues(record): print "Failed to set all of '%s' to cell '%s'" % ( record, writer.cell()) #writer.insertValues(record) writer.next() except StopIteration: pass finally: csvfile.close()
def start(self): writer = KSpread.writer() filename = self.showImportDialog(writer) if not filename: return # no exception, user prob pressed cancel KPlato = Kross.module("KPlato") if KPlato is None: raise Exception, i18n("Failed to start KPlato. Is KPlato installed?") KPlato.document().openUrl( filename ) proj = KPlato.project() data = self.showDataSelectionDialog( writer, KPlato ) if len(data) == 0: raise Exception, i18n("No data to import") objectType = data[0] schedule = data[1] props = data[2] if len(props) == 0: raise Exception, i18n("No properties to import") record = [] if data[3] == True: for prop in props: record.append( KPlato.headerData( objectType, prop ) ) if not writer.setValues(record): if self.forms.showMessageBox("WarningContinueCancel", i18n("Warning"), i18n("Failed to set all properties of '%1' to cell '%2'", [", ".join(record), writer.cell()])) == "Cancel": return writer.next() if objectType == 0: # Nodes self.importValues( writer, KPlato, proj, props, schedule ) if objectType == 1: # Resources for i in range( proj.resourceGroupCount() ): self.importValues( writer, KPlato, proj.resourceGroupAt( i ), props, schedule ) if objectType == 2: # Accounts for i in range( proj.accountCount() ): self.importValues( writer, KPlato, proj.accountAt( i ), props, schedule )
def start(self): writer = KSpread.writer() connection = self.showImportDialog(writer) if not connection: return try: print "databaseNames = %s" % connection.databaseNames() print "tableNames = %s" % connection.tableNames() print "queryNames = %s" % connection.queryNames() queryschema = self.showTableDialog(connection) if not queryschema: return print "queryschema.name() = %s" % queryschema.name() print "queryschema.caption() = %s" % queryschema.caption() print "queryschema.description() = %s" % queryschema.description() cursor = connection.executeQuerySchema(queryschema) if not cursor: raise Exception, T.i18n("Failed to create cursor.") if not cursor.moveFirst(): raise Exception, T.i18n( "The cursor has no records to read from.") while not cursor.eof(): record = [] for i in range(cursor.fieldCount()): record.append(cursor.value(i)) if writer.setValues(record): writer.next() else: print "Failed to set all of '%s' to cell '%s'" % ( record, writer.cell()) cursor.moveNext() finally: connection.disconnect()
def start(self): writer = KSpread.writer() connection = self.showImportDialog(writer) if not connection: return try: print "databaseNames = %s" % connection.databaseNames() print "tableNames = %s" % connection.tableNames() print "queryNames = %s" % connection.queryNames() queryschema = self.showTableDialog(connection) if not queryschema: return print "queryschema.name() = %s" % queryschema.name() print "queryschema.caption() = %s" % queryschema.caption() print "queryschema.description() = %s" % queryschema.description() cursor = connection.executeQuerySchema(queryschema) if not cursor: raise Exception, T.i18n("Failed to create cursor.") if not cursor.moveFirst(): raise Exception, T.i18n("The cursor has no records to read from.") while not cursor.eof(): record = [] for i in range( cursor.fieldCount() ): record.append( cursor.value(i) ) if writer.setValues(record): writer.next() else: print "Failed to set all of '%s' to cell '%s'" % (record,writer.cell()) cursor.moveNext() finally: connection.disconnect()