class Test_NamedRanges(unittest.TestCase): def setUp(self): self.sp = Spreadsheet("./tests/files/NamedRanges.xlsx", ignore_sheets=['IHS']) sys.setrecursionlimit(10000) def test_before_set_value(self): self.assertTrue( self.sp.cell_evaluate('INPUT') == 1 and self.sp.cell_evaluate('Sheet1!A1') == 1 and self.sp.cell_evaluate('RESULT') == 187) def test_after_set_value(self): # test if changing a input (named cell) leads to change in result (named cell with formula) self.sp.cell_set_value('INPUT', 2025) self.assertTrue( self.sp.cell_evaluate('INPUT') == 2025 and self.sp.cell_evaluate('Sheet1!A1') == 2025 and self.sp.cell_evaluate('RESULT') == 2211) # want to test multiple values as sometimes it gets stuck after one self.sp.cell_set_value('INPUT', 26) self.assertTrue( self.sp.cell_evaluate('INPUT') == 26 and self.sp.cell_evaluate('Sheet1!A1') == 26 and self.sp.cell_evaluate('RESULT') == 212)
def test_as_from_dict(self): file_name = os.path.abspath("./tests/excel/VDB.xlsx") sp1 = Spreadsheet(file_name) sp1.cell_set_value('Sheet1!B7', value=100) sp1.cell_set_value('Sheet1!B8', value=200) # serialize to a dict, then back to a clone instance data = sp1.asdict() sp2 = Spreadsheet.from_dict(data) # set values in the new spreadsheet - should be different than before sp2.cell_set_value('Sheet1!B7', value=500) sp2.cell_set_value('Sheet1!B8', value=600) self.assertNotEqual(sp1.cell_evaluate('Sheet1!B7'), sp2.cell_evaluate('Sheet1!B7')) self.assertNotEqual(sp1.cell_evaluate('Sheet1!B8'), sp2.cell_evaluate('Sheet1!B8'))
from koala import Spreadsheet sp = Spreadsheet("example.xlsx") v = sp.cell_evaluate('Sheet 1!A1') print("A1", v) sp.cell_set_value('Sheet 1!B5', 15) v = sp.cell_evaluate('Sheet 1!A1') print("A1", v) address = 'Sheet 1!B6' if address not in sp.cellmap and address not in sp.named_ranges: set_value = sp.cell_add else: set_value = sp.cell_set_value set_value(address, value=15)