Example #1
0
def read(filename):
    with open(filename, newline='') as f:
        try:
            dialect = csv.Sniffer().sniff(f.read())
        except:
            dialect = csv.excel
        f.seek(0)
        reader = csv.reader(f, dialect)
        sheet = Sheet()
        sheet.title = filename
        for row in reader:
            sheet.cursor[0] = 0
            for cell in row:
                sheet.append(cell)
                sheet.cursor[0] += 1
            sheet.cursor[1] += 1
        for column in range(sheet.size[0]):
            width = max(
                len(sheet.cells[column][row].content)
                for row in range(sheet.size[1])) + 2
            sheet.column_widths[column] = width
        sheet.cursor = [0, 0]
        sheet.modified = False
        sheet.status = 'Read file'
        return sheet
Example #2
0
def read(filename):
    with open(filename, newline='') as f:
        try:
            dialect = csv.Sniffer().sniff(f.read())
        except:
            dialect = csv.excel
        f.seek(0)
        reader = csv.reader(f, dialect)
        sheet = Sheet()
        sheet.title = filename
        for row in reader:
            sheet.cursor[0] = 0
            for cell in row:
                sheet.append(cell)
                sheet.cursor[0] += 1
            sheet.cursor[1] += 1
        for column in range(sheet.size[0]):
            width = max(len(sheet.cells[column][row].content)
                        for row in range(sheet.size[1])) + 2
            sheet.column_widths[column] = width
        sheet.cursor = [0, 0]
        sheet.modified = False
        sheet.status = 'Read file'
        return sheet
Example #3
0
 def test_write(self):
     sheet = Sheet()
     sheet.append('a')
     sheet.cursor = [1, 0]
     sheet.append('2')
     sheet.cursor = [3, 0]
     sheet.append('delta')
     sheet.cursor = [0, 1]
     sheet.append('two words')
     sheet.cursor = [2, 1]
     sheet.append('a, comma')
     write(sheet, FILENAME)
     with open(FILENAME) as f:
         self.assertEqual(f.read(), TEST_TEXT)
     os.remove(FILENAME)
Example #4
0
File: app.py Project: jangler/vcii
 def new_sheet(self):
     sheet = Sheet()
     if self.string:
         sheet.title = self.string
     sheet.status = 'New file'
     return sheet
Example #5
0
File: app.py Project: semtle/vcii
 def __init__(self):
     self.sheets = [Sheet()]
     self.sheet = self.sheets[0]
     self.mode = MODE_NORMAL
     self.string = ''
     self.cursor = 0
Example #6
0
File: app.py Project: semtle/vcii
 def new_sheet(self):
     sheet = Sheet()
     if self.string:
         sheet.title = self.string
     sheet.status = 'New file'
     return sheet
Example #7
0
 def test_write(self):
     sheet = Sheet()
     sheet.append('a')
     sheet.cursor = [1, 0]
     sheet.append('2')
     sheet.cursor = [3, 0]
     sheet.append('delta')
     sheet.cursor = [0, 1]
     sheet.append('two words')
     sheet.cursor = [2, 1]
     sheet.append('a, comma')
     write(sheet, FILENAME)
     with open(FILENAME) as f:
         self.assertEqual(f.read(), TEST_TEXT)
     os.remove(FILENAME)