Example #1
0
    def importVCardFile(self, vcardfilename, currentSheet):
        self.componentDict = {}
        self.componentList = []

        writer = KCells.writer()
        if not writer.setSheet(currentSheet):
            raise 'Invalid sheet "%s" 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)
Example #2
0
    def doImport(self):
        currentSheet = self.sheetslistview.sheet()
        if not currentSheet:
            raise "No current sheet."

        writer = KCells.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()
Example #3
0
    def importVCardFile(self, vcardfilename, currentSheet):
        self.componentDict = {}
        self.componentList = []

        writer = KCells.writer()
        if not writer.setSheet(currentSheet):
            raise "Invalid sheet \"%s\" 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)
Example #4
0
    def start(self):
        writer = KCells.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 "Failed to create cursor."
            if not cursor.moveFirst():
                raise "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()
Example #5
0
    def doImport(self):
        currentSheet = self.sheetslistview.sheet()
        if not currentSheet:
            raise "No current sheet."

        writer = KCells.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()